Skip to content

Transmogrify fix NULL role affiliation (CFM-383) #180

Merged
merged 1 commit into from May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 44 additions & 1 deletion app/src/Command/TransmogrifyCommand.php
Expand Up @@ -134,6 +134,7 @@ class TransmogrifyCommand extends Command {
],
'person_roles' => [
'source' => 'cm_co_person_roles',
'sqlSelect' => 'roleSqlSelect',
'displayField' => 'id',
// We don't currently need status specifically, just that the role exists
'cache' => [ 'status' ],
Expand Down Expand Up @@ -1287,6 +1288,48 @@ protected function processExtendedAttributes() {
}
}

/**
* Return SQL used to select CO Person Roles from inbound database.
*
* @since COmanage Registry v5.0.0
* @param string $tableName Name of the SQL table
* @return string SQL string to select rows from inbound database
*/

protected function roleSqlSelect(string $tableName): string {
// Cast the affiliation value to 'member' when NULL or empty string.
define("ROLE_SQL_SELECT", <<<SQL
SELECT
id,
co_person_id,
sponsor_co_person_id,
manager_co_person_id,
cou_id,
CASE
WHEN affiliation IS NULL THEN "member"
WHEN affiliation = "" THEN "member"
ELSE affiliation
END as affiliation,
title,
o,
ou,
valid_from,
valid_through,
ordr,
status,
source_org_identity_id,
created,
modified,
co_person_role_id,
revision,
deleted,
actor_identifier
FROM cm_co_person_roles;
SQL);

return ROLE_SQL_SELECT;
}

/**
* Split an External Identity into an External Identity Role.
*
Expand Down Expand Up @@ -1339,4 +1382,4 @@ protected function split_external_identity(array $origRow, array $row) {
$qualifiedTableName = $this->outconn->qualifyTableName($tableName);
$this->outconn->insert($qualifiedTableName, $roleRow);
}
}
}