From 894ebd36dda332487ad9fc8bf386534269f16c0e Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 20 Nov 2025 05:41:17 +0200 Subject: [PATCH] Fix person status mapping --- .../Transmogrify/config/schema/tables.json | 3 +- .../src/Lib/Traits/TypeMapperTrait.php | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index c3dfca2e..256ec205 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -194,7 +194,8 @@ "displayField": "id", "cache": ["co_id"], "fieldMap": { - "co_person_id": "person_id" + "co_person_id": "person_id", + "status": "&mapPersonStatus" } }, "person_roles": { diff --git a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php index 2da28144..47e7d195 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php @@ -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) @@ -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 *