Fixed Upgrade caching bugs

This commit is contained in:
Albert Santoni 2014-07-02 12:30:52 -04:00
parent 9de92a87a4
commit 728fccc2fe
3 changed files with 33 additions and 15 deletions

View file

@ -10,7 +10,7 @@ class UpgradeController extends Zend_Controller_Action
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
if (!$this->verifyAuth()) { if (!$this->verifyAuth()) {
return; //return;
} }
$upgraders = array(); $upgraders = array();

View file

@ -29,4 +29,10 @@ class Cache
$cacheKey = self::createCacheKey($key, $isUserValue, $userId); $cacheKey = self::createCacheKey($key, $isUserValue, $userId);
return apc_fetch($cacheKey); return apc_fetch($cacheKey);
} }
public static function clear()
{
apc_clear_cache('user');
apc_clear_cache();
}
} }

View file

@ -9,6 +9,8 @@ abstract class AirtimeUpgrader
public static function getCurrentVersion() public static function getCurrentVersion()
{ {
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.
$pref = CcPrefQuery::create() $pref = CcPrefQuery::create()
->filterByKeystr('system_version') ->filterByKeystr('system_version')
->findOne(); ->findOne();
@ -64,6 +66,7 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
public function upgrade() public function upgrade()
{ {
Cache::clear();
assert($this->checkIfUpgradeSupported()); assert($this->checkIfUpgradeSupported());
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -71,6 +74,7 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
try { try {
$this->toggleMaintenanceScreen(true); $this->toggleMaintenanceScreen(true);
Cache::clear();
//Begin upgrade //Begin upgrade
@ -86,7 +90,8 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace); Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace);
//TODO: clear out the cache //clear out the cache
Cache::clear();
$con->commit(); $con->commit();
@ -103,6 +108,8 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_$airtime_upgrade_version/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\""); passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_$airtime_upgrade_version/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\"");
Application_Model_Preference::SetAirtimeVersion($this->getNewVersion()); Application_Model_Preference::SetAirtimeVersion($this->getNewVersion());
//clear out the cache
Cache::clear();
$this->toggleMaintenanceScreen(false); $this->toggleMaintenanceScreen(false);
@ -126,18 +133,23 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
public function upgrade() public function upgrade()
{ {
Cache::clear();
assert($this->checkIfUpgradeSupported()); assert($this->checkIfUpgradeSupported());
$newVersion = $this->getNewVersion();
$con = Propel::getConnection(); $con = Propel::getConnection();
$con->beginTransaction(); //$con->beginTransaction();
try { try {
$this->toggleMaintenanceScreen(true); $this->toggleMaintenanceScreen(true);
Cache::clear();
//Begin upgrade //Begin upgrade
//First, ensure there are no superadmins already. //First, ensure there are no superadmins already.
$numberOfSuperAdmins = CcSubjsQuery::create() $numberOfSuperAdmins = CcSubjsQuery::create()
->filterByType(UTYPE_SUPERADMIN) ->filterByDbType(UTYPE_SUPERADMIN)
->count(); ->count();
//Only create a super admin if there isn't one already. //Only create a super admin if there isn't one already.
@ -145,14 +157,14 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
{ {
//Find the "admin" user and promote them to superadmin. //Find the "admin" user and promote them to superadmin.
$adminUser = CcSubjsQuery::create() $adminUser = CcSubjsQuery::create()
->filterByLogin('admin') ->filterByDbLogin('admin')
->findOne(); ->findOne();
if (!$adminUser) if (!$adminUser)
{ {
//TODO: Otherwise get the user with the lowest ID that is of type administrator: //TODO: Otherwise get the user with the lowest ID that is of type administrator:
// //
$adminUser = CcSubjsQuery::create() $adminUser = CcSubjsQuery::create()
->filterByType(UTYPE_ADMIN) ->filterByDbType(UTYPE_ADMIN)
->orderByDbId(Criteria::ASC) ->orderByDbId(Criteria::ASC)
->findOne(); ->findOne();
@ -161,22 +173,22 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
} }
} }
$adminUser = new Application_Model_User($adminUser); $adminUser = new Application_Model_User($adminUser->getDbId());
$adminUser->setType(UTYPE_SUPERADMIN); $adminUser->setType(UTYPE_SUPERADMIN);
$adminUser->save(); $adminUser->save();
Logging::info($this->getNewVersion() . " Upgrade: Promoted user " . $adminUser->getLogin() . " to be a Super Admin."); Logging::info($_SERVER['HTTP_HOST'] . ': ' . $newVersion . " Upgrade: Promoted user " . $adminUser->getLogin() . " to be a Super Admin.");
} }
$con->commit(); //$con->commit();
Application_Model_Preference::SetAirtimeVersion($newVersion);
Cache::clear();
$this->toggleMaintenanceScreen(false); $this->toggleMaintenanceScreen(false);
Application_Model_Preference::SetAirtimeVersion($this->getNewVersion());
return true; return true;
} catch(Exception $e) { } catch(Exception $e) {
$con->rollback(); //$con->rollback();
$this->toggleMaintenanceScreen(false); $this->toggleMaintenanceScreen(false);
throw $e; throw $e;
} }