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
|
@ -81,10 +81,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
}
|
||||
|
||||
protected function _initUpgrade() {
|
||||
if (AIRTIME_CODE_VERSION > Application_Model_Preference::GetAirtimeVersion()) {
|
||||
$upgradeManager = new UpgradeManager();
|
||||
$upgradeManager->runUpgrades(array(new AirtimeUpgrader252()), (__DIR__ . "/controllers"));
|
||||
}
|
||||
UpgradeManager::checkIfUpgradeIsNeeded(); //This will do the upgrade too if it's needed...
|
||||
}
|
||||
|
||||
protected function _initHeadLink()
|
||||
|
|
|
@ -24,9 +24,12 @@ class ErrorController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
// Log exception, if logger available
|
||||
/* No idea why this doesn't work or why it was implemented like this. Disabling it -- Albert
|
||||
if (($log = $this->getLog())) {
|
||||
$log->crit($this->view->message, $errors->exception);
|
||||
}
|
||||
}*/
|
||||
//Logging that actually works: -- Albert
|
||||
Logging::error($this->view->message . ": " . $errors->exception);
|
||||
|
||||
// conditionally display exceptions
|
||||
if ($this->getInvokeArg('displayExceptions') == true) {
|
||||
|
|
|
@ -13,25 +13,19 @@ class UpgradeController extends Zend_Controller_Action
|
|||
return;
|
||||
}
|
||||
|
||||
$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());
|
||||
*/
|
||||
$didWePerformAnUpgrade = false;
|
||||
try {
|
||||
$upgradeManager = new UpgradeManager();
|
||||
$didWePerformAnUpgrade = $upgradeManager->runUpgrades($upgraders, __DIR__);
|
||||
$didWePerformAnUpgrade = $upgradeManager->doUpgrade();
|
||||
|
||||
if (!$didWePerformAnUpgrade) {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody("No upgrade was performed. The current Airtime version is " . AirtimeUpgrader::getCurrentVersion() . ".<br>");
|
||||
->appendBody("No upgrade was performed. The current schema version is " . Application_Model_Preference::GetSchemaVersion() . ".<br>");
|
||||
} else {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody("Upgrade to Airtime " . $upgrader->getNewVersion() . " OK<br>");
|
||||
->appendBody("Upgrade to Airtime schema version " . Application_Model_Preference::GetSchemaVersion() . " OK<br>");
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
-- Replacing system_version with schema_version
|
||||
DELETE FROM cc_pref WHERE keystr = 'system_version';
|
||||
INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '2.5.2');
|
||||
INSERT INTO cc_pref (keystr, valstr) VALUES ('schema_version', '2.5.2');
|
||||
|
||||
ALTER TABLE cc_show ADD COLUMN image_path varchar(255) DEFAULT '';
|
||||
ALTER TABLE cc_show_instances ADD COLUMN description varchar(255) DEFAULT '';
|
||||
|
|
|
@ -862,10 +862,22 @@ class Application_Model_Preference
|
|||
|
||||
return self::getValue("enable_stream_conf");
|
||||
}
|
||||
|
||||
public static function SetAirtimeVersion($version)
|
||||
|
||||
public static function GetSchemaVersion()
|
||||
{
|
||||
self::setValue("system_version", $version);
|
||||
$schemaVersion = self::getValue("schema_version");
|
||||
|
||||
//Pre-2.5.2 releases all used this ambiguous "system_version" key to represent both the code and schema versions...
|
||||
if (empty($schemaVersion)) {
|
||||
$schemaVersion = self::getValue("system_version");
|
||||
}
|
||||
|
||||
return $schemaVersion;
|
||||
}
|
||||
|
||||
public static function SetSchemaVersion($version)
|
||||
{
|
||||
self::setValue("schema_version", $version);
|
||||
}
|
||||
|
||||
public static function GetAirtimeVersion()
|
||||
|
|
|
@ -1232,6 +1232,7 @@ SELECT si.starts AS start_timestamp,
|
|||
si.id AS instance_id,
|
||||
si.record,
|
||||
s.url,
|
||||
s.image_path,
|
||||
starts,
|
||||
ends
|
||||
FROM cc_show_instances si
|
||||
|
|
|
@ -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…
Reference in New Issue