From 313229aaea8c8a6f4dd21747011a6c3399c5100c Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 5 Apr 2026 05:34:44 +0000 Subject: [PATCH] Add support for provisioning history records --- .../Transmogrify/config/schema/tables.json | 19 ++++++ .../src/Lib/Traits/ManageDefaultsTrait.php | 66 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index 232eb640c..01f04ae0f 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -571,6 +571,7 @@ "provisioning_targets": { "source": "cm_co_provisioning_targets", "displayField": "description", + "cache": ["id", "co_id"], "fieldMap": { "plugin": "&mapProvisionerPlugin", "provision_co_group_id": "provisioning_group_id", @@ -920,5 +921,23 @@ "sorid": "source_key" }, "dependencies": ["api_sources"] + }, + "provisioning_history_records": { + "source": "cm_co_provisioning_exports", + "displayField": "id", + "fieldMap": { + "status": "=P", + "subject_model": "&mapToSubjectModel", + "subject_id": "&mapToSubjectId", + "co_provisioning_target_id": "provisioning_target_id", + "comment": "=Record Exported", + "co_person_id": "person_id", + "co_group_id": "group_id", + "co_email_list_id": null, + "co_service_id": null, + "exporttime": null + }, + "addChangelog": true, + "dependencies": ["groups", "people", "provisioning_targets"] } } diff --git a/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php index b65641a71..a346cd548 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php @@ -187,6 +187,72 @@ protected function mapToDefaultTelephoneNumberTypeId(array $row): ?int ); } + + /** + * Determine the subject model ID ("People" or "Groups") for a given row. + * + * This method evaluates whether the row corresponds to a person or a group + * based on the presence of either `co_person_id` or `co_group_id`, ensuring + * that exactly one of these fields is populated. + * + * @param array $row Row data containing subject identifiers + * @return string Either "People" or "Groups" based on the input data + * @throws \RuntimeException If neither or both `co_person_id` and `co_group_id` are set + * @since COmanage Registry v5.2.0 + */ + protected function mapToSubjectModel(array $row): string + { + $personId = $row['co_person_id'] ?? null; + $groupId = $row['co_group_id'] ?? null; + + $hasPerson = ($personId !== null && $personId !== ''); + $hasGroup = ($groupId !== null && $groupId !== ''); + + if($hasPerson xor $hasGroup) { + return $hasPerson ? 'People' : 'Groups'; + } + + $exportId = $row['id'] ?? '(unknown)'; + + throw new \RuntimeException( + "Invalid cm_co_provisioning_exports row {$exportId}: exactly one of co_person_id or co_group_id must be set" + ); + } + + + /** + * Determine the subject ID ("People" or "Groups") for a given row. + * + * This method evaluates whether the row corresponds to a person or a group + * based on the presence of either `co_person_id` or `co_group_id`, ensuring + * that exactly one of these fields is populated, and returns the corresponding ID. + * + * @param array $row Row data containing subject identifiers + * @return int|null ID of the person or group, or null if neither can be determined + * @throws \RuntimeException If neither or both `co_person_id` and `co_group_id` are set + * @since COmanage Registry v5.2.0 + */ + protected function mapToSubjectId(array $row): ?int + { + $personId = $row['co_person_id'] ?? null; + $groupId = $row['co_group_id'] ?? null; + + $hasPerson = ($personId !== null && $personId !== ''); + $hasGroup = ($groupId !== null && $groupId !== ''); + + // Exactly one of co_person_id / co_group_id must be set. + if($hasPerson xor $hasGroup) { + return $hasPerson ? (int)$personId : (int)$groupId; + } + + $exportId = $row['id'] ?? '(unknown)'; + + throw new \RuntimeException( + "Invalid provisioning export row {$exportId}: exactly one of co_person_id or co_group_id must be set" + ); + } + + /** * Insert default CO Settings for COs that don't have settings. *