This commit is contained in:
Julio Cesar Laura Avendaño
2019-08-14 10:51:20 -04:00
parent 2c618e68b1
commit 310aa683e3
2 changed files with 45 additions and 32 deletions

View File

@@ -625,6 +625,7 @@ function database_upgrade($args)
foreach ($workspaces as $workspace) { foreach ($workspaces as $workspace) {
try { try {
$workspace->upgradeDatabase(); $workspace->upgradeDatabase();
$workspace->close();
} catch (Exception $e) { } catch (Exception $e) {
G::outRes("> Error: " . CLI::error($e->getMessage()) . "\n"); G::outRes("> Error: " . CLI::error($e->getMessage()) . "\n");
} }

View File

@@ -1354,7 +1354,6 @@ class WorkspaceTools
// Ending the schema update // Ending the schema update
CLI::logging("-> Schema Updated\n"); CLI::logging("-> Schema Updated\n");
$this->closeDatabase();
return true; return true;
} }
@@ -2562,40 +2561,22 @@ class WorkspaceTools
throw new Exception($errorMessage); throw new Exception($errorMessage);
} }
// Clean the queries array // Updating PRO_ID field
$listQueries = []; $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListProId');
// 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'));
// Run queries in multiple threads for update the list tables // Updating TAS_ID field
$processesManager = new ProcessesManager($listQueries); $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST', 'LIST_UNASSIGNED'], 'updateListTasId');
$processesManager->run();
// If exists an error throw an exception // Updating USR_ID field
if (!empty($processesManager->getErrors())) { $this->runUpdateListField(['LIST_CANCELED', 'LIST_INBOX', 'LIST_PARTICIPATED_LAST'], 'updateListUsrId');
$errorMessage = '';
foreach ($processesManager->getErrors() as $error) {
$errorMessage .= $error['rawAnswer'] . PHP_EOL;
}
throw new Exception($errorMessage);
}
// 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');
$this->listFirstExecution('insert', 'unassigned'); $this->listFirstExecution('insert', 'unassigned');
} }
@@ -2986,6 +2967,37 @@ class WorkspaceTools
$stmt->executeQuery($this->updateListTasId('LIST_UNASSIGNED')); $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 * Return query to update PRO_ID in list table
* *