Skip to content

Commit

Permalink
Add support for provisioning history records
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 7, 2026
1 parent 859f7d8 commit 313229a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/plugins/Transmogrify/config/schema/tables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]
}
}
66 changes: 66 additions & 0 deletions app/plugins/Transmogrify/src/Lib/Traits/ManageDefaultsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 313229a

Please sign in to comment.