Skip to content

Commit

Permalink
closes #4079
Browse files Browse the repository at this point in the history
  • Loading branch information
crossan007 committed Mar 7, 2018
1 parent 8dd918e commit ba69ef3
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions src/ChurchCRM/Service/UpgradeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,48 @@ static public function upgradeDatabaseVersion()
}

//the database isn't at the current version. Start the upgrade
$dbUpdatesFile = file_get_contents(SystemURLs::getDocumentRoot() . '/mysql/upgrade.json');
$dbUpdates = json_decode($dbUpdatesFile, true);
$errorFlag = false;
$connection = Propel::getConnection();
foreach ($dbUpdates as $dbUpdate) {
if (in_array(SystemService::getDBVersion(), $dbUpdate['versions'])) {
$version = new Version();
$version->setVersion($dbUpdate['dbVersion']);
$version->setUpdateStart(new \DateTime());
$logger->info("New Version: " .$version->getVersion());
foreach ($dbUpdate['scripts'] as $dbScript) {
$scriptName = SystemURLs::getDocumentRoot() . $dbScript;
$logger->info("Upgrade DB - " . $scriptName);
if (pathinfo($scriptName, PATHINFO_EXTENSION) == "sql") {
SQLUtils::sqlImport($scriptName, $connection);
} else {
require_once ($scriptName);
}
}
if (!$errorFlag) {
$version->setUpdateEnd(new \DateTime());
$version->save();
}
try
{
$dbUpdatesFile = file_get_contents(SystemURLs::getDocumentRoot() . '/mysql/upgrade.json');
$dbUpdates = json_decode($dbUpdatesFile, true);
$errorFlag = false;
$connection = Propel::getConnection();
foreach ($dbUpdates as $dbUpdate) {
try{
if (in_array(SystemService::getDBVersion(), $dbUpdate['versions'])) {
$version = new Version();
$version->setVersion($dbUpdate['dbVersion']);
$version->setUpdateStart(new \DateTime());
$logger->info("New Version: " .$version->getVersion());
foreach ($dbUpdate['scripts'] as $dbScript) {
$scriptName = SystemURLs::getDocumentRoot() . $dbScript;
$logger->info("Upgrade DB - " . $scriptName);
if (pathinfo($scriptName, PATHINFO_EXTENSION) == "sql") {
SQLUtils::sqlImport($scriptName, $connection);
} else {
require_once ($scriptName);
}
}
if (!$errorFlag) {
$version->setUpdateEnd(new \DateTime());
$version->save();
}
}
}
}
// always rebuild the menu
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/rebuild_views.sql', $connection);
catch (\Exception $exc) {
$logger->error(gettext("Unable to execute upgrade").": ".$scriptName.": ".$exc->getMessage());
throw $exc;
}
}
// always rebuild the menu
SQLUtils::sqlImport(SystemURLs::getDocumentRoot() . '/mysql/upgrade/rebuild_views.sql', $connection);

return true;
return true;
}
catch (\Exception $exc){
$logger->error(gettext("Unable to execute database upgrade").": " . $exc->getMessage());
throw $exc; //allow the method requesting the upgrade to handle this failure also.
}
}

}

0 comments on commit ba69ef3

Please sign in to comment.