From 54875794e920a62a03a930ccde006529a543674e Mon Sep 17 00:00:00 2001 From: Scott Koranda Date: Mon, 1 Apr 2024 09:56:40 -0500 Subject: [PATCH] Transmogrify fix COU ordering issue (CFM-376) --- app/src/Command/TransmogrifyCommand.php | 31 +++- app/src/Lib/Util/TransmogrifyUtilities.php | 179 +++++++++++++++++++++ 2 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 app/src/Lib/Util/TransmogrifyUtilities.php diff --git a/app/src/Command/TransmogrifyCommand.php b/app/src/Command/TransmogrifyCommand.php index ced9173c6..eb70e4ead 100644 --- a/app/src/Command/TransmogrifyCommand.php +++ b/app/src/Command/TransmogrifyCommand.php @@ -40,6 +40,7 @@ use Cake\Utility\Inflector; use \App\Lib\Util\PaginatedSqlIterator; use \App\Lib\Util\DBALConnection; +use \App\Lib\Util\TransmogrifyUtilities; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; @@ -118,7 +119,8 @@ class TransmogrifyCommand extends Command { ], 'cous' => [ 'source' => 'cm_cous', - 'displayField' => 'name' + 'displayField' => 'name', + 'sqlSelect' => 'couSqlSelect' ], //'dashboards' => [ 'source' => 'cm_co_dashboards' ] 'people' => [ @@ -465,6 +467,26 @@ protected function check_group_membership(array $origRow, array $row) { } } + /** + * Return SQL used to select COUs 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 couSqlSelect(string $tableName): string { + if($this->inconn->isMySQL()) { + $sqlTemplate = TransmogrifyUtilities::COU_SQL_SELECT_TEMPLATE_MYSQL; + } else { + $sqlTemplate = TransmogrifyUtilities::COU_SQL_SELECT_TEMPLATE_POSTGRESQL; + } + + $sql = str_replace('{table}', $tableName, $sqlTemplate); + + return $sql; + } + /** * Create an Owners Group for an existing Group. * @@ -583,7 +605,12 @@ public function execute(Arguments $args, ConsoleIo $io) { $count = $this->inconn->fetchOne("SELECT COUNT(*) FROM " . $qualifiedTableName); // Select all the rows from the inbound table. - $insql = "SELECT * FROM " . $qualifiedTableName . " ORDER BY id ASC"; + if(!empty($this->tables[$t]['sqlSelect'])) { + $p = $this->tables[$t]['sqlSelect']; + $insql = $this->$p($qualifiedTableName); + } else { + $insql = "SELECT * FROM " . $qualifiedTableName . " ORDER BY id ASC"; + } $stmt = $this->inconn->executeQuery($insql); $tally = 0; diff --git a/app/src/Lib/Util/TransmogrifyUtilities.php b/app/src/Lib/Util/TransmogrifyUtilities.php new file mode 100644 index 000000000..65be538f8 --- /dev/null +++ b/app/src/Lib/Util/TransmogrifyUtilities.php @@ -0,0 +1,179 @@ +