filterByKeystr('system_version') ->findOne(); $airtime_version = $pref->getValStr(); return $airtime_version; } /** * This function checks to see if this class can perform an upgrade of your version of Airtime * @return boolean True if we can upgrade your version of Airtime. */ public function checkIfUpgradeSupported() { if (!in_array(AirtimeUpgrader::getCurrentVersion(), $this->getSupportedVersions())) { return false; } return true; } protected function toggleMaintenanceScreen($toggle) { if ($toggle) { //Disable Airtime UI //create a temporary maintenance notification file //when this file is on the server, zend framework redirects all //requests to the maintenance page and sets a 503 response code /* DISABLED because this does not work correctly $this->maintenanceFile = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."maintenance.txt" : "/tmp/maintenance.txt"; $file = fopen($this->maintenanceFile, 'w'); fclose($file); */ } else { //delete maintenance.txt to give users access back to Airtime /* DISABLED because this does not work correctly if ($this->maintenanceFile) { unlink($this->maintenanceFile); }*/ } } /** Implement this for each new version of Airtime */ abstract public function upgrade(); } class AirtimeUpgrader253 extends AirtimeUpgrader { protected function getSupportedVersions() { return array('2.5.1', '2.5.2'); } public function getNewVersion() { return '2.5.3'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $con = Propel::getConnection(); $con->beginTransaction(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); //Begin upgrade //Update disk_usage value in cc_pref $musicDir = CcMusicDirsQuery::create() ->filterByType('stor') ->filterByExists(true) ->findOne(); $storPath = $musicDir->getDirectory(); //Update disk_usage value in cc_pref $storDir = isset($_SERVER['AIRTIME_BASE']) ? $_SERVER['AIRTIME_BASE']."srv/airtime/stor" : "/srv/airtime/stor"; $diskUsage = shell_exec("du -sb $storDir | awk '{print $1}'"); Application_Model_Preference::setDiskUsage($diskUsage); //clear out the cache Cache::clear(); $con->commit(); //update system_version in cc_pref and change some columns in cc_files $airtimeConf = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; $values = parse_ini_file($airtimeConf, true); $username = $values['database']['dbuser']; $password = $values['database']['dbpass']; $host = $values['database']['host']; $database = $values['database']['dbname']; passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_".$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\""); Application_Model_Preference::SetAirtimeVersion($this->getNewVersion()); //clear out the cache Cache::clear(); $this->toggleMaintenanceScreen(false); } catch (Exception $e) { $con->rollback(); $this->toggleMaintenanceScreen(false); } } } class AirtimeUpgrader254 extends AirtimeUpgrader { protected function getSupportedVersions() { return array('2.5.3'); } public function getNewVersion() { return '2.5.4'; } 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; } } } class AirtimeUpgrader255 extends AirtimeUpgrader { protected function getSupportedVersions() { return array ( '2.5.4' ); } public function getNewVersion() { return '2.5.5'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $newVersion = $this->getNewVersion(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); // Begin upgrade $airtimeConf = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; $values = parse_ini_file($airtimeConf, true); $username = $values['database']['dbuser']; $password = $values['database']['dbpass']; $host = $values['database']['host']; $database = $values['database']['dbname']; passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_" .$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\""); Application_Model_Preference::SetAirtimeVersion($newVersion); Cache::clear(); $this->toggleMaintenanceScreen(false); return true; } catch(Exception $e) { $this->toggleMaintenanceScreen(false); throw $e; } } } class AirtimeUpgrader259 extends AirtimeUpgrader { protected function getSupportedVersions() { return array ( '2.5.5' ); } public function getNewVersion() { return '2.5.9'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $newVersion = $this->getNewVersion(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); // Begin upgrade $airtimeConf = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; $values = parse_ini_file($airtimeConf, true); $username = $values['database']['dbuser']; $password = $values['database']['dbpass']; $host = $values['database']['host']; $database = $values['database']['dbname']; passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_" .$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\""); Application_Model_Preference::SetAirtimeVersion($newVersion); Cache::clear(); $this->toggleMaintenanceScreen(false); } catch(Exception $e) { $this->toggleMaintenanceScreen(false); throw $e; } } } class AirtimeUpgrader2510 extends AirtimeUpgrader { protected function getSupportedVersions() { return array ( '2.5.9' ); } public function getNewVersion() { return '2.5.10'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $newVersion = $this->getNewVersion(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); // Begin upgrade $airtimeConf = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; $values = parse_ini_file($airtimeConf, true); $username = $values['database']['dbuser']; $password = $values['database']['dbpass']; $host = $values['database']['host']; $database = $values['database']['dbname']; passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_" .$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\""); Application_Model_Preference::SetAirtimeVersion($newVersion); Cache::clear(); $this->toggleMaintenanceScreen(false); } catch(Exception $e) { $this->toggleMaintenanceScreen(false); throw $e; } } } class AirtimeUpgrader2511 extends AirtimeUpgrader { protected function getSupportedVersions() { return array ( '2.5.10' ); } public function getNewVersion() { return '2.5.11'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $newVersion = $this->getNewVersion(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); // Begin upgrade $queryResult = CcFilesQuery::create() ->select(array('disk_usage')) ->withColumn('SUM(CcFiles.filesize)', 'disk_usage') ->find(); $disk_usage = $queryResult[0]; Application_Model_Preference::setDiskUsage($disk_usage); Application_Model_Preference::SetAirtimeVersion($newVersion); Cache::clear(); $this->toggleMaintenanceScreen(false); } catch(Exception $e) { $this->toggleMaintenanceScreen(false); throw $e; } } public function downgrade() { } } class AirtimeUpgrader2512 extends AirtimeUpgrader { protected function getSupportedVersions() { return array ( '2.5.10', '2.5.11' ); } public function getNewVersion() { return '2.5.12'; } public function upgrade($dir = __DIR__) { Cache::clear(); assert($this->checkIfUpgradeSupported()); $newVersion = $this->getNewVersion(); try { $this->toggleMaintenanceScreen(true); Cache::clear(); // Begin upgrade $airtimeConf = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; $values = parse_ini_file($airtimeConf, true); $username = $values['database']['dbuser']; $password = $values['database']['dbpass']; $host = $values['database']['host']; $database = $values['database']['dbname']; passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_" .$this->getNewVersion()."/upgrade.sql $database 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\""); Application_Model_Preference::SetAirtimeVersion($newVersion); Cache::clear(); $this->toggleMaintenanceScreen(false); } catch(Exception $e) { $this->toggleMaintenanceScreen(false); throw $e; } } public function downgrade() { } }