From 310aa683e3f2d0d4279a39d5510aa2cff3fc3502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Wed, 14 Aug 2019 10:51:20 -0400 Subject: [PATCH] PMC-1060 --- workflow/engine/bin/tasks/cliWorkspaces.php | 1 + workflow/engine/classes/WorkspaceTools.php | 76 ++++++++++++--------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index d44c1c7d5..14daabc23 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -625,6 +625,7 @@ function database_upgrade($args) foreach ($workspaces as $workspace) { try { $workspace->upgradeDatabase(); + $workspace->close(); } catch (Exception $e) { G::outRes("> Error: " . CLI::error($e->getMessage()) . "\n"); } diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index 4400f8da9..c74663a92 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -1354,7 +1354,6 @@ class WorkspaceTools // Ending the schema update CLI::logging("-> Schema Updated\n"); - $this->closeDatabase(); return true; } @@ -2562,40 +2561,22 @@ class WorkspaceTools throw new Exception($errorMessage); } - // Clean the queries array - $listQueries = []; - // Canceled List - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_CANCELED')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_CANCELED')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_CANCELED')); - // Inbox List - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_INBOX')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_INBOX')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_INBOX')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListAppStatusId('LIST_INBOX')); - // Participated List - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_PARTICIPATED_LAST')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListUsrId('LIST_PARTICIPATED_LAST')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_PARTICIPATED_LAST')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListAppStatusId('LIST_PARTICIPATED_LAST')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListParticipatedLastCurrentUser()); - // Unassigned List - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListProId('LIST_UNASSIGNED')); - $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->updateListTasId('LIST_UNASSIGNED')); + // Updating PRO_ID field + $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListProId'); - // Run queries in multiple threads for update the list tables - $processesManager = new ProcessesManager($listQueries); - $processesManager->run(); + // Updating TAS_ID field + $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListTasId'); - // If exists an error throw an exception - if (!empty($processesManager->getErrors())) { - $errorMessage = ''; - foreach ($processesManager->getErrors() as $error) { - $errorMessage .= $error['rawAnswer'] . PHP_EOL; - } - throw new Exception($errorMessage); - } + // Updating USR_ID field + $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST'], 'updateListUsrId'); + // Updating APP_STATUS_ID field + $this->runUpdateListField(['LIST_INBOX', 'LIST_PARTICIPATED_LAST'], 'updateListAppStatusId'); + + // Updating Last Current User Information + $this->runUpdateListField(['LIST_PARTICIPATED_LAST'], 'updateListParticipatedLastCurrentUser'); + + // Updating flags for the list population $this->listFirstExecution('insert'); $this->listFirstExecution('insert', 'unassigned'); } @@ -2986,6 +2967,37 @@ class WorkspaceTools $stmt->executeQuery($this->updateListTasId('LIST_UNASSIGNED')); } + /** + * Run the update queries for the specified tables + * + * @param array $listTables + * @param string $methodName + * + * @throws Exception + */ + public function runUpdateListField(array $listTables, $methodName) { + // Clean the queries array + $listQueries = []; + + // Get the queries + foreach ($listTables as $listTable) { + $listQueries[] = new RunProcessUpgradeQuery($this->name, $this->$methodName($listTable)); + } + + // Run queries in multiple threads for update the list tables + $processesManager = new ProcessesManager($listQueries); + $processesManager->run(); + + // If exists an error throw an exception + if (!empty($processesManager->getErrors())) { + $errorMessage = ''; + foreach ($processesManager->getErrors() as $error) { + $errorMessage .= $error['rawAnswer'] . PHP_EOL; + } + throw new Exception($errorMessage); + } + } + /** * Return query to update PRO_ID in list table *