Format code using php-cs-fixer

This commit is contained in:
jo 2021-10-11 16:10:47 +02:00
parent 43d7dc92cd
commit d52c6184b9
352 changed files with 17473 additions and 17041 deletions

View file

@ -1,57 +1,60 @@
<?php
/**
* Check if a given classname belongs to a subclass of AirtimeUpgrader
* Check if a given classname belongs to a subclass of AirtimeUpgrader.
*
* @param $c string class name
*
* @return bool true if the $c is a subclass of AirtimeUpgrader
*/
function isUpgrade($c) {
return is_subclass_of($c, "AirtimeUpgrader");
function isUpgrade($c)
{
return is_subclass_of($c, 'AirtimeUpgrader');
}
/**
* Filter all declared classes to get all upgrade classes dynamically
* Filter all declared classes to get all upgrade classes dynamically.
*
* @return array all upgrade classes
*/
function getUpgrades() {
return array_filter(get_declared_classes(), "isUpgrade");
function getUpgrades()
{
return array_filter(get_declared_classes(), 'isUpgrade');
}
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.
*
* @return array a list of schema versions that this version of the codebase supports
*/
public static function getSupportedSchemaVersions()
{
$config = Config::getConfig();
//What versions of the schema does the code support today:
return array($config['airtime_version']);
return [$config['airtime_version']];
}
public static function checkIfUpgradeIsNeeded()
{
$schemaVersion = Application_Model_Preference::GetSchemaVersion();
$supportedSchemaVersions = self::getSupportedSchemaVersions();
return !in_array($schemaVersion, $supportedSchemaVersions);
}
/**
* Upgrade the Airtime schema version to match the highest supported version
* Upgrade the Airtime schema version to match the highest supported version.
*
* @return boolean whether or not an upgrade was performed
* @return bool whether or not an upgrade was performed
*/
public static function doUpgrade()
{
// Get all upgrades dynamically (in declaration order!) so we don't have to add them explicitly each time
// TODO: explicitly sort classnames by ascending version suffix for safety
$upgraders = getUpgrades();
$dir = (dirname(__DIR__) . "/controllers");
$dir = (dirname(__DIR__) . '/controllers');
$upgradePerformed = false;
foreach ($upgraders as $upgrader) {
@ -62,16 +65,16 @@ class UpgradeManager
}
/**
* Downgrade the Airtime schema version to match the given version
* Downgrade the Airtime schema version to match the given version.
*
* @param string $toVersion the version we want to downgrade to
*
* @return boolean whether or not an upgrade was performed
* @return bool whether or not an upgrade was performed
*/
public static function doDowngrade($toVersion)
{
$downgraders = array_reverse(getUpgrades()); // Reverse the array because we're downgrading
$dir = (dirname(__DIR__) . "/controllers");
$dir = (dirname(__DIR__) . '/controllers');
$downgradePerformed = false;
foreach ($downgraders as $downgrader) {
@ -87,40 +90,45 @@ class UpgradeManager
}
/**
* Run the given upgrade
* Run the given upgrade.
*
* @param $upgrader AirtimeUpgrader the upgrader class to be executed
*
* @return bool true if the upgrade was successful, otherwise false
*/
private static function _runUpgrade(AirtimeUpgrader $upgrader) {
private static function _runUpgrade(AirtimeUpgrader $upgrader)
{
return $upgrader->checkIfUpgradeSupported() && $upgrader->upgrade();
}
/**
* Run the given downgrade
* Run the given downgrade.
*
* @param $downgrader AirtimeUpgrader the upgrader class to be executed
* @param $supportedVersions array array of supported versions
*
* @return bool true if the downgrade was successful, otherwise false
*/
private static function _runDowngrade(AirtimeUpgrader $downgrader) {
private static function _runDowngrade(AirtimeUpgrader $downgrader)
{
return $downgrader->checkIfDowngradeSupported() && $downgrader->downgrade();
}
}
abstract class AirtimeUpgrader
{
protected $_dir;
protected $username, $password, $host, $database;
protected $username;
protected $password;
protected $host;
protected $database;
/**
* @param $dir string directory housing upgrade files
*/
public function __construct($dir) {
public function __construct($dir)
{
$this->_dir = $dir;
}
@ -136,8 +144,9 @@ abstract class AirtimeUpgrader
}
/**
* 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.
* This function checks to see if this class can perform an upgrade of your version of Airtime.
*
* @return bool true if we can upgrade your version of Airtime
*/
public function checkIfUpgradeSupported()
{
@ -145,9 +154,9 @@ abstract class AirtimeUpgrader
}
/**
* This function checks to see if this class can perform a downgrade of your version of Airtime
* This function checks to see if this class can perform a downgrade of your version of Airtime.
*
* @return boolean True if we can downgrade your version of Airtime.
* @return bool true if we can downgrade your version of Airtime
*/
public function checkIfDowngradeSupported()
{
@ -156,8 +165,7 @@ abstract class AirtimeUpgrader
protected function toggleMaintenanceScreen($toggle)
{
if ($toggle)
{
if ($toggle) {
//Disable Airtime UI
//create a temporary maintenance notification file
//when this file is on the server, zend framework redirects all
@ -167,21 +175,21 @@ abstract class AirtimeUpgrader
$file = fopen($this->maintenanceFile, 'w');
fclose($file);
*/
} else {
//delete maintenance.txt to give users access back to Airtime
}
//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
* This function abstracts out the core upgrade functionality,
* allowing child classes to overwrite _runUpgrade to reduce duplication
* allowing child classes to overwrite _runUpgrade to reduce duplication.
*/
public function upgrade() {
public function upgrade()
{
try {
// $this->toggleMaintenanceScreen(true);
@ -191,9 +199,10 @@ abstract class AirtimeUpgrader
Application_Model_Preference::SetSchemaVersion($this->getNewVersion());
// $this->toggleMaintenanceScreen(false);
} catch(Exception $e) {
} catch (Exception $e) {
// $this->toggleMaintenanceScreen(false);
Logging::error('Error in upgrade: '. $e->getMessage());
Logging::error('Error in upgrade: ' . $e->getMessage());
return false;
}
@ -203,10 +212,10 @@ abstract class AirtimeUpgrader
/**
* Implement this for each new version of Airtime
* This function abstracts out the core downgrade functionality,
* allowing child classes to overwrite _runDowngrade to reduce duplication
* allowing child classes to overwrite _runDowngrade to reduce duplication.
*/
public function downgrade() {
public function downgrade()
{
try {
$this->_getDbValues();
$this->_runDowngrade();
@ -221,42 +230,43 @@ abstract class AirtimeUpgrader
// Set the schema version to the highest supported version so we don't skip versions when downgrading
Application_Model_Preference::SetSchemaVersion($highestSupportedVersion);
} catch(Exception $e) {
} catch (Exception $e) {
return false;
}
return true;
}
protected function _getDbValues() {
protected function _getDbValues()
{
$config = Config::getConfig();
$this->username = $config['dsn']['username'];
$this->password = $config['dsn']['password'];
$this->host = $config['dsn']['hostspec'];
$this->host = $config['dsn']['hostspec'];
$this->database = $config['dsn']['database'];
}
protected function _runUpgrade() {
passthru("export PGPASSWORD=".$this->password." && /usr/bin/psql -h ".$this->host." -U ".$this->username." -q -f ".$this->_dir."/upgrade_sql/airtime_"
.$this->getNewVersion()."/upgrade.sql ".$this->database." 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\"");
protected function _runUpgrade()
{
passthru('export PGPASSWORD=' . $this->password . ' && /usr/bin/psql -h ' . $this->host . ' -U ' . $this->username . ' -q -f ' . $this->_dir . '/upgrade_sql/airtime_'
. $this->getNewVersion() . '/upgrade.sql ' . $this->database . ' 2>&1 | grep -v -E "will create implicit sequence|will create implicit index"');
}
protected function _runDowngrade() {
passthru("export PGPASSWORD=".$this->password." && /usr/bin/psql -h ".$this->host." -U ".$this->username." -q -f ".$this->_dir."/downgrade_sql/airtime_"
.$this->getNewVersion()."/downgrade.sql ".$this->database." 2>&1 | grep -v -E \"will create implicit sequence|will create implicit index\"");
protected function _runDowngrade()
{
passthru('export PGPASSWORD=' . $this->password . ' && /usr/bin/psql -h ' . $this->host . ' -U ' . $this->username . ' -q -f ' . $this->_dir . '/downgrade_sql/airtime_'
. $this->getNewVersion() . '/downgrade.sql ' . $this->database . ' 2>&1 | grep -v -E "will create implicit sequence|will create implicit index"');
}
}
class AirtimeUpgrader253 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions()
{
return array('2.5.1', '2.5.2');
return ['2.5.1', '2.5.2'];
}
public function getNewVersion()
{
return '2.5.3';
@ -265,8 +275,8 @@ class AirtimeUpgrader253 extends AirtimeUpgrader
protected function _runUpgrade()
{
//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}'");
$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);
@ -278,8 +288,9 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions()
{
return array('2.5.3');
return ['2.5.3'];
}
public function getNewVersion()
{
return '2.5.4';
@ -290,23 +301,24 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
//First, ensure there are no superadmins already.
$numberOfSuperAdmins = CcSubjsQuery::create()
->filterByDbType(UTYPE_SUPERADMIN)
->filterByDbLogin("sourcefabric_admin", Criteria::NOT_EQUAL) //Ignore sourcefabric_admin users
->count();
->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)
{
if ($numberOfSuperAdmins == 0) {
//Find the "admin" user and promote them to superadmin.
$adminUser = CcSubjsQuery::create()
->filterByDbLogin('admin')
->findOne();
if (!$adminUser)
{
->findOne()
;
if (!$adminUser) {
// Otherwise get the user with the lowest ID that is of type administrator:
$adminUser = CcSubjsQuery::create()
->filterByDbType(UTYPE_ADMIN)
->orderByDbId(Criteria::ASC)
->findOne();
->findOne()
;
if (!$adminUser) {
throw new Exception("Failed to find any users of type 'admin' ('A').");
@ -316,76 +328,89 @@ class AirtimeUpgrader254 extends AirtimeUpgrader
$adminUser = new Application_Model_User($adminUser->getDbId());
$adminUser->setType(UTYPE_SUPERADMIN);
$adminUser->save();
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . " Upgrade: Promoted user " . $adminUser->getLogin() . " to be a Super Admin.");
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . ' 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();
->findOne()
;
if ($sofabAdminUser) {
$sofabAdminUser = new Application_Model_User($sofabAdminUser->getDbId());
$sofabAdminUser->setType(UTYPE_SUPERADMIN);
$sofabAdminUser->save();
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . " Upgrade: Promoted user " . $sofabAdminUser->getLogin() . " to be a Super Admin.");
Logging::info($_SERVER['HTTP_HOST'] . ': ' . $this->getNewVersion() . ' Upgrade: Promoted user ' . $sofabAdminUser->getLogin() . ' to be a Super Admin.');
}
}
}
}
class AirtimeUpgrader255 extends AirtimeUpgrader {
protected function getSupportedSchemaVersions() {
return array (
'2.5.4'
);
class AirtimeUpgrader255 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions()
{
return [
'2.5.4',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.5';
}
}
class AirtimeUpgrader259 extends AirtimeUpgrader {
protected function getSupportedSchemaVersions() {
return array (
'2.5.5'
);
class AirtimeUpgrader259 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions()
{
return [
'2.5.5',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.9';
}
}
class AirtimeUpgrader2510 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
'2.5.9'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.9',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.10';
}
}
class AirtimeUpgrader2511 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
'2.5.10'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.10',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.11';
}
protected function _runUpgrade() {
protected function _runUpgrade()
{
$queryResult = CcFilesQuery::create()
->select(array('disk_usage'))
->select(['disk_usage'])
->withColumn('SUM(CcFiles.filesize)', 'disk_usage')
->find();
->find()
;
$disk_usage = $queryResult[0];
Application_Model_Preference::setDiskUsage($disk_usage);
}
@ -393,20 +418,22 @@ class AirtimeUpgrader2511 extends AirtimeUpgrader
class AirtimeUpgrader2512 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
protected function getSupportedSchemaVersions()
{
return [
'2.5.10',
'2.5.11'
);
'2.5.11',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.12';
}
}
/**
* Class AirtimeUpgrader2513 - Celery and SoundCloud upgrade
* Class AirtimeUpgrader2513 - Celery and SoundCloud upgrade.
*
* Adds third_party_track_references and celery_tasks tables for third party service
* authentication and task architecture.
@ -428,41 +455,44 @@ class AirtimeUpgrader2512 extends AirtimeUpgrader
* name -> string external Celery task name
* dispatch_time -> timestamp internal message dispatch time
* status -> string external Celery task status
*
*/
class AirtimeUpgrader2513 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
'2.5.12'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.12',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.13';
}
}
/**
* Class AirtimeUpgrader2514
* Class AirtimeUpgrader2514.
*
* SAAS-923 - Add a partial constraint to cc_pref so that keystrings must be unique
*/
class AirtimeUpgrader2514 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
'2.5.13'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.13',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.14';
}
}
/**
* Class AirtimeUpgrader2515
* Class AirtimeUpgrader2515.
*
* SAAS-1071 - Remove not null constraint from file_id fk in third_party_track_references
* so that we can create track references for downloads (which won't have a file
@ -470,184 +500,205 @@ class AirtimeUpgrader2514 extends AirtimeUpgrader
*/
class AirtimeUpgrader2515 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array (
'2.5.14'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.14',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.15';
}
}
class AirtimeUpgrader2516 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'2.5.15'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.15',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '2.5.16';
}
}
class AirtimeUpgrader300alpha extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'2.5.16'
);
protected function getSupportedSchemaVersions()
{
return [
'2.5.16',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha';
}
}
class AirtimeUpgrader300alpha1 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.1';
}
}
class AirtimeUpgrader300alpha6 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.1'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.1',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.6';
}
}
/**
* Class AirtimeUpgrader300alpha7
* Class AirtimeUpgrader300alpha7.
*
* GH-#636 - https://github.com/LibreTime/libretime/pull/636 - Change dynamic smartblock to be default smartblock type
*/
class AirtimeUpgrader300alpha7 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.6'
);
}
public function getNewVersion() {
return '3.0.0-alpha.7';
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.6',
];
}
public function getNewVersion()
{
return '3.0.0-alpha.7';
}
}
/**
* Class AirtimeUpgrader300alpha7-1
* Class AirtimeUpgrader300alpha7-1.
*
* GH-#659 - https://github.com/LibreTime/libretime/pull/659/ - Add description and title to podcast episodes database table
*/
class AirtimeUpgrader300alpha7_1 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.7'
);
}
public function getNewVersion() {
return '3.0.0-alpha.7.1';
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.7',
];
}
public function getNewVersion()
{
return '3.0.0-alpha.7.1';
}
}
/**
* Class AirtimeUpgrader300alpha7-2
* Class AirtimeUpgrader300alpha7-2.
*
* GH-#704 - https://github.com/LibreTime/libretime/pull/704/ - Add criteria group to smartblock table to enable database to store separately
*/
class AirtimeUpgrader300alpha7_2 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.7.1'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.7.1',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.7.2';
}
}
class AirtimeUpgrader300alpha7_3 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.7.2'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.7.2',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.7.3';
}
}
class AirtimeUpgrader300alpha9_1 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.7.3'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.7.3',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.9.1';
}
}
class AirtimeUpgrader300alpha9_2 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.9.1'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.9.1',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.9.2';
}
}
class AirtimeUpgrader200alpha9_3 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.9.2'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.9.2',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.9.3';
}
}
class AirtimeUpgrader200alpha9_4 extends AirtimeUpgrader
{
protected function getSupportedSchemaVersions() {
return array(
'3.0.0-alpha.9.3'
);
protected function getSupportedSchemaVersions()
{
return [
'3.0.0-alpha.9.3',
];
}
public function getNewVersion() {
public function getNewVersion()
{
return '3.0.0-alpha.9.4';
}
}
}