From 512bbf57bf18c0d205518dda9c9666ef2d39551e Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 3 Nov 2026 15:06:58 +0000 Subject: [PATCH] Transmogrify Match Server Attributes to PE attribute names (CO-3012) --- .../Transmogrify/config/schema/tables.json | 1 + .../src/Lib/Traits/RowTransformationTrait.php | 1 + .../src/Lib/Traits/TypeMapperTrait.php | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/app/availableplugins/Transmogrify/config/schema/tables.json b/app/availableplugins/Transmogrify/config/schema/tables.json index 2ada6ed64..3096e7efa 100644 --- a/app/availableplugins/Transmogrify/config/schema/tables.json +++ b/app/availableplugins/Transmogrify/config/schema/tables.json @@ -199,6 +199,7 @@ "cache": ["match_server_id"], "fieldMap": { "type_id": "&mapMatchAttributeTypeId", + "attribute": "&mapMatchAttribute", "type": null }, "dependencies": ["match_servers", "types"] diff --git a/app/availableplugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php b/app/availableplugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php index 70619efe1..aaa831030 100644 --- a/app/availableplugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php +++ b/app/availableplugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php @@ -691,6 +691,7 @@ private function performFunctionMapping(array &$row, string $oldname, string $fu 'mapAffiliationType', 'mapHistoricPetitionViewerId', 'mapCoIdFromApiUserId', + 'mapMatchAttributeTypeId', ]; // Tables that allow null types diff --git a/app/availableplugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php b/app/availableplugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php index aa08a3c2e..4599c500d 100644 --- a/app/availableplugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php +++ b/app/availableplugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php @@ -119,6 +119,19 @@ trait TypeMapperTrait 'dateOfBirth' => '', ]; + /** + * Map v4 match attribute names to v5 match attribute (wire) names + * + * @var array + * @since COmanage Registry v5.4.0 + */ + public const MATCH_ATTRIBUTE_NAME_MAP = [ + 'emailAddress' => 'emailAddresses', + 'identifier' => 'identifiers', + 'name' => 'names', + 'dateOfBirth' => 'dateOfBirth', + ]; + /** * Find and set adopted person ID based on linked external/org identity ID @@ -512,6 +525,15 @@ protected function mapMatchAttributeTypeId(array $row): ?int { // Determine the model based on the match attribute map (eg, emailAddress -> EmailAddresses) $attributeKey = $row['attribute'] ?? null; + + // Accept v5 attribute names as well (eg, emailAddresses -> emailAddress) + if ($attributeKey && !array_key_exists($attributeKey, self::MATCH_ATTRIBUTE_TYPE_MAP)) { + $v4Key = array_search($attributeKey, self::MATCH_ATTRIBUTE_NAME_MAP, true); + if ($v4Key !== false) { + $attributeKey = $v4Key; + } + } + if (!$attributeKey || !array_key_exists($attributeKey, self::MATCH_ATTRIBUTE_TYPE_MAP)) { return null; } @@ -525,6 +547,37 @@ protected function mapMatchAttributeTypeId(array $row): ?int return $this->mapType($row, $model . '.type', $this->findCoId($row)); } + /** + * Map v4 match attribute name in $row['attribute'] to v5 match attribute (wire) name + * + * Unknown values are passed through unchanged (with a warning) so the migration does not abort. + * + * @param array $row Row data containing 'attribute' (v4 record) + * @return string|null Mapped v5 attribute name, or the original value if not mapped + * @since COmanage Registry v5.4.0 + */ + protected function mapMatchAttribute(array $row): ?string + { + $attribute = $row['attribute'] ?? null; + + if ($attribute === null || $attribute === '') { + return $attribute; + } + + if (array_key_exists($attribute, self::MATCH_ATTRIBUTE_NAME_MAP)) { + return self::MATCH_ATTRIBUTE_NAME_MAP[$attribute]; + } + + // Already a v5 attribute name, nothing to do + if (in_array($attribute, self::MATCH_ATTRIBUTE_NAME_MAP, true)) { + return $attribute; + } + + $this->cmdPrinter->warning("Unknown match server attribute '{$attribute}' (match_server_attributes id " . ($row['id'] ?? '?') . "), keeping value as-is"); + + return $attribute; + } + /** * Map v4 MessageTemplateEnum code in $row['context'] to v5 MessageTemplateContextEnum code *