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
104 changes: 83 additions & 21 deletions app/availableplugins/Transmogrify/config/schema/tables.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"types": {
"source": "cm_co_extended_types",
"displayField": "display_name",
"postTable": "insertPronounTypes",
"postTable": "insertDefaultTypes",
"fieldMap": {
"attribute": "&mapExtendedType",
"name": "value",
Expand Down Expand Up @@ -108,6 +108,15 @@
"sqlSelect": "couSqlSelect",
"dependencies": ["cos"]
},
"organizations": {
"source": "cm_organizations",
"displayField": "name",
"cache": ["id", "co_id"],
"fieldMap": {
"type_id": "&mapOrganizationType",
"type": null
}
},
"servers": {
"source": "cm_servers",
"plugin": "CoreServer",
Expand Down Expand Up @@ -237,7 +246,7 @@
"booleans": ["hash_source_record"],
"cache": ["co_id"],
"fieldMap": {
"plugin": "&mapExternalIdentitySourcePlugin",
"plugin": "&mapSourcePlugin",
"co_pipeline_id": "pipeline_id",
"org_identity_source_id": "external_identity_source_id",
"status": "&mapStatusAndSyncToStatus",
Expand Down Expand Up @@ -310,6 +319,30 @@
},
"dependencies": ["external_identity_sources", "types"]
},
"organization_sources": {
"source": "cm_organization_sources",
"displayField": "description",
"plugin": "FederationConnector",
"fieldMap": {
"plugin": "&mapSourcePlugin",
"sync_mode": null
},
"dependencies": ["co_id"]
},
"federation_sources": {
"source": "cm_federation_sources",
"displayField": "id",
"plugin": "FederationConnector",
"fieldMap": {},
"dependencies": ["co_id", "organization_sources", "organizations"]
},
"organization_source_records": {
"source": "cm_organization_source_records",
"displayField": "id",
"plugin": "FederationConnector",
"fieldMap": {},
"dependencies": ["co_id", "organization_sources", "organizations"]
},
"api_sources": {
"source": "cm_api_sources",
"plugin": "ApiConnector",
Expand Down Expand Up @@ -605,6 +638,21 @@
},
"dependencies": ["groups", "people", "group_nestings"]
},
"departments": {
"source": "cm_co_departments",
"displayField": "name",
"cache": ["id", "co_id"],
"fieldMap": {
"co_department_id": "department_id",
"leadership_co_group_id": "leadership_group_id",
"administrative_co_group_id": "administrative_group_id",
"support_co_group_id": "support_group_id",
"type_id": "&mapDepartmentType",
"introduction": "public_description",
"type": null
},
"dependencies": ["co", "cous", "groups", "types"]
},
"names": {
"source": "cm_names",
"displayField": "id",
Expand All @@ -627,11 +675,11 @@
"type_id": "&mapEmailType",
"co_person_id": "person_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"organization_id": null,
"co_department_id": "department_id",
"organization_id": "organization_id",
"type": null
},
"dependencies": ["people", "external_identities", "types"]
"dependencies": ["people", "external_identities", "types", "departments", "organizations"]
},
"identifiers": {
"source": "cm_identifiers",
Expand All @@ -644,13 +692,13 @@
"co_group_id": "group_id",
"co_person_id": "person_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"co_provisioning_target_id": null,
"organization_id": null,
"co_department_id": "department_id",
"organization_id": "organization_id",
"co_provisioning_target_id": "provisioning_target_id",
"type": null,
"language": null
},
"dependencies": ["groups", "people", "external_identities", "types"]
"dependencies": ["groups", "people", "external_identities", "types", "departments", "organizations"]
},
"urls": {
"source": "cm_urls",
Expand All @@ -660,12 +708,12 @@
"type_id": "&mapUrlType",
"co_person_id": "person_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"organization_id": null,
"co_department_id": "department_id",
"organization_id": "organization_id",
"type": null,
"language": null
},
"dependencies": ["people", "external_identities", "types"]
"dependencies": ["people", "external_identities", "types", "departments", "organizations"]
},
"addresses": {
"source": "cm_addresses",
Expand All @@ -675,11 +723,11 @@
"type_id": "&mapAddressType",
"co_person_role_id": "person_role_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"organization_id": null,
"co_department_id": "department_id",
"organization_id": "organization_id",
"type": null
},
"dependencies": ["person_roles", "external_identities", "types"]
"dependencies": ["person_roles", "external_identities", "types", "departments", "organizations"]
},
"telephone_numbers": {
"source": "cm_telephone_numbers",
Expand All @@ -689,11 +737,11 @@
"type_id": "&mapTelephoneType",
"co_person_role_id": "person_role_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"organization_id": null,
"co_department_id": "department_id",
"organization_id": "organization_id",
"type": null
},
"dependencies": ["person_roles", "external_identities", "types"]
"dependencies": ["person_roles", "external_identities", "types", "departments", "organizations"]
},
"ad_hoc_attributes": {
"source": "cm_ad_hoc_attributes",
Expand All @@ -702,11 +750,25 @@
"fieldMap": {
"co_person_role_id": "person_role_id",
"org_identity_id": "external_identity_id",
"co_department_id": null,
"organization_id": null
"co_department_id": "department_id",
"organization_id": "organization_id"
},
"postTable": "migrateExtendedAttributesToAdHocAttributes",
"dependencies": ["person_roles", "external_identities"]
"dependencies": ["person_roles", "external_identities", "organizations", "departments"]
},
"contacts": {
"source": "cm_contacts",
"displayField": "id",
"booleans": [
"frozen"
],
"fieldMap": {
"type_id": "&mapContactType",
"organization_id": "organization_id",
"co_department_id": "department_id",
"type": null
},
"dependencies": ["organizations", "departments"]
},
"notifications": {
"source": "cm_co_notifications",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,22 @@ public function execute(Arguments $args, ConsoleIo $io): int
$this->cmdPrinter->out('Running assignUuids task via UpgradeCommand...');
$this->executeCommand(UpgradeCommand::class, ['-D', '-X', '-t', 'assignUuids'], $this->io);

// Install default Mostly Static Pages
$this->cmdPrinter->out('Running installMostlyStaticPages task via UpgradeCommand...');
$this->executeCommand(UpgradeCommand::class, ['-D', '-X', '-t', 'installMostlyStaticPages'], $this->io);

// Rebuild Group Tree hierarchy (lft/rght bounds)
$this->cmdPrinter->out('Running buildGroupTree task via UpgradeCommand...');
$this->executeCommand(UpgradeCommand::class, ['-D', '-X', '-t', 'buildGroupTree'], $this->io);

// Create missing default groups (Approvers, MFA Exempt, etc.)
$this->cmdPrinter->out('Running createDefaultGroups task via UpgradeCommand...');
$this->executeCommand(UpgradeCommand::class, ['-D', '-X', '-P', '-t', 'createDefaultGroups'], $this->io);

// Initialize default normalizations
$this->cmdPrinter->out('Running setupNormalizations task via UpgradeCommand...');
$this->executeCommand(UpgradeCommand::class, ['-D', '-X', '-t', 'setupNormalizations'], $this->io);

// Display total execution time
$executionTime = microtime(true) - $this->startTime;

Expand Down
59 changes: 58 additions & 1 deletion app/availableplugins/Transmogrify/src/Lib/Traits/CacheTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function cacheFieldById(string $table, array $row, string $field): voi
* @param string $table Table to cache
* @param array $row Row of table data
* @param array $orinRow Original Row of table data
* @param array $cacheConfig Optional cache configuration (overrides tables.json)
* @param array|null $cacheConfig Optional cache configuration (overrides tables.json)
*/

protected function cacheResults(string $table, array $row, array $orinRow, ?array $cacheConfig = []): void
Expand Down Expand Up @@ -188,6 +188,18 @@ protected function findCoId(array $row): int

isset($row['co_person_role_id']) => $this->getCoIdFromPersonRoleId((int)$row['co_person_role_id']),

isset($row['person_role_id']) => $this->getCoIdFromPersonRoleId((int)$row['person_role_id']),

isset($row['organization_id']) => $this->getCoIdFromOrganizationId((int)$row['organization_id']),

isset($row['department_id']) => $this->getCoIdFromDepartmentId((int)$row['department_id']),

isset($row['co_department_id']) => $this->getCoIdFromDepartmentId((int)$row['co_department_id']),

isset($row['provisioning_target_id']) => $this->getCoIdFromProvisioningTargetId((int)$row['provisioning_target_id']),

isset($row['co_provisioning_target_id']) => $this->getCoIdFromProvisioningTargetId((int)$row['co_provisioning_target_id']),

default => null,
};

Expand Down Expand Up @@ -312,4 +324,49 @@ private function getCoIdFromPersonRoleId(int $personRoleId): ?int
}
return null;
}

/**
* Resolve a CO ID from an Organization ID via cache.
*
* @param int $organizationId Organization ID to resolve
* @return int|null CO ID if found, null otherwise
* @since COmanage Registry v5.3.0
*/
private function getCoIdFromOrganizationId(int $organizationId): ?int
{
if (isset($this->cache['organizations']['id'][$organizationId]['co_id'])) {
return (int)$this->cache['organizations']['id'][$organizationId]['co_id'];
}
return null;
}

/**
* Resolve a CO ID from a Department ID via cache.
*
* @param int $departmentId Department ID to resolve
* @return int|null CO ID if found, null otherwise
* @since COmanage Registry v5.3.0
*/
private function getCoIdFromDepartmentId(int $departmentId): ?int
{
if (isset($this->cache['departments']['id'][$departmentId]['co_id'])) {
return (int)$this->cache['departments']['id'][$departmentId]['co_id'];
}
return null;
}

/**
* Resolve a CO ID from a Provisioning Target ID via cache.
*
* @param int $provisioningTargetId Provisioning Target ID to resolve
* @return int|null CO ID if found, null otherwise
* @since COmanage Registry v5.3.0
*/
private function getCoIdFromProvisioningTargetId(int $provisioningTargetId): ?int
{
if (isset($this->cache['provisioning_targets']['id'][$provisioningTargetId]['co_id'])) {
return (int)$this->cache['provisioning_targets']['id'][$provisioningTargetId]['co_id'];
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function runSqlSelectHook(string $table, string $qualifiedTableName): st
'co_group_id',
'co_department_id',
'co_provisioning_target_id',
'organization_id'
'organization_id' // XXX The name in v4 and v5 is the same. As a result this needs to exist in the table.json!!!
];
$fieldMap = $this->tables[$table]['fieldMap'] ?? [];
$presentFks = array_values(array_intersect($fkCandidates, array_keys($fieldMap)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,39 @@ protected function insertDefaultSettings(): void
}
}

/**
* Insert default types for all COs.
*
* @since COmanage Registry v5.3.0
* @return void
*/
protected function insertDefaultTypes(): void
{
$Types = TableRegistry::getTableLocator()->get('Types');

foreach (array_keys($this->cache['cos']['id']) as $coId) {
$Types->addDefaults($coId);
}

// Populate cache with all default and extended types
$allTypes = $Types->find()
->where([
'co_id IN' => array_keys($this->cache['cos']['id']),
])
->all();

foreach ($allTypes as $type) {
$row = [
'id' => $type->id,
'co_id' => $type->co_id,
'attribute' => $type->attribute,
'value' => $type->value,
];

$this->cacheCompositeKey('types', $row, ['co_id', 'attribute', 'value']);
}
}

/**
* Insert default Pronoun types for all COs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ protected function mapExternalIdentityToExternalIdentityRole(array $origRow, arr
if (
isset($origRow['co_id'])
&& (!isset($this->cache['cos'][$origRow['co_id']])
|| ($this->cache['cos'][$origRow['co_id']]['status'])
&& $this->cache['cos'][$origRow['co_id']]['status'] == 'TR')
|| (($this->cache['cos'][$origRow['co_id']]['status'])
&& $this->cache['cos'][$origRow['co_id']]['status'] == 'TR'))
) {
// This CO has been deleted, so we can't map the type. We will return null
$roleRow['affiliation_type_id'] = null;
Expand Down Expand Up @@ -735,6 +735,10 @@ private function applyDefaultIfNull(array &$row, string $oldname, string $defaul
*/
private function renameField(array &$row, string $oldname, string $newname): void
{
if ($oldname === $newname) {
return;
}

// Only copy if the old field exists to avoid notices
if (array_key_exists($oldname, $row)) {
$row[$newname] = $row[$oldname];
Expand Down
Loading