diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index d4103fba..26872e5e 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -591,5 +591,20 @@ "eppn_suffix": null, "org_identity_source_id": "external_identity_source_id" } + }, + "ext_identity_source_records": { + "source": "cm_org_identity_source_records", + "displayField": "id", + "cache": ["org_identity_id", "sorid"], + "preRow": "findAdoptedPersonByLinkedOrgIdentityId", + "fieldMap": { + "org_identity_source_id": "external_identity_source_id", + "sorid": "source_key", + "org_identity_id": "external_identity_id", + "co_petition_id": null, + "co_person_id": "adopted_person_id", + "reference_identifier": "reference_identifier", + "org_identity_source_record_id": "ext_identity_source_record_id" + } } } diff --git a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php index 47b15b49..cfd6512e 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php @@ -113,6 +113,46 @@ trait TypeMapperTrait 'dateOfBirth' => '', ]; + + /** + * Find and set adopted person ID based on linked external/org identity ID + * + * Attempts to find the associated CO Person ID using either external_identity_id + * or org_identity_id from either original or current row data. If found, updates + * the co_person_id in the original row. + * + * @param array &$origRow Original row data by reference + * @param array &$row Current row data by reference + * @return void + * @throws Exception + * @since COmanage Registry v5.2.0 + */ + protected function findAdoptedPersonByLinkedOrgIdentityId(array &$origRow, array &$row): void + { + // Try to locate an external identity (or legacy org identity) id from either array + $externalIdentityId = null; + + if (!empty($row['external_identity_id'])) { + $externalIdentityId = (int)$row['external_identity_id']; + } elseif (!empty($origRow['org_identity_id'])) { + $externalIdentityId = (int)$origRow['org_identity_id']; + } elseif (!empty($row['org_identity_id'])) { + $externalIdentityId = (int)$row['org_identity_id']; + } + + $personId = null; + + if ($externalIdentityId !== null) { + $personId = $this->mapOrgIdentityCoPersonId(['id' => $externalIdentityId]); + } + + + $row['co_person_id'] = null; + if ($personId !== null) { + $row['co_person_id'] = $personId; + } + } + /** * Map address type to corresponding type ID *