Skip to content

Commit

Permalink
Fix person status mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Nov 20, 2025
1 parent 39c5735 commit 894ebd3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/plugins/Transmogrify/config/schema/tables.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
"displayField": "id",
"cache": ["co_id"],
"fieldMap": {
"co_person_id": "person_id"
"co_person_id": "person_id",
"status": "&mapPersonStatus"
}
},
"person_roles": {
Expand Down
56 changes: 56 additions & 0 deletions app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ protected function mapExtendedType(array $row): string
return Inflector::pluralize($bits[0]) . "." . $bits[1];
}


/**
* Map a petition/attribute record to its associated historic petition viewer ID
*
* The mapping is done by:
* 1. Using enrollment_flow_id directly from row if available
* 2. Otherwise looking up flow ID via petition_id foreign key
* 3. Using flow ID to get viewer ID from enrollment_flows cache
*
* @param array $row Row data containing either enrollment_flow_id or petition_id
* @return int|null Historic petition viewer ID if mapping found, null otherwise
* @since COmanage Registry v5.2.0
*/
protected function mapHistoricPetitionViewerId(array $row): ?int
{
// 1) Flow id available directly on the row (co_petitions)
Expand Down Expand Up @@ -472,6 +485,49 @@ protected function mapPetitionStatus(array $row): ?string
}


/**
* Map v4 person status codes to v5 StatusEnum values
*
* Maps legacy/in-progress statuses to equivalent v5 statuses:
* - Approved (Y), Confirmed (C), Declined (X), Invited (I),
* PendingApproval (PA), PendingConfirmation (PC) -> Pending (P)
* - Denied (N) -> Suspended (S)
* - Otherwise returns original code if allowed
*
* @param array $row Row data containing v4 status code in 'status' field
* @return string|null Mapped v5 status code or null if status empty/missing
* @since COmanage Registry v5.2.0
*/
protected function mapPersonStatus(array $row): ?string
{
$code = $row['status'] ?? null;
if ($code === null) {
return null;
}

$code = strtoupper(trim((string)$code));

// Approved, Confirmed, Declined, Invited, PendingApproval, PendingConfirmation -> Pending
// Denied -> Suspended
$map = [
'Y' => 'P', // Approved
'C' => 'P', // Confirmed
'X' => 'P', // Declined
'I' => 'P', // Invited
'PA' => 'P', // PendingApproval
'PC' => 'P', // PendingConfirmation
'N' => 'S', // Denied
];

if (isset($map[$code])) {
return $map[$code];
}

// If it is allowed, just return it
return $code;
}


/**
* Map server type code to corresponding plugin path
*
Expand Down

0 comments on commit 894ebd3

Please sign in to comment.