From f2eecebeedb0153e1fde8b57a2e8f363bb220512 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 17 Sep 2014 13:07:18 -0400 Subject: [PATCH] Checkout commit --- airtime_mvc/application/upgrade/Upgrades.php | 73 ++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/airtime_mvc/application/upgrade/Upgrades.php b/airtime_mvc/application/upgrade/Upgrades.php index c371e0461..cd0e24514 100644 --- a/airtime_mvc/application/upgrade/Upgrades.php +++ b/airtime_mvc/application/upgrade/Upgrades.php @@ -206,4 +206,77 @@ class AirtimeUpgrader254 extends AirtimeUpgrader throw $e; } } +} + +class AirtimeUpgrader255 extends AirtimeUpgrader { + protected function getSupportedVersions() { + return array ( + '2.5.4' + ); + } + + public function getNewVersion() { + return '2.5.5'; + } + + public function upgrade() { + Cache::clear(); + assert ( $this->checkIfUpgradeSupported () ); + + $newVersion = $this->getNewVersion (); + + $con = Propel::getConnection (); + // $con->beginTransaction(); + try { + $this->toggleMaintenanceScreen ( true ); + Cache::clear (); + + // Begin upgrade + + // First, ensure there are no superadmins already. + $numberOfSuperAdmins = CcSubjsQuery::create ()->filterByDbType ( UTYPE_SUPERADMIN )->filterByDbLogin ( "sourcefabric_admin", Criteria::NOT_EQUAL )-> // Ignore sourcefabric_admin users + count (); + + // Only create a super admin if there isn't one already. + if ($numberOfSuperAdmins == 0) { + // Find the "admin" user and promote them to superadmin. + $adminUser = CcSubjsQuery::create ()->filterByDbLogin ( 'admin' )->findOne (); + if (! $adminUser) { + // TODO: Otherwise get the user with the lowest ID that is of type administrator: + // + $adminUser = CcSubjsQuery::create ()->filterByDbType ( UTYPE_ADMIN )->orderByDbId ( Criteria::ASC )->findOne (); + + if (! $adminUser) { + throw new Exception ( "Failed to find any users of type 'admin' ('A')." ); + } + } + + $adminUser = new Application_Model_User ( $adminUser->getDbId () ); + $adminUser->setType ( UTYPE_SUPERADMIN ); + $adminUser->save (); + Logging::info ( $_SERVER ['HTTP_HOST'] . ': ' . $newVersion . " Upgrade: Promoted user " . $adminUser->getLogin () . " to be a Super Admin." ); + + // Also try to promote the sourcefabric_admin user + $sofabAdminUser = CcSubjsQuery::create ()->filterByDbLogin ( 'sourcefabric_admin' )->findOne (); + if ($sofabAdminUser) { + $sofabAdminUser = new Application_Model_User ( $sofabAdminUser->getDbId () ); + $sofabAdminUser->setType ( UTYPE_SUPERADMIN ); + $sofabAdminUser->save (); + Logging::info ( $_SERVER ['HTTP_HOST'] . ': ' . $newVersion . " Upgrade: Promoted user " . $sofabAdminUser->getLogin () . " to be a Super Admin." ); + } + } + + // $con->commit(); + Application_Model_Preference::SetAirtimeVersion ( $newVersion ); + Cache::clear (); + + $this->toggleMaintenanceScreen ( false ); + + return true; + } catch ( Exception $e ) { + // $con->rollback(); + $this->toggleMaintenanceScreen ( false ); + throw $e; + } + } } \ No newline at end of file