Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Nov 7, 2025
1 parent 7b81dd1 commit edc7b39
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 403 deletions.
6 changes: 3 additions & 3 deletions app/plugins/Transmogrify/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
use Transmogrify\Lib\Traits\ManageDefaultsTrait;
use Transmogrify\Lib\Traits\RowTransformationTrait;
use Transmogrify\Lib\Traits\TypeMapperTrait;
use Transmogrify\Lib\Util\CommanLinePrinter;
use Transmogrify\Lib\Util\CommandLinePrinter;
use Transmogrify\Lib\Util\DbInfoPrinter;
use Transmogrify\Lib\Util\RawSqlQueries;

Expand Down Expand Up @@ -282,7 +282,7 @@ public function execute(Arguments $args, ConsoleIo $io): int
};
$stmt = $this->inconn->executeQuery($insql);

$progress = new CommanLinePrinter($io, 'green', 50, true);
$progress = new CommandLinePrinter($io, 'green', 50, true);
$progress->start($count);
$tally = 0;
$warns = 0;
Expand Down Expand Up @@ -357,7 +357,7 @@ public function execute(Arguments $args, ConsoleIo $io): int
$io->error(sprintf('Errors: %d', $err));

// Step 11: Execute any post-processing hooks for the table
if ($modeltableEmpty && !$notSelected) {
if ($modeltableEmpty && $notSelected) {
$this->runPostTableHook($t);
}

Expand Down
86 changes: 44 additions & 42 deletions app/plugins/Transmogrify/src/Lib/Traits/TypeMapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,54 +202,56 @@ protected function mapOrgIdentitycoPersonId(array $row): ?int

$oid = (int)$row['id'];

if(!isset($this->cache['org_identities']['co_people'])) {
if(empty($this->cache['org_identities']['co_people'])) {
$this->cache['org_identities']['co_people'] = [];
}

// Guard 1: If we already have this org identity mapped, return immediately
if (isset($this->cache['org_identities']['co_people'][$oid])) {
return $this->cache['org_identities']['co_people'][$oid];
}

// Build cache on first use
$this->io->info('Populating org identity map...');

$tableName = 'cm_co_org_identity_links';
$changelogFK = 'co_org_identity_link_id';
$qualifiedTableName = $this->inconn->qualifyTableName($tableName);

// Only fetch current rows (historical/deleted rows are filtered out)
$mapsql = RawSqlQueries::buildSelectAll(
qualifiedTableName: $qualifiedTableName,
onlyCurrent: true,
changelogFK: $changelogFK
);

$stmt = $this->inconn->executeQuery($mapsql);

while ($r = $stmt->fetchAssociative()) {
if (!empty($r['org_identity_id'])) {
$rOid = (int)$r['org_identity_id'];
$cop = isset($r['co_person_id']) ? (int)$r['co_person_id'] : null;

if ($cop === null) {
// Defensive: skip rows without a co_person_id
$this->io->warning('Org Identity ' . $rOid . ' has no mapped CO Person ID, skipping');
continue;
}

if (isset($this->cache['org_identities']['co_people'][$rOid])) {
// Unexpected duplicate "current" mapping, keep the first and warn
$this->io->warning('Found duplicate current CO Person mapping for Org Identity ' . $rOid . ', skipping');
continue;
// Build cache on first use
$this->io->info('Populating org identity map...');

$tableName = 'cm_co_org_identity_links';
$changelogFK = 'co_org_identity_link_id';
$qualifiedTableName = $this->inconn->qualifyTableName($tableName);

// Only fetch current rows (historical/deleted rows are filtered out)
$mapsql = RawSqlQueries::buildSelectAll(
qualifiedTableName: $qualifiedTableName,
onlyCurrent: true,
changelogFK: $changelogFK
);

$stmt = $this->inconn->executeQuery($mapsql);

while ($r = $stmt->fetchAssociative()) {
if (!empty($r['org_identity_id'])) {
$rOid = (int)$r['org_identity_id'];
$rOrevision = (int)$r['revision'];
$cop = isset($r['co_person_id']) ? (int)$r['co_person_id'] : null;

if ($cop === null) {
$this->io->warning('Org Identity ' . $rOid . ' has no mapped CO Person ID, skipping');
continue;
}

if (isset($this->cache['org_identities']['co_people'][$rOid][$rOrevision])) {
// If for some reason we already have a record, it's probably due to
// improper unpooling from a legacy deployment. We'll accept only the
// first record and throw warnings on the others.
$this->io->verbose('Found duplicate current CO Person mapping for Org Identity ' . $rOid . ', skipping');
continue;
}

$this->cache['org_identities']['co_people'][$rOid][$rOrevision] = $cop;
}

$this->cache['org_identities']['co_people'][$rOid] = $cop;
}
}

// Return the now-cached mapping (or null if not present)
return $this->cache['org_identities']['co_people'][$oid] ?? null;
if (!empty($this->cache['org_identities']['co_people'][$oid])) {
// Return the record with the highest revision number
$rev = max(array_keys($this->cache['org_identities']['co_people'][ $oid ]));
return $this->cache['org_identities']['co_people'][$oid][$rev];
}

return null;
}

/**
Expand Down
184 changes: 0 additions & 184 deletions app/plugins/Transmogrify/src/Lib/Util/CommanLinePrinter.php

This file was deleted.

Loading

0 comments on commit edc7b39

Please sign in to comment.