Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"cache": ["match_server_id"],
"fieldMap": {
"type_id": "&mapMatchAttributeTypeId",
"attribute": "&mapMatchAttribute",
"type": null
},
"dependencies": ["match_servers", "types"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ private function performFunctionMapping(array &$row, string $oldname, string $fu
'mapAffiliationType',
'mapHistoricPetitionViewerId',
'mapCoIdFromApiUserId',
'mapMatchAttributeTypeId',
];

// Tables that allow null types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ trait TypeMapperTrait
'dateOfBirth' => '',
];

/**
* Map v4 match attribute names to v5 match attribute (wire) names
*
* @var array<string,string>
* @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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
*
Expand Down