From 38a7a7df5ca040e97c4997ab5dcddde20625730c Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 19 Dec 2025 12:05:12 +0200 Subject: [PATCH] Fix external identity sources status/sync_mode transmogrification --- .../Transmogrify/config/schema/tables.json | 1 + .../src/Command/TransmogrifyCommand.php | 1 + .../src/Lib/Traits/RowTransformationTrait.php | 1 + .../src/Lib/Traits/TypeMapperTrait.php | 49 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/app/plugins/Transmogrify/config/schema/tables.json b/app/plugins/Transmogrify/config/schema/tables.json index 6fc39279b..d0d61d85f 100644 --- a/app/plugins/Transmogrify/config/schema/tables.json +++ b/app/plugins/Transmogrify/config/schema/tables.json @@ -225,6 +225,7 @@ "plugin": "&mapExternalIdentitySourcePlugin", "co_pipeline_id": "pipeline_id", "org_identity_source_id": "external_identity_source_id", + "status": "&mapStatusAndSyncToStatus", "sync_mode": null, "sync_query_mismatch_mode": null, "sync_query_skip_known": null, diff --git a/app/plugins/Transmogrify/src/Command/TransmogrifyCommand.php b/app/plugins/Transmogrify/src/Command/TransmogrifyCommand.php index 4b4ec1364..542685902 100644 --- a/app/plugins/Transmogrify/src/Command/TransmogrifyCommand.php +++ b/app/plugins/Transmogrify/src/Command/TransmogrifyCommand.php @@ -373,6 +373,7 @@ public function execute(Arguments $args, ConsoleIo $io): int return BaseCommand::CODE_ERROR; } + // Execute any pre-processing hooks for the current table $this->runPreTableHook($t); diff --git a/app/plugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php index ae0c71ea3..4aee6e751 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/RowTransformationTrait.php @@ -624,6 +624,7 @@ private function applyDefaultIfNull(array &$row, string $oldname, string $defaul } } + /** * Rename a field by copying its value to a new key and removing the old key. * diff --git a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php index 016c4c205..6a4b2b794 100644 --- a/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php +++ b/app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php @@ -30,6 +30,7 @@ namespace Transmogrify\Lib\Traits; use App\Lib\Enum\PetitionStatusEnum; +use App\Lib\Enum\SyncModeEnum; use Cake\ORM\TableRegistry; use Cake\Utility\Hash; use Cake\Utility\Inflector; @@ -820,6 +821,54 @@ protected function mapPersonStatus(array $row): ?string } + /** + * Maps v4 status/sync_mode combination to v5 status values + * + * v4: + * - status: 'A' (active) or 'S' (suspended) + * - sync_mode: 'F' (Full), 'M' (Manual), 'Q' (Query), 'U' (Update) + * + * v5: + * - sync_mode and status are merged into the single "status" column + * - "Active" is no longer a separate thing + * - v4 suspended ('S') becomes v5 Disabled ('X') + * + * Logic: + * - If v4 status is suspended ('S'), always map to Disabled. + * - Otherwise, copy the sync_mode over: + * F -> Full + * M -> Manual + * U -> Update + * Q -> Disabled (not yet supported; see CFM-372). + * + * @param array $row Row data containing 'status' and 'sync_mode' fields from v4 + * @return string|null Mapped v5 status value or null if sync_mode missing/empty + * @since COmanage Registry v5.2.0 + */ + protected function mapStatusAndSyncToStatus(array $row): ?string + { + $v4Status = $row['status'] ?? null; + $v4SyncMode = $row['sync_mode'] ?? null; + + // Suspended in v4 becomes Disabled in v5 + if ($v4Status === 'S') { + return SyncModeEnum::Disabled; + } + + if ($v4SyncMode === null || $v4SyncMode === '') { + return null; + } + + return match ($v4SyncMode) { + 'F' => SyncModeEnum::Full, + 'M' => SyncModeEnum::Manual, + 'U' => SyncModeEnum::Update, + 'Q' => SyncModeEnum::Disabled, // XXX not yet supported; see CFM-372 + default => null, + }; + } + + /** * Map server type code to corresponding plugin path *