SAAS-547: Refactor upgrade procedure in 2.5.x-installer branch
* Start using "schema_version" key instead of "system_version" * Refactored the upgrade code a bit and make it be automatically invoked from the Zend bootstrap if a schema update is needed. * Fixed error logging in certain cases * Fixed an exception in Show related to image_path
This commit is contained in:
parent
5abe364a69
commit
2cb26db84b
7 changed files with 81 additions and 34 deletions
|
@ -1,6 +1,37 @@
|
|||
<?php
|
||||
|
||||
class UpgradeManager {
|
||||
class UpgradeManager
|
||||
{
|
||||
/** Used to determine if the database schema needs an upgrade in order for this version of the Airtime codebase to work correctly.
|
||||
* @return array A list of schema versions that this version of the codebase supports.
|
||||
*/
|
||||
public static function getSupportedSchemaVersions()
|
||||
{
|
||||
//What versions of the schema does the code support today:
|
||||
return array('2.5.2');
|
||||
}
|
||||
|
||||
public static function checkIfUpgradeIsNeeded()
|
||||
{
|
||||
$schemaVersion = Application_Model_Preference::GetSchemaVersion();
|
||||
$supportedSchemaVersions = self::getSupportedSchemaVersions();
|
||||
$upgradeNeeded = !in_array($schemaVersion, $supportedSchemaVersions);
|
||||
if ($upgradeNeeded) {
|
||||
self::doUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
public static function doUpgrade()
|
||||
{
|
||||
$upgradeManager = new UpgradeManager();
|
||||
$upgraders = array();
|
||||
array_push($upgraders, new AirtimeUpgrader252());
|
||||
/* These upgrades do not apply to open source Airtime yet.
|
||||
array_push($upgraders, new AirtimeUpgrader253());
|
||||
array_push($upgraders, new AirtimeUpgrader254());
|
||||
*/
|
||||
return $upgradeManager->runUpgrades(array(new AirtimeUpgrader252()), (__DIR__ . "/controllers"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a given set of upgrades
|
||||
|
@ -10,7 +41,7 @@ class UpgradeManager {
|
|||
* @return boolean whether or not an upgrade was performed
|
||||
*/
|
||||
public function runUpgrades($upgraders, $dir) {
|
||||
$upgradePerformed;
|
||||
$upgradePerformed = false;
|
||||
|
||||
for($i = 0; $i < count($upgraders); $i++) {
|
||||
$upgrader = $upgraders[$i];
|
||||
|
@ -29,20 +60,28 @@ class UpgradeManager {
|
|||
|
||||
abstract class AirtimeUpgrader
|
||||
{
|
||||
/** Versions that this upgrader class can upgrade from (an array of version strings). */
|
||||
abstract protected function getSupportedVersions();
|
||||
/** The version that this upgrader class will upgrade to. (returns a version string) */
|
||||
/** Schema versions that this upgrader class can upgrade from (an array of version strings). */
|
||||
abstract protected function getSupportedSchemaVersions();
|
||||
/** The schema version that this upgrader class will upgrade to. (returns a version string) */
|
||||
abstract public function getNewVersion();
|
||||
|
||||
public static function getCurrentVersion()
|
||||
public static function getCurrentSchemaVersion()
|
||||
{
|
||||
CcPrefPeer::clearInstancePool(); //Ensure we don't get a cached Propel object (cached DB results)
|
||||
//because we're updating this version number within this HTTP request as well.
|
||||
|
||||
//Old versions use system_version
|
||||
$pref = CcPrefQuery::create()
|
||||
->filterByKeystr('system_version')
|
||||
->findOne();
|
||||
$airtime_version = $pref->getValStr();
|
||||
return $airtime_version;
|
||||
if (empty($pref)) {
|
||||
//New versions use schema_version
|
||||
$pref = CcPrefQuery::create()
|
||||
->filterByKeystr('schema_version')
|
||||
->findOne();
|
||||
}
|
||||
$schema_version = $pref->getValStr();
|
||||
return $schema_version;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +90,7 @@ abstract class AirtimeUpgrader
|
|||
*/
|
||||
public function checkIfUpgradeSupported()
|
||||
{
|
||||
if (!in_array(AirtimeUpgrader::getCurrentVersion(), $this->getSupportedVersions())) {
|
||||
if (!in_array(AirtimeUpgrader::getCurrentSchemaVersion(), $this->getSupportedSchemaVersions())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -82,7 +121,7 @@ abstract class AirtimeUpgrader
|
|||
|
||||
/** This upgrade adds schema changes to accommodate show artwork and show instance descriptions */
|
||||
class AirtimeUpgrader252 extends AirtimeUpgrader {
|
||||
protected function getSupportedVersions() {
|
||||
protected function getSupportedSchemaVersions() {
|
||||
return array (
|
||||
'2.5.1'
|
||||
);
|
||||
|
@ -114,7 +153,7 @@ class AirtimeUpgrader252 extends AirtimeUpgrader {
|
|||
passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_"
|
||||
.$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\"");
|
||||
|
||||
Application_Model_Preference::SetAirtimeVersion($newVersion);
|
||||
Application_Model_Preference::SetSchemaVersion($newVersion);
|
||||
Cache::clear();
|
||||
|
||||
$this->toggleMaintenanceScreen(false);
|
||||
|
@ -129,7 +168,7 @@ class AirtimeUpgrader252 extends AirtimeUpgrader {
|
|||
|
||||
class AirtimeUpgrader253 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedVersions()
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return array('2.5.2');
|
||||
}
|
||||
|
@ -181,7 +220,7 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
|
|||
|
||||
passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_".$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\"");
|
||||
|
||||
Application_Model_Preference::SetAirtimeVersion($this->getNewVersion());
|
||||
Application_Model_Preference::SetSchemaVersion($this->getNewVersion());
|
||||
//clear out the cache
|
||||
Cache::clear();
|
||||
|
||||
|
@ -196,7 +235,7 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
|
|||
|
||||
class AirtimeUpgrader254 extends AirtimeUpgrader
|
||||
{
|
||||
protected function getSupportedVersions()
|
||||
protected function getSupportedSchemaVersions()
|
||||
{
|
||||
return array('2.5.3');
|
||||
}
|
||||
|
@ -266,7 +305,7 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
|
|||
}
|
||||
|
||||
//$con->commit();
|
||||
Application_Model_Preference::SetAirtimeVersion($newVersion);
|
||||
Application_Model_Preference::SetSchemaVersion($newVersion);
|
||||
Cache::clear();
|
||||
|
||||
$this->toggleMaintenanceScreen(false);
|
||||
|
@ -292,7 +331,7 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
|
|||
*
|
||||
*/
|
||||
class AirtimeUpgrader256 extends AirtimeUpgrader {
|
||||
protected function getSupportedVersions() {
|
||||
protected function getSupportedSchemaVersions() {
|
||||
return array (
|
||||
'2.5.4', '2.5.5'
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue