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

@ -8,7 +8,8 @@ class TestHelper
//pass to the adapter the submitted username and password
$authAdapter->setIdentity('admin')
->setCredential('admin');
->setCredential('admin')
;
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
@ -25,13 +26,14 @@ class TestHelper
public static function getDbZendConfig()
{
$config = Config::getConfig();
return new Zend_Config(
array(
'host' => $config['dsn']['hostspec'],
'dbname' => $config['dsn']['database'],
[
'host' => $config['dsn']['hostspec'],
'dbname' => $config['dsn']['database'],
'username' => $config['dsn']['username'],
'password' => $config['dsn']['password']
)
'password' => $config['dsn']['password'],
]
);
}
@ -40,36 +42,35 @@ class TestHelper
//We need to load the config before our app bootstrap runs. The config
//is normally
$CC_CONFIG = Config::getConfig();
$dbuser = $CC_CONFIG['dsn']['username'];
$dbpasswd = $CC_CONFIG['dsn']['password'];
$dbname = $CC_CONFIG['dsn']['database'];
$dbhost = $CC_CONFIG['dsn']['hostspec'];
$databaseAlreadyExists = AirtimeInstall::createDatabase();
if ($databaseAlreadyExists)
{
if ($databaseAlreadyExists) {
//Truncate all the tables
$con = Propel::getConnection();
$sql = "select * from pg_tables where tableowner = '${dbuser}'";
$sql = "select * from pg_tables where tableowner = '{$dbuser}'";
try {
$rows = $con->query($sql)->fetchAll();
} catch (Exception $e) {
$rows = array();
$rows = [];
}
//Add any tables that shouldn't be cleared here.
// cc_subjs - Most of Airtime requires an admin account to work, which has id=1,
// so don't clear it.
// cc_music_dirs - Has foreign key constraints against cc_files, so we clear cc_files
// cc_music_dirs - Has foreign key constraints against cc_files, so we clear cc_files
// first and clear cc_music_dirs after
$tablesToNotClear = array("cc_subjs", "cc_music_dirs");
$tablesToNotClear = ['cc_subjs', 'cc_music_dirs'];
$con->beginTransaction();
foreach ($rows as $row) {
$tablename = $row["tablename"];
if (in_array($tablename, $tablesToNotClear))
{
$tablename = $row['tablename'];
if (in_array($tablename, $tablesToNotClear)) {
continue;
}
//echo " * Clearing database table $tablename...";
@ -77,50 +78,51 @@ class TestHelper
//TRUNCATE is actually slower than DELETE in many cases:
//http://stackoverflow.com/questions/11419536/postgresql-truncation-speed
//$sql = "TRUNCATE TABLE $tablename CASCADE";
$sql = "DELETE FROM $tablename";
$sql = "DELETE FROM {$tablename}";
AirtimeInstall::InstallQuery($sql, false);
}
//Now that cc_files is empty, clearing cc_music_dirs should work
$sql = "DELETE FROM cc_music_dirs";
$sql = 'DELETE FROM cc_music_dirs';
AirtimeInstall::InstallQuery($sql, false);
// Because files are stored relative to their watch directory,
// we need to set the "stor" path before we can successfully
// create a fake file in the database.
//Copy paste from airtime-db-install.php:
$stor_dir = "/tmp";
$stor_dir = '/tmp';
$con = Propel::getConnection();
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('{$stor_dir}', 'stor')";
try {
$con->exec($sql);
} catch (Exception $e) {
echo " * Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
echo " * Message {$e->getMessage()}".PHP_EOL;
echo " * Failed inserting {$stor_dir} in cc_music_dirs" . PHP_EOL;
echo " * Message {$e->getMessage()}" . PHP_EOL;
return false;
}
$con->commit();
//Because we're DELETEing all the rows instead of using TRUNCATE (for speed),
//we have to reset the sequences so the auto-increment columns (like primary keys)
//all start at 1 again. This is hacky but it still lets all of this execute fast.
$sql = "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'";
try {
$rows = $con->query($sql)->fetchAll();
} catch (Exception $e) {
$rows = array();
$rows = [];
}
$con->beginTransaction();
foreach ($rows as $row) {
$seqrelname= $row["relname"];
$sql = "ALTER SEQUENCE ${seqrelname} RESTART WITH 1";
$seqrelname = $row['relname'];
$sql = "ALTER SEQUENCE {$seqrelname} RESTART WITH 1";
AirtimeInstall::InstallQuery($sql, false);
}
$con->commit();
}
else
{
} else {
//Create all the database tables
AirtimeInstall::CreateDatabaseTables($dbuser, $dbpasswd, $dbname, $dbhost);
AirtimeInstall::UpdateDatabaseTables();
@ -131,6 +133,7 @@ class TestHelper
{
$application = new Zend_Application(APPLICATION_ENV, CONFIG_PATH . 'application.ini');
$application->bootstrap();
return $application;
}
}