CC-1927: Remove PEAR DB
Fixed all install/upgrade scripts.
This commit is contained in:
parent
7f78a7f663
commit
95d69a3bbe
|
@ -17,7 +17,7 @@ require_once "DateHelper.php";
|
|||
require_once "OsPath.php";
|
||||
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
|
||||
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
global $CC_CONFIG; //, $CC_DBC;
|
||||
$dsn = $CC_CONFIG['dsn'];
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -27,6 +27,7 @@ $dsn = $CC_CONFIG['dsn'];
|
|||
// PDO returns false
|
||||
// ******************************************************************
|
||||
|
||||
|
||||
// $CC_DBC = DB::connect($dsn, FALSE);
|
||||
// if (PEAR::isError($CC_DBC)) {
|
||||
// echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
|
||||
|
@ -41,9 +42,14 @@ $dsn = $CC_CONFIG['dsn'];
|
|||
// $result = $CC_DBC->GetOne($sql);
|
||||
// var_dump($result);
|
||||
|
||||
// $con = Propel::getConnection();
|
||||
// $q = $con->query($sql);
|
||||
// //var_dump($q);
|
||||
// $sql = "SELECT 1";
|
||||
// try {
|
||||
// $con = Propel::getConnection();
|
||||
// //$q = $con->query($sql);
|
||||
// } catch (Exception $e) {
|
||||
// var_dump($e);
|
||||
// }
|
||||
// var_dump($q);
|
||||
// //var_dump($q->fetchAll());
|
||||
// var_dump($q->fetchColumn(0));
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* our custom changes requires the database parameters to be loaded from /etc/airtime/airtime.conf so
|
||||
* that the user can customize these.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
global $CC_CONFIG;
|
||||
|
||||
|
@ -17,12 +17,12 @@ $dbuser = $CC_CONFIG['dsn']['username'];
|
|||
$dbpass = $CC_CONFIG['dsn']['password'];
|
||||
|
||||
$conf = array (
|
||||
'datasources' =>
|
||||
'datasources' =>
|
||||
array (
|
||||
'airtime' =>
|
||||
'airtime' =>
|
||||
array (
|
||||
'adapter' => 'pgsql',
|
||||
'connection' =>
|
||||
'connection' =>
|
||||
array (
|
||||
'dsn' => "pgsql:host=$dbhost;port=5432;dbname=$dbname;user=$dbuser;password=$dbpass",
|
||||
),
|
||||
|
|
|
@ -5,7 +5,6 @@ if (file_exists('/usr/share/php/libzend-framework-php')){
|
|||
set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path());
|
||||
}
|
||||
require_once('Zend/Loader/Autoloader.php');
|
||||
require_once('DB.php');
|
||||
|
||||
class AirtimeInstall
|
||||
{
|
||||
|
@ -41,61 +40,46 @@ class AirtimeInstall
|
|||
|
||||
public static function GetVersionInstalled()
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
global $CC_CONFIG;
|
||||
$con = Propel::getConnection();
|
||||
|
||||
if(file_exists('/etc/airtime/airtime.conf')) {
|
||||
if (file_exists('/etc/airtime/airtime.conf')) {
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
}
|
||||
else {
|
||||
//echo "New Airtime Install.".PHP_EOL;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
$sql = "SELECT valstr FROM cc_pref WHERE keystr = 'system_version' LIMIT 1";
|
||||
$version = $con->query($sql)->fetchColumn(0);
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
//echo "New Airtime Install.".PHP_EOL;
|
||||
if (!$version) {
|
||||
// no pref table something is wrong.
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
$sql = "SELECT valstr FROM cc_pref WHERE keystr = 'system_version'";
|
||||
$version = $CC_DBC->GetOne($sql);
|
||||
|
||||
if (PEAR::isError($version)) {
|
||||
// no pref table something is wrong.
|
||||
return null;
|
||||
if ($version == '') {
|
||||
$sql = "SELECT * FROM cc_show_rebroadcast LIMIT 1";
|
||||
$result = $con->query($sql)->fetchColumn(0);
|
||||
if (!PEAR::isError($result)) {
|
||||
$version = "1.7.0";
|
||||
//echo "Airtime Version: ".$version." ".PHP_EOL;
|
||||
}
|
||||
|
||||
if ($version == '') {
|
||||
$sql = "SELECT * FROM cc_show_rebroadcast LIMIT 1";
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (!PEAR::isError($result)) {
|
||||
$version = "1.7.0";
|
||||
//echo "Airtime Version: ".$version." ".PHP_EOL;
|
||||
}
|
||||
else {
|
||||
$version = false;
|
||||
}
|
||||
else {
|
||||
$version = false;
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -103,35 +87,46 @@ class AirtimeInstall
|
|||
|
||||
public static function InstallQuery($sql, $verbose = true)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "Error! ".$result->getMessage()."\n";
|
||||
echo " SQL statement was:\n";
|
||||
echo " ".$sql."\n\n";
|
||||
} else {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$con->exec($sql);
|
||||
if ($verbose) {
|
||||
echo "done.\n";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "Error!\n".$e->getMessage()."\n";
|
||||
echo " SQL statement was:\n";
|
||||
echo " ".$sql."\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
public static function DropSequence($p_sequenceName)
|
||||
{
|
||||
AirtimeInstall::InstallQuery("DROP SEQUENCE IF EXISTS $p_sequenceName");
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect to the database. Return true on success, false on failure.
|
||||
* @param boolean $p_exitOnError
|
||||
* Exit the program on failure.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function DbConnect($p_exitOnError = true)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
global $CC_CONFIG;
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,7 +134,7 @@ class AirtimeInstall
|
|||
* install script. */
|
||||
public static function InstallStorageDirectory()
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
global $CC_CONFIG;
|
||||
echo "* Storage directory setup".PHP_EOL;
|
||||
|
||||
$ini = parse_ini_file(__DIR__."/airtime-install.ini");
|
||||
|
@ -231,10 +226,11 @@ class AirtimeInstall
|
|||
|
||||
public static function InstallPostgresScriptingLanguage()
|
||||
{
|
||||
global $CC_DBC;
|
||||
$con = Propel::getConnection();
|
||||
|
||||
// Install postgres scripting language
|
||||
$langIsInstalled = $CC_DBC->GetOne('SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\'');
|
||||
$sql = 'SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\'';
|
||||
$langIsInstalled = $con->query($sql)->fetchColumn(0);
|
||||
if ($langIsInstalled == '0') {
|
||||
echo " * Installing Postgres scripting language".PHP_EOL;
|
||||
$sql = "CREATE LANGUAGE 'plpgsql'";
|
||||
|
@ -250,15 +246,15 @@ class AirtimeInstall
|
|||
|
||||
// Put Propel sql files in Database
|
||||
//$command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql 2>/dev/null";
|
||||
|
||||
|
||||
$dir = AirtimeInstall::CONF_DIR_WWW."/build/sql/";
|
||||
$files = array("schema.sql", "sequences.sql", "views.sql", "triggers.sql", "defaultdata.sql");
|
||||
|
||||
|
||||
foreach ($files as $f){
|
||||
$command = "export PGPASSWORD=$p_dbpasswd && psql --username $p_dbuser --dbname $p_dbname --host $p_dbhost --file $dir$f 2>/dev/null";
|
||||
@exec($command, $output, $results);
|
||||
}
|
||||
|
||||
|
||||
AirtimeInstall::$databaseTablesCreated = true;
|
||||
}
|
||||
|
||||
|
@ -284,13 +280,13 @@ class AirtimeInstall
|
|||
|
||||
public static function SetAirtimeVersion($p_version)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$con = Propel::getConnection();
|
||||
$sql = "DELETE FROM cc_pref WHERE keystr = 'system_version'";
|
||||
$CC_DBC->query($sql);
|
||||
$con->exec($sql);
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '$p_version')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -298,54 +294,46 @@ class AirtimeInstall
|
|||
|
||||
public static function SetUniqueId()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$uniqueId = md5(uniqid("", true));
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('uniqueId', '$uniqueId')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$defaultTimezone = exec("cat /etc/timezone");
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function SetImportTimestamp()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('import_timestamp', '0')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function GetAirtimeVersion()
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT valstr FROM cc_pref WHERE keystr = 'system_version'";
|
||||
$version = $CC_DBC->GetOne($sql);
|
||||
|
||||
if (PEAR::isError($version)) {
|
||||
return false;
|
||||
}
|
||||
$con = Propel::getConnection();
|
||||
$sql = "SELECT valstr FROM cc_pref WHERE keystr = 'system_version' LIMIT 1";
|
||||
$version = $con->query($sql)->fetchColumn(0);
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
@ -473,21 +461,21 @@ class AirtimeInstall
|
|||
fwrite($fp, "$minute $hour * * * root /usr/lib/airtime/utils/phone_home_stat\n");
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
|
||||
public static function removeVirtualEnvDistributeFile(){
|
||||
echo "* Removing distribute-0.6.10.tar.gz".PHP_EOL;
|
||||
if(file_exists('/usr/share/python-virtualenv/distribute-0.6.10.tar.gz')){
|
||||
exec("rm -f /usr/share/python-virtualenv/distribute-0.6.10.tar.gz");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function printUsage($opts)
|
||||
{
|
||||
$msg = $opts->getUsageMessage();
|
||||
echo PHP_EOL."Usage: airtime-install [options]";
|
||||
echo substr($msg, strpos($msg, "\n")).PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
public static function getOpts()
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
* cannot be created. So this script is run after all DEB packages have been installed.
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
//set_include_path(__DIR__.'/../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require_once(dirname(__FILE__).'/AirtimeIni.php');
|
||||
require_once(dirname(__FILE__).'/AirtimeInstall.php');
|
||||
require_once(__DIR__.'/AirtimeIni.php');
|
||||
require_once(__DIR__.'/AirtimeInstall.php');
|
||||
require_once(__DIR__.'/airtime-constants.php');
|
||||
|
||||
require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/conf.php');
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(AirtimeInstall::GetAirtimeSrcDir()."/application/configs/airtime-conf-production.php");
|
||||
|
||||
echo PHP_EOL."* Database Installation".PHP_EOL;
|
||||
|
||||
|
@ -19,7 +21,7 @@ AirtimeInstall::CreateDatabaseUser();
|
|||
|
||||
$databaseExisted = AirtimeInstall::CreateDatabase();
|
||||
|
||||
AirtimeInstall::DbConnect(true);
|
||||
//AirtimeInstall::DbConnect(true);
|
||||
|
||||
AirtimeInstall::InstallPostgresScriptingLanguage();
|
||||
|
||||
|
@ -65,12 +67,13 @@ if (AirtimeInstall::$databaseTablesCreated) {
|
|||
|
||||
$stor_dir = realpath($ini["storage_dir"])."/";
|
||||
echo " * Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
try {
|
||||
$con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
echo " * Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
|
||||
echo " * Message {$result->getMessage()}".PHP_EOL;
|
||||
echo " * Message {$e->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
* Checks if a previous version of Airtime is currently installed and upgrades Airtime if so.
|
||||
* Performs a new install (new configs, database install) otherwise.
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/AirtimeIni.php');
|
||||
require_once(dirname(__FILE__).'/AirtimeInstall.php');
|
||||
require_once(__DIR__.'/AirtimeIni.php');
|
||||
require_once(__DIR__.'/AirtimeInstall.php');
|
||||
require_once(__DIR__.'/airtime-constants.php');
|
||||
|
||||
$version = AirtimeInstall::GetVersionInstalled();
|
||||
|
@ -18,7 +18,7 @@ $version = AirtimeInstall::GetVersionInstalled();
|
|||
// -------------------------------------------------------------------------
|
||||
|
||||
$newInstall = false;
|
||||
if(is_null($version)) {
|
||||
if (is_null($version)) {
|
||||
$newInstall = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ echo "* Uninstalling Airtime ".AIRTIME_VERSION.PHP_EOL;
|
|||
//------------------------------------------------------------------------
|
||||
// Delete the database
|
||||
// Note: Do not put a call to AirtimeInstall::DbConnect()
|
||||
// before this function, even if you called $CC_DBC->disconnect(), there will
|
||||
// still be a connection to the database and you wont be able to delete it.
|
||||
// before this function, it will create a connection to the database
|
||||
// and you wont be able to delete it.
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
//close connection for any process id using airtime database since we are about to drop the database.
|
||||
|
@ -47,12 +47,14 @@ $command = "su postgres -c \"dropdb ".$CC_CONFIG["dsn"]["database"]."\"";
|
|||
//------------------------------------------------------------------------
|
||||
if ($dbDeleteFailed) {
|
||||
echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL;
|
||||
AirtimeInstall::DbConnect(false);
|
||||
$connected = AirtimeInstall::DbConnect(false);
|
||||
|
||||
if (!PEAR::isError($CC_DBC)) {
|
||||
if ($connected) {
|
||||
$con = Propel::getConnection();
|
||||
$sql = "select * from pg_tables where tableowner = 'airtime'";
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
if (PEAR::isError($rows)) {
|
||||
try {
|
||||
$rows = $con->query($sql)->fetchAll();
|
||||
} catch (Exception $e) {
|
||||
$rows = array();
|
||||
}
|
||||
|
||||
|
@ -60,11 +62,10 @@ if ($dbDeleteFailed) {
|
|||
$tablename = $row["tablename"];
|
||||
echo " * Removing database table $tablename...";
|
||||
|
||||
if (AirtimeInstall::DbTableExists($tablename)){
|
||||
if (AirtimeInstall::DbTableExists($tablename)) {
|
||||
$sql = "DROP TABLE $tablename CASCADE";
|
||||
AirtimeInstall::InstallQuery($sql, false);
|
||||
|
||||
$CC_DBC->dropSequence($tablename."_id");
|
||||
AirtimeInstall::DropSequence($tablename."_id");
|
||||
}
|
||||
echo "done.".PHP_EOL;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,20 @@ require_once(__DIR__.'/airtime-constants.php');
|
|||
require_once(dirname(__FILE__).'/AirtimeIni.php');
|
||||
require_once(dirname(__FILE__).'/AirtimeInstall.php');
|
||||
|
||||
if(posix_geteuid() != 0){
|
||||
if(posix_geteuid() != 0) {
|
||||
echo "Must be root user.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
function pause(){
|
||||
require_once(__DIR__.'/airtime-constants.php');
|
||||
require_once(__DIR__.'/AirtimeIni.php');
|
||||
require_once(__DIR__.'/AirtimeInstall.php');
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(AirtimeInstall::GetAirtimeSrcDir()."/application/configs/airtime-conf-production.php");
|
||||
|
||||
|
||||
function pause()
|
||||
{
|
||||
/* Type "sudo -s" to change to root user then type "export AIRTIME_INSTALL_DEBUG=1" and then
|
||||
* start airtime-install to enable this feature. Is used to pause between upgrade scripts
|
||||
* to examine the state of the system and see if everything is as expected. */
|
||||
|
@ -26,33 +34,8 @@ function pause(){
|
|||
}
|
||||
}
|
||||
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
|
||||
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
exit(1);
|
||||
} else {
|
||||
echo "* Connected to database".PHP_EOL;
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
}
|
||||
AirtimeInstall::DbConnect(true);
|
||||
$con = Propel::getConnection();
|
||||
|
||||
$version = AirtimeInstall::GetVersionInstalled();
|
||||
|
||||
|
@ -121,13 +104,13 @@ if (strcmp($version, "2.1.0") < 0){
|
|||
|
||||
//set the new version in the database.
|
||||
$sql = "DELETE FROM cc_pref WHERE keystr = 'system_version'";
|
||||
$CC_DBC->query($sql);
|
||||
$con->exec($sql);
|
||||
|
||||
$values = parse_ini_file(CONF_FILE_AIRTIME, true);
|
||||
$phpDir = $values['general']['airtime_dir'];
|
||||
|
||||
$newVersion = AIRTIME_VERSION;
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '$newVersion')";
|
||||
$CC_DBC->query($sql);
|
||||
$con->exec($sql);
|
||||
|
||||
echo "******************************* Upgrade Complete *******************************".PHP_EOL;
|
||||
|
|
|
@ -55,6 +55,7 @@ $CC_CONFIG = array(
|
|||
);
|
||||
|
||||
AirtimeInstall::DbConnect(true);
|
||||
$con = Propel::getConnection();
|
||||
|
||||
echo PHP_EOL."*** Updating Database Tables ***".PHP_EOL;
|
||||
|
||||
|
@ -68,11 +69,11 @@ AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110406182005');
|
|||
|
||||
//setting data for new aggregate show length column.
|
||||
$sql = "SELECT id FROM cc_show_instances";
|
||||
$show_instances = $CC_DBC->GetAll($sql);
|
||||
$show_instances = $con->query($sql)->fetchAll();
|
||||
|
||||
foreach ($show_instances as $show_instance) {
|
||||
$sql = "UPDATE cc_show_instances SET time_filled = (SELECT SUM(clip_length) FROM cc_schedule WHERE instance_id = {$show_instance["id"]}) WHERE id = {$show_instance["id"]}";
|
||||
$CC_DBC->query($sql);
|
||||
$con->exec($sql);
|
||||
}
|
||||
//end setting data for new aggregate show length column.
|
||||
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
require_once 'conf.php';
|
||||
require_once 'DB.php';
|
||||
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
|
||||
set_include_path(__DIR__.'/propel' . PATH_SEPARATOR . get_include_path());
|
||||
Propel::init(__DIR__."/propel/airtime-conf.php");
|
||||
|
||||
|
@ -75,10 +65,11 @@ class AirtimeInstall{
|
|||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -99,7 +90,7 @@ class AirtimeInstall{
|
|||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
echo "Upgrading database, may take several minutes, please wait".PHP_EOL;
|
||||
|
||||
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$SCRIPTPATH = __DIR__;
|
||||
$command = "php --php-ini $SCRIPTPATH/../../airtime-php.ini ".
|
||||
|
@ -368,28 +359,26 @@ class AirtimeInstall{
|
|||
echo "* Inserting data into country table".PHP_EOL;
|
||||
Airtime190Upgrade::execSqlQuery($sql);
|
||||
}
|
||||
|
||||
|
||||
public static function SetUniqueId()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$uniqueId = md5(uniqid("", true));
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('uniqueId', '$uniqueId')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function SetImportTimestamp()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('import_timestamp', '0')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$result = $con->exec($sql);
|
||||
if ($result < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -586,31 +575,30 @@ class Airtime190Upgrade{
|
|||
}
|
||||
|
||||
|
||||
public static function execSqlQuery($sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed sql query: $sql".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
public static function execSqlQuery($sql)
|
||||
{
|
||||
$result = 0;
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
$result = $con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
echo "* Failed sql query: $sql".PHP_EOL;
|
||||
echo "* Message {$e->getMessage()}".PHP_EOL;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
public static function connectToDatabase()
|
||||
{
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function backupFileInfoInStorToFile($values) {
|
||||
|
@ -626,7 +614,7 @@ class Airtime190Upgrade{
|
|||
if ($baseDir[strlen($baseDir)-1] != '/'){
|
||||
$baseDir.='/';
|
||||
}
|
||||
|
||||
|
||||
$stor_dir = $baseDir.'stor';
|
||||
|
||||
|
||||
|
@ -696,7 +684,7 @@ class Airtime190Upgrade{
|
|||
|
||||
$pi = pathinfo($values['general']['base_files_dir']);
|
||||
$stor_dir = $pi["dirname"].DIRECTORY_SEPARATOR.$pi["basename"].DIRECTORY_SEPARATOR."stor".DIRECTORY_SEPARATOR;
|
||||
|
||||
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
$propel_stor_dir->setDirectory($stor_dir);
|
||||
$propel_stor_dir->save();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
require_once('DB.php');
|
||||
|
||||
/* These are helper functions that are common to each upgrade such as
|
||||
* creating connections to a database, backing up config files etc.
|
||||
*/
|
||||
|
@ -17,32 +15,31 @@ class UpgradeCommon{
|
|||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
const CONF_BACKUP_SUFFIX = "200";
|
||||
const VERSION_NUMBER = "2.0.0";
|
||||
|
||||
|
||||
public static function connectToDatabase($p_exitOnError = true)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -56,7 +53,7 @@ class UpgradeCommon{
|
|||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
echo "Upgrading database, may take several minutes, please wait".PHP_EOL;
|
||||
|
||||
|
||||
$appDir = self::GetAirtimeSrcDir();
|
||||
$command = "php --php-ini $dir/../../airtime-php.ini ".
|
||||
"$appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
|
@ -182,9 +179,9 @@ class UpgradeCommon{
|
|||
private static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
|
@ -233,16 +230,18 @@ class UpgradeCommon{
|
|||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function queryDb($p_sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->query($p_sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "Error executing $sql. Exiting.";
|
||||
public static function queryDb($p_sql)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
|
||||
try {
|
||||
$result = $con->exec($p_sql);
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing $p_sql. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,586 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/models' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/configs' . PATH_SEPARATOR . get_include_path());
|
||||
require_once 'conf.php';
|
||||
require_once 'DB.php';
|
||||
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(__DIR__."/../../../airtime_mvc/application/configs/airtime-conf.php");
|
||||
|
||||
class AirtimeInstall{
|
||||
const CONF_DIR_BINARIES = "/usr/lib/airtime";
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$defaultTimezone = date_default_timezone_get();
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function GetUtilsSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../utils";
|
||||
}
|
||||
|
||||
public static function InstallBinaries()
|
||||
{
|
||||
echo "* Installing binaries to ".AirtimeInstall::CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec("mkdir -p ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
exec("cp -R ".AirtimeInstall::GetUtilsSrcDir()." ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
}
|
||||
|
||||
public static function CreateSymlinksToUtils()
|
||||
{
|
||||
echo "* Installing airtime-log".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log";
|
||||
copy(AirtimeInstall::GetUtilsSrcDir()."/airtime-log.php", AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log.php");
|
||||
|
||||
exec("ln -s $dir /usr/bin/airtime-log");
|
||||
}
|
||||
|
||||
public static function SetDefaultStreamSetting()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
echo "* Setting up default stream setting".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '128');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('plan_level', 'disabled');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_bitrate', '128', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_host', '127.0.0.1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_port', '8000', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_pass', 'hackme', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_mount', 'airtime_128', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_url', 'http://airtime.sourcefabric.org', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_genre', '', 'string');";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function BypassMigrations($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction --add migrations:version $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction migrations:migrate $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function GetAirtimeSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../airtime_mvc";
|
||||
}
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function GetOldLiquidsoapCfgAndUpdate(){
|
||||
global $CC_DBC;
|
||||
echo "* Retrieving old liquidsoap configuration".PHP_EOL;
|
||||
$map = array();
|
||||
$fh = fopen("/etc/airtime/liquidsoap.cfg", 'r');
|
||||
$newConfigMap = array();
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$map[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
$newConfigMap['output_sound_device'] = $map['output_sound_device'];
|
||||
$newConfigMap['icecast_vorbis_metadata'] = $map['output_icecast_vorbis_metadata'];
|
||||
$newConfigMap['log_file'] = $map['log_file'];
|
||||
|
||||
$count = 1;
|
||||
if( $map['output_icecast_vorbis'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_vorbis'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "ogg";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_icecast_mp3'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_mp3'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_shoutcast'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'shoutcast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['shoutcast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['shoutcast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['shoutcast_pass'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['shoutcast_url'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['shoutcast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
foreach( $newConfigMap as $key=>$val){
|
||||
if(substr($val, 0, 1) == '"' && substr($val, strlen($val)-1,1)){
|
||||
$val = ltrim($val, '"');
|
||||
$val = rtrim($val, '"');
|
||||
}
|
||||
$sql .= "UPDATE cc_stream_setting SET value='$val' WHERE keyname='$key';";
|
||||
}
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Airtime200Upgrade{
|
||||
|
||||
public static function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
}
|
||||
|
||||
public static function InstallAirtimePhpServerCode($phpDir)
|
||||
{
|
||||
|
||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||
|
||||
// delete old files
|
||||
exec("rm -rf ".$phpDir);
|
||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||
exec("mkdir -p ".$phpDir);
|
||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||
}
|
||||
|
||||
public static function RemoveOldMonitFile(){
|
||||
unlink("/etc/monit/conf.d/airtime-monit.cfg");
|
||||
}
|
||||
}
|
||||
|
||||
class ConvertToUtc{
|
||||
|
||||
public static function setPhpDefaultTimeZoneToSystemTimezone(){
|
||||
//we can get the default system timezone on debian/ubuntu by reading "/etc/timezone"
|
||||
$filename = "/etc/timezone";
|
||||
$handle = fopen($filename, "r");
|
||||
$contents = trim(fread($handle, filesize($filename)));
|
||||
echo "System timezone detected as: $contents".PHP_EOL;
|
||||
fclose($handle);
|
||||
|
||||
date_default_timezone_set($contents);
|
||||
}
|
||||
|
||||
public static function convert_cc_playlist(){
|
||||
/* cc_playlist has a field that keeps track of when the playlist was last modified. */
|
||||
$playlists = CcPlaylistQuery::create()->find();
|
||||
|
||||
foreach ($playlists as $pl){
|
||||
$dt = new DateTime($pl->getDbMtime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$pl->setDbMtime($dt);
|
||||
|
||||
$pl->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_schedule(){
|
||||
/* cc_schedule has start and end fields that need to be changed to UTC. */
|
||||
$schedules = CcScheduleQuery::create()->find();
|
||||
|
||||
foreach ($schedules as $s){
|
||||
$dt = new DateTime($s->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($s->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbEnds($dt);
|
||||
|
||||
$s->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_days(){
|
||||
/* cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC. */
|
||||
$showDays = CcShowDaysQuery::create()->find();
|
||||
|
||||
foreach ($showDays as $sd){
|
||||
$dt = new DateTime($sd->getDbFirstShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbFirstShow($dt->format("Y-m-d"));
|
||||
$sd->setDbStartTime($dt->format("H:i:s"));
|
||||
|
||||
$dt = new DateTime($sd->getDbLastShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbLastShow($dt->format("Y-m-d"));
|
||||
|
||||
$sd->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_instances(){
|
||||
/* convert_cc_show_instances has starts and ends fields that need to be changed to UTC. */
|
||||
$showInstances = CcShowInstancesQuery::create()->find();
|
||||
|
||||
foreach ($showInstances as $si){
|
||||
$dt = new DateTime($si->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($si->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbEnds($dt);
|
||||
|
||||
$si->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeIni200{
|
||||
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
const CONF_FILE_PYPO = "/etc/airtime/pypo.cfg";
|
||||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
|
||||
const CONF_FILE_MEDIAMONITOR = "/etc/airtime/media-monitor.cfg";
|
||||
const CONF_FILE_API_CLIENT = "/etc/airtime/api_client.cfg";
|
||||
|
||||
const CONF_PYPO_GRP = "pypo";
|
||||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
|
||||
/**
|
||||
* This function updates an INI style config file.
|
||||
*
|
||||
* A property and the value the property should be changed to are
|
||||
* supplied. If the property is not found, then no changes are made.
|
||||
*
|
||||
* @param string $p_filename
|
||||
* The path the to the file.
|
||||
* @param string $p_property
|
||||
* The property to look for in order to change its value.
|
||||
* @param string $p_value
|
||||
* The value the property should be changed to.
|
||||
*
|
||||
*/
|
||||
public static function UpdateIniValue($p_filename, $p_property, $p_value)
|
||||
{
|
||||
$lines = file($p_filename);
|
||||
$n=count($lines);
|
||||
foreach ($lines as &$line) {
|
||||
if ($line[0] != "#"){
|
||||
$key_value = explode("=", $line);
|
||||
$key = trim($key_value[0]);
|
||||
|
||||
if ($key == $p_property){
|
||||
$line = "$p_property = $p_value".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fp=fopen($p_filename, 'w');
|
||||
for($i=0; $i<$n; $i++){
|
||||
fwrite($fp, $lines[$i]);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$values[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function MergeConfigFiles($configFiles, $suffix) {
|
||||
foreach ($configFiles as $conf) {
|
||||
// we want to use new liquidsoap.cfg so don't merge
|
||||
// also for monit
|
||||
if( $conf == AirtimeIni200::CONF_FILE_LIQUIDSOAP){
|
||||
continue;
|
||||
}
|
||||
if (file_exists("$conf$suffix.bak")) {
|
||||
|
||||
if($conf === AirtimeIni200::CONF_FILE_AIRTIME) {
|
||||
// Parse with sections
|
||||
$newSettings = parse_ini_file($conf, true);
|
||||
$oldSettings = parse_ini_file("$conf$suffix.bak", true);
|
||||
}
|
||||
else {
|
||||
$newSettings = AirtimeIni200::ReadPythonConfig($conf);
|
||||
$oldSettings = AirtimeIni200::ReadPythonConfig("$conf$suffix.bak");
|
||||
}
|
||||
|
||||
$settings = array_keys($newSettings);
|
||||
|
||||
foreach($settings as $section) {
|
||||
if(isset($oldSettings[$section])) {
|
||||
if(is_array($oldSettings[$section])) {
|
||||
$sectionKeys = array_keys($newSettings[$section]);
|
||||
foreach($sectionKeys as $sectionKey) {
|
||||
// skip airtim_dir as we want to use new value
|
||||
if($sectionKey != "airtime_dir"){
|
||||
if(isset($oldSettings[$section][$sectionKey])) {
|
||||
AirtimeIni200::UpdateIniValue($conf, $sectionKey, $oldSettings[$section][$sectionKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
AirtimeIni200::UpdateIniValue($conf, $section, $oldSettings[$section]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Re: http://dev.sourcefabric.org/browse/CC-2797
|
||||
* We don't want config files to be world-readable so we
|
||||
* set the strictest permissions possible. */
|
||||
public static function changeConfigFilePermissions(){
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_AIRTIME, self::CONF_WWW_DATA_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_API_CLIENT, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_PYPO, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of pypo.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_RECORDER, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of recorder.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_LIQUIDSOAP, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of liquidsoap.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_MEDIAMONITOR, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of media-monitor.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static function ChangeFileOwnerGroupMod($filename, $user){
|
||||
return (chown($filename, $user) &&
|
||||
chgrp($filename, $user) &&
|
||||
chmod($filename, 0640));
|
||||
}
|
||||
|
||||
public static function upgradeConfigFiles(){
|
||||
|
||||
$configFiles = array(AirtimeIni200::CONF_FILE_AIRTIME,
|
||||
AirtimeIni200::CONF_FILE_PYPO,
|
||||
AirtimeIni200::CONF_FILE_RECORDER,
|
||||
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
||||
AirtimeIni200::CONF_FILE_MEDIAMONITOR,
|
||||
AirtimeIni200::CONF_FILE_API_CLIENT);
|
||||
|
||||
// Backup the config files
|
||||
$suffix = date("Ymdhis")."-2.0.0";
|
||||
foreach ($configFiles as $conf) {
|
||||
// do not back up monit cfg
|
||||
if (file_exists($conf)) {
|
||||
echo "Backing up $conf to $conf$suffix.bak".PHP_EOL;
|
||||
//copy($conf, $conf.$suffix.".bak");
|
||||
exec("cp -p $conf $conf$suffix.bak"); //use cli version to preserve file attributes
|
||||
}
|
||||
}
|
||||
|
||||
$default_suffix = "200";
|
||||
AirtimeIni200::CreateIniFiles($default_suffix);
|
||||
AirtimeIni200::MergeConfigFiles($configFiles, $suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates the /etc/airtime configuration folder
|
||||
* and copies the default config files to it.
|
||||
*/
|
||||
public static function CreateIniFiles($suffix)
|
||||
{
|
||||
if (!file_exists("/etc/airtime/")){
|
||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||
echo "Could not create /etc/airtime/ directory. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!copy(__DIR__."/airtime.conf.$suffix", AirtimeIni200::CONF_FILE_AIRTIME)){
|
||||
echo "Could not copy airtime.conf to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/pypo.cfg.$suffix", AirtimeIni200::CONF_FILE_PYPO)){
|
||||
echo "Could not copy pypo.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/recorder.cfg.$suffix", AirtimeIni200::CONF_FILE_RECORDER)){
|
||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
/*if (!copy(__DIR__."/liquidsoap.cfg.$suffix", AirtimeIni200::CONF_FILE_LIQUIDSOAP)){
|
||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}*/
|
||||
if (!copy(__DIR__."/api_client.cfg.$suffix", AirtimeIni200::CONF_FILE_API_CLIENT)){
|
||||
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Airtime200Upgrade::connectToDatabase();
|
||||
AirtimeInstall::SetDefaultTimezone();
|
||||
|
||||
AirtimeInstall::InstallBinaries();
|
||||
AirtimeInstall::CreateSymlinksToUtils();
|
||||
|
||||
/* Airtime 2.0.0 starts interpreting all database times in UTC format. Prior to this, all the times
|
||||
* were stored using the local time zone. Let's convert to UTC time. */
|
||||
ConvertToUtc::setPhpDefaultTimeZoneToSystemTimezone();
|
||||
ConvertToUtc::convert_cc_playlist();
|
||||
ConvertToUtc::convert_cc_schedule();
|
||||
ConvertToUtc::convert_cc_show_days();
|
||||
ConvertToUtc::convert_cc_show_instances();
|
||||
|
||||
// merging/updating config files
|
||||
echo "* Updating configFiles\n";
|
||||
AirtimeIni200::changeConfigFilePermissions();
|
||||
AirtimeIni200::upgradeConfigFiles();
|
||||
|
||||
$values = parse_ini_file(AirtimeIni200::CONF_FILE_AIRTIME, true);
|
||||
$phpDir = $values['general']['airtime_dir'];
|
||||
Airtime200Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||
|
||||
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
||||
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005', '20110629143017', '20110711161043', '20110713161043');
|
||||
foreach($migrations as $migration) {
|
||||
AirtimeInstall::BypassMigrations(__DIR__, $migration);
|
||||
}
|
||||
}
|
||||
|
||||
AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110925171256');
|
||||
|
||||
AirtimeInstall::SetDefaultStreamSetting();
|
||||
|
||||
AirtimeInstall::GetOldLiquidsoapCfgAndUpdate();
|
||||
|
||||
AirtimeUpgrade::RemoveOldMonitFile();
|
||||
|
||||
// restart monit
|
||||
exec("service monit restart");
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
/*
|
||||
* In the future, most Airtime upgrades will involve just mutating the
|
||||
* data that is stored on the system. For example, The only data
|
||||
|
@ -27,14 +20,15 @@ require_once 'UpgradeCommon.php';
|
|||
/* All functions other than start() should be marked as
|
||||
* private.
|
||||
*/
|
||||
class AirtimeDatabaseUpgrade{
|
||||
class AirtimeDatabaseUpgrade {
|
||||
|
||||
public static function start(){
|
||||
public static function start()
|
||||
{
|
||||
self::doDbMigration();
|
||||
|
||||
self::setPhpDefaultTimeZoneToSystemTimezone();
|
||||
self::SetDefaultTimezone();
|
||||
|
||||
|
||||
echo "* Converting database to store all schedule times in UTC. This may take a a while...".PHP_EOL;
|
||||
self::convert_cc_playlist();
|
||||
self::convert_cc_schedule();
|
||||
|
@ -47,13 +41,14 @@ class AirtimeDatabaseUpgrade{
|
|||
|
||||
private static function SetDefaultTimezone()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
|
||||
$defaultTimezone = date_default_timezone_get();
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
try {
|
||||
$result = $con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -72,45 +67,45 @@ class AirtimeDatabaseUpgrade{
|
|||
|
||||
private static function convert_cc_playlist(){
|
||||
echo " * Converting playlists to UTC".PHP_EOL;
|
||||
|
||||
|
||||
$sql = "SELECT * FROM cc_playlist";
|
||||
$result = UpgradeCommon::queryDb($sql);
|
||||
|
||||
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
|
||||
$dt = new DateTime($row['mtime'], new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
|
||||
|
||||
$id = $row['id'];
|
||||
$mtime = $dt->format("Y-m-d H:i:s");
|
||||
|
||||
|
||||
$sql = "UPDATE cc_playlist SET mtime = '$mtime' WHERE id = $id";
|
||||
UpgradeCommon::queryDb($sql);
|
||||
//echo ".";
|
||||
//flush();
|
||||
//usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
echo " * Converting playlists to UTC".PHP_EOL;
|
||||
// cc_playlist has a field that keeps track of when the playlist was last modified.
|
||||
$playlists = CcPlaylistQuery::create()->find();
|
||||
|
||||
|
||||
foreach ($playlists as $pl){
|
||||
$dt = new DateTime($pl->getDbMtime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$pl->setDbMtime($dt);
|
||||
|
||||
|
||||
$pl->save();
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private static function convert_cc_schedule(){
|
||||
|
||||
|
||||
echo " * Converting schedule to UTC".PHP_EOL;
|
||||
|
||||
|
||||
$sql = "SELECT * FROM cc_schedule";
|
||||
$result = UpgradeCommon::queryDb($sql);
|
||||
|
||||
|
@ -120,11 +115,11 @@ class AirtimeDatabaseUpgrade{
|
|||
|
||||
$dtEnds = new DateTime($row['ends'], new DateTimeZone(date_default_timezone_get()));
|
||||
$dtEnds->setTimezone(new DateTimeZone("UTC"));
|
||||
|
||||
|
||||
$id = $row['id'];
|
||||
$starts = $dtStarts->format("Y-m-d H:i:s");
|
||||
$ends = $dtEnds->format("Y-m-d H:i:s");
|
||||
|
||||
|
||||
$sql = "UPDATE cc_schedule SET starts = '$starts', ends = '$ends' WHERE id = $id";
|
||||
UpgradeCommon::queryDb($sql);
|
||||
//echo ".";
|
||||
|
@ -132,62 +127,62 @@ class AirtimeDatabaseUpgrade{
|
|||
//usleep(100000);
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
echo " * Converting schedule to UTC".PHP_EOL;
|
||||
//cc_schedule has start and end fields that need to be changed to UTC.
|
||||
$schedules = CcScheduleQuery::create()->find();
|
||||
|
||||
|
||||
foreach ($schedules as $s){
|
||||
$dt = new DateTime($s->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbStarts($dt);
|
||||
|
||||
|
||||
$dt = new DateTime($s->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbEnds($dt);
|
||||
|
||||
|
||||
$s->save();
|
||||
echo ".";
|
||||
}
|
||||
* */
|
||||
}
|
||||
|
||||
|
||||
private static function convert_cc_show_days(){
|
||||
|
||||
echo " * Converting show days to UTC".PHP_EOL;
|
||||
|
||||
|
||||
$sql = "SELECT * FROM cc_show_days";
|
||||
$result = UpgradeCommon::queryDb($sql);
|
||||
|
||||
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)){
|
||||
|
||||
|
||||
$id = $row['id'];
|
||||
$timezone = date_default_timezone_get();
|
||||
|
||||
|
||||
$sql = "UPDATE cc_show_days SET timezone = '$timezone' WHERE id = $id";
|
||||
UpgradeCommon::queryDb($sql);
|
||||
//echo ".";
|
||||
//flush();
|
||||
//usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC.
|
||||
$showDays = CcShowDaysQuery::create()->find();
|
||||
|
||||
foreach ($showDays as $sd){
|
||||
|
||||
foreach ($showDays as $sd){
|
||||
$sd->setDbTimezone(date_default_timezone_get())->save();
|
||||
|
||||
|
||||
echo ".";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
private static function convert_cc_show_instances(){
|
||||
echo " * Converting show instances to UTC".PHP_EOL;
|
||||
|
||||
|
||||
// convert_cc_show_instances has starts and ends fields that need to be changed to UTC.
|
||||
|
||||
|
||||
$sql = "SELECT * FROM cc_show_instances";
|
||||
$result = UpgradeCommon::queryDb($sql);
|
||||
|
||||
|
@ -197,32 +192,32 @@ class AirtimeDatabaseUpgrade{
|
|||
|
||||
$dtEnds = new DateTime($row['ends'], new DateTimeZone(date_default_timezone_get()));
|
||||
$dtEnds->setTimezone(new DateTimeZone("UTC"));
|
||||
|
||||
|
||||
$id = $row['id'];
|
||||
$starts = $dtStarts->format("Y-m-d H:i:s");
|
||||
$ends = $dtEnds->format("Y-m-d H:i:s");
|
||||
|
||||
|
||||
$sql = "UPDATE cc_show_instances SET starts = '$starts', ends = '$ends' WHERE id = $id";
|
||||
UpgradeCommon::queryDb($sql);
|
||||
//echo ".";
|
||||
//flush();
|
||||
//usleep(100000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
$showInstances = CcShowInstancesQuery::create()->find();
|
||||
|
||||
|
||||
foreach ($showInstances as $si){
|
||||
$dt = new DateTime($si->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbStarts($dt);
|
||||
|
||||
|
||||
$dt = new DateTime($si->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbEnds($dt);
|
||||
|
||||
|
||||
$si->save();
|
||||
|
||||
|
||||
echo ".";
|
||||
}
|
||||
* */
|
||||
|
@ -241,19 +236,19 @@ class AirtimeDatabaseUpgrade{
|
|||
|
||||
private static function SetDefaultStreamSetting()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$con = Propel::getConnection();
|
||||
|
||||
echo "* Setting up default stream setting".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '320');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('plan_level', 'disabled');
|
||||
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device_type', 'ALSA', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
|
||||
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_enable', 'true', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string');
|
||||
|
@ -266,7 +261,7 @@ class AirtimeDatabaseUpgrade{
|
|||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_url', 'http://airtime.sourcefabric.org', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string');
|
||||
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_enable', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string');
|
||||
|
@ -279,7 +274,7 @@ class AirtimeDatabaseUpgrade{
|
|||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string');
|
||||
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_enable', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string');
|
||||
|
@ -292,21 +287,24 @@ class AirtimeDatabaseUpgrade{
|
|||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_genre', '', 'string');";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
try {
|
||||
$con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function GetOldLiquidsoapCfgAndUpdate(){
|
||||
global $CC_DBC;
|
||||
private static function GetOldLiquidsoapCfgAndUpdate()
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
|
||||
echo "* Retrieving old liquidsoap configuration".PHP_EOL;
|
||||
$map = array();
|
||||
$fh = fopen("/etc/airtime/liquidsoap.cfg", 'r');
|
||||
$newConfigMap = array();
|
||||
|
||||
while(!feof($fh)){
|
||||
|
||||
while (!feof($fh)) {
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
|
@ -318,7 +316,7 @@ class AirtimeDatabaseUpgrade{
|
|||
$newConfigMap['output_sound_device'] = $map['output_sound_device'];
|
||||
$newConfigMap['icecast_vorbis_metadata'] = $map['output_icecast_vorbis_metadata'];
|
||||
$newConfigMap['log_file'] = $map['log_file'];
|
||||
|
||||
|
||||
$count = 1;
|
||||
if( $map['output_icecast_vorbis'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
|
@ -366,8 +364,9 @@ class AirtimeDatabaseUpgrade{
|
|||
}
|
||||
$sql .= "UPDATE cc_stream_setting SET value='$val' WHERE keyname='$key';";
|
||||
}
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
try {
|
||||
$con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
require_once('DB.php');
|
||||
|
||||
/* These are helper functions that are common to each upgrade such as
|
||||
* creating connections to a database, backing up config files etc.
|
||||
*/
|
||||
|
@ -17,42 +15,41 @@ class UpgradeCommon{
|
|||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
const CONF_BACKUP_SUFFIX = "201";
|
||||
const VERSION_NUMBER = "2.0.1";
|
||||
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
{
|
||||
$sql = "SELECT valstr from cc_pref WHERE keystr = 'timezone'";
|
||||
|
||||
$result = self::queryDb($sql);
|
||||
$timezone = $result['valstr'];
|
||||
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
|
||||
public static function connectToDatabase($p_exitOnError = true)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -66,7 +63,7 @@ class UpgradeCommon{
|
|||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
echo "Upgrading database, may take several minutes, please wait".PHP_EOL;
|
||||
|
||||
|
||||
$appDir = self::GetAirtimeSrcDir();
|
||||
$command = "php --php-ini $dir/../../airtime-php.ini ".
|
||||
"$appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
|
@ -192,9 +189,9 @@ class UpgradeCommon{
|
|||
private static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
|
@ -243,16 +240,17 @@ class UpgradeCommon{
|
|||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function queryDb($p_sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->getRow($p_sql, $fetchmode=DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "Error executing $sql. Exiting.";
|
||||
public static function queryDb($p_sql){
|
||||
$con = Propel::getConnection();
|
||||
|
||||
try {
|
||||
$result = $con->exec($p_sql);
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing $p_sql. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,586 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/models' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/configs' . PATH_SEPARATOR . get_include_path());
|
||||
require_once 'conf.php';
|
||||
require_once 'DB.php';
|
||||
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(__DIR__."/../../../airtime_mvc/application/configs/airtime-conf.php");
|
||||
|
||||
class AirtimeInstall{
|
||||
const CONF_DIR_BINARIES = "/usr/lib/airtime";
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$defaultTimezone = date_default_timezone_get();
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function GetUtilsSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../utils";
|
||||
}
|
||||
|
||||
public static function InstallBinaries()
|
||||
{
|
||||
echo "* Installing binaries to ".AirtimeInstall::CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec("mkdir -p ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
exec("cp -R ".AirtimeInstall::GetUtilsSrcDir()." ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
}
|
||||
|
||||
public static function CreateSymlinksToUtils()
|
||||
{
|
||||
echo "* Installing airtime-log".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log";
|
||||
copy(AirtimeInstall::GetUtilsSrcDir()."/airtime-log.php", AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log.php");
|
||||
|
||||
exec("ln -s $dir /usr/bin/airtime-log");
|
||||
}
|
||||
|
||||
public static function SetDefaultStreamSetting()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
echo "* Setting up default stream setting".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '128');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('plan_level', 'disabled');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_bitrate', '128', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_host', '127.0.0.1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_port', '8000', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_pass', 'hackme', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_mount', 'airtime_128', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_url', 'http://airtime.sourcefabric.org', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_genre', '', 'string');";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function BypassMigrations($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction --add migrations:version $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction migrations:migrate $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function GetAirtimeSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../airtime_mvc";
|
||||
}
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function GetOldLiquidsoapCfgAndUpdate(){
|
||||
global $CC_DBC;
|
||||
echo "* Retrieving old liquidsoap configuration".PHP_EOL;
|
||||
$map = array();
|
||||
$fh = fopen("/etc/airtime/liquidsoap.cfg", 'r');
|
||||
$newConfigMap = array();
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$map[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
$newConfigMap['output_sound_device'] = $map['output_sound_device'];
|
||||
$newConfigMap['icecast_vorbis_metadata'] = $map['output_icecast_vorbis_metadata'];
|
||||
$newConfigMap['log_file'] = $map['log_file'];
|
||||
|
||||
$count = 1;
|
||||
if( $map['output_icecast_vorbis'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_vorbis'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "ogg";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_icecast_mp3'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_mp3'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_shoutcast'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'shoutcast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['shoutcast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['shoutcast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['shoutcast_pass'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['shoutcast_url'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['shoutcast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
foreach( $newConfigMap as $key=>$val){
|
||||
if(substr($val, 0, 1) == '"' && substr($val, strlen($val)-1,1)){
|
||||
$val = ltrim($val, '"');
|
||||
$val = rtrim($val, '"');
|
||||
}
|
||||
$sql .= "UPDATE cc_stream_setting SET value='$val' WHERE keyname='$key';";
|
||||
}
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Airtime200Upgrade{
|
||||
|
||||
public static function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
}
|
||||
|
||||
public static function InstallAirtimePhpServerCode($phpDir)
|
||||
{
|
||||
|
||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||
|
||||
// delete old files
|
||||
exec("rm -rf ".$phpDir);
|
||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||
exec("mkdir -p ".$phpDir);
|
||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||
}
|
||||
|
||||
public static function RemoveOldMonitFile(){
|
||||
unlink("/etc/monit/conf.d/airtime-monit.cfg");
|
||||
}
|
||||
}
|
||||
|
||||
class ConvertToUtc{
|
||||
|
||||
public static function setPhpDefaultTimeZoneToSystemTimezone(){
|
||||
//we can get the default system timezone on debian/ubuntu by reading "/etc/timezone"
|
||||
$filename = "/etc/timezone";
|
||||
$handle = fopen($filename, "r");
|
||||
$contents = trim(fread($handle, filesize($filename)));
|
||||
echo "System timezone detected as: $contents".PHP_EOL;
|
||||
fclose($handle);
|
||||
|
||||
date_default_timezone_set($contents);
|
||||
}
|
||||
|
||||
public static function convert_cc_playlist(){
|
||||
/* cc_playlist has a field that keeps track of when the playlist was last modified. */
|
||||
$playlists = CcPlaylistQuery::create()->find();
|
||||
|
||||
foreach ($playlists as $pl){
|
||||
$dt = new DateTime($pl->getDbMtime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$pl->setDbMtime($dt);
|
||||
|
||||
$pl->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_schedule(){
|
||||
/* cc_schedule has start and end fields that need to be changed to UTC. */
|
||||
$schedules = CcScheduleQuery::create()->find();
|
||||
|
||||
foreach ($schedules as $s){
|
||||
$dt = new DateTime($s->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($s->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbEnds($dt);
|
||||
|
||||
$s->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_days(){
|
||||
/* cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC. */
|
||||
$showDays = CcShowDaysQuery::create()->find();
|
||||
|
||||
foreach ($showDays as $sd){
|
||||
$dt = new DateTime($sd->getDbFirstShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbFirstShow($dt->format("Y-m-d"));
|
||||
$sd->setDbStartTime($dt->format("H:i:s"));
|
||||
|
||||
$dt = new DateTime($sd->getDbLastShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbLastShow($dt->format("Y-m-d"));
|
||||
|
||||
$sd->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_instances(){
|
||||
/* convert_cc_show_instances has starts and ends fields that need to be changed to UTC. */
|
||||
$showInstances = CcShowInstancesQuery::create()->find();
|
||||
|
||||
foreach ($showInstances as $si){
|
||||
$dt = new DateTime($si->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($si->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbEnds($dt);
|
||||
|
||||
$si->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeIni200{
|
||||
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
const CONF_FILE_PYPO = "/etc/airtime/pypo.cfg";
|
||||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
|
||||
const CONF_FILE_MEDIAMONITOR = "/etc/airtime/media-monitor.cfg";
|
||||
const CONF_FILE_API_CLIENT = "/etc/airtime/api_client.cfg";
|
||||
|
||||
const CONF_PYPO_GRP = "pypo";
|
||||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
|
||||
/**
|
||||
* This function updates an INI style config file.
|
||||
*
|
||||
* A property and the value the property should be changed to are
|
||||
* supplied. If the property is not found, then no changes are made.
|
||||
*
|
||||
* @param string $p_filename
|
||||
* The path the to the file.
|
||||
* @param string $p_property
|
||||
* The property to look for in order to change its value.
|
||||
* @param string $p_value
|
||||
* The value the property should be changed to.
|
||||
*
|
||||
*/
|
||||
public static function UpdateIniValue($p_filename, $p_property, $p_value)
|
||||
{
|
||||
$lines = file($p_filename);
|
||||
$n=count($lines);
|
||||
foreach ($lines as &$line) {
|
||||
if ($line[0] != "#"){
|
||||
$key_value = explode("=", $line);
|
||||
$key = trim($key_value[0]);
|
||||
|
||||
if ($key == $p_property){
|
||||
$line = "$p_property = $p_value".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fp=fopen($p_filename, 'w');
|
||||
for($i=0; $i<$n; $i++){
|
||||
fwrite($fp, $lines[$i]);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$values[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function MergeConfigFiles($configFiles, $suffix) {
|
||||
foreach ($configFiles as $conf) {
|
||||
// we want to use new liquidsoap.cfg so don't merge
|
||||
// also for monit
|
||||
if( $conf == AirtimeIni200::CONF_FILE_LIQUIDSOAP){
|
||||
continue;
|
||||
}
|
||||
if (file_exists("$conf$suffix.bak")) {
|
||||
|
||||
if($conf === AirtimeIni200::CONF_FILE_AIRTIME) {
|
||||
// Parse with sections
|
||||
$newSettings = parse_ini_file($conf, true);
|
||||
$oldSettings = parse_ini_file("$conf$suffix.bak", true);
|
||||
}
|
||||
else {
|
||||
$newSettings = AirtimeIni200::ReadPythonConfig($conf);
|
||||
$oldSettings = AirtimeIni200::ReadPythonConfig("$conf$suffix.bak");
|
||||
}
|
||||
|
||||
$settings = array_keys($newSettings);
|
||||
|
||||
foreach($settings as $section) {
|
||||
if(isset($oldSettings[$section])) {
|
||||
if(is_array($oldSettings[$section])) {
|
||||
$sectionKeys = array_keys($newSettings[$section]);
|
||||
foreach($sectionKeys as $sectionKey) {
|
||||
// skip airtim_dir as we want to use new value
|
||||
if($sectionKey != "airtime_dir"){
|
||||
if(isset($oldSettings[$section][$sectionKey])) {
|
||||
AirtimeIni200::UpdateIniValue($conf, $sectionKey, $oldSettings[$section][$sectionKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
AirtimeIni200::UpdateIniValue($conf, $section, $oldSettings[$section]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Re: http://dev.sourcefabric.org/browse/CC-2797
|
||||
* We don't want config files to be world-readable so we
|
||||
* set the strictest permissions possible. */
|
||||
public static function changeConfigFilePermissions(){
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_AIRTIME, self::CONF_WWW_DATA_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_API_CLIENT, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_PYPO, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of pypo.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_RECORDER, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of recorder.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_LIQUIDSOAP, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of liquidsoap.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_MEDIAMONITOR, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of media-monitor.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static function ChangeFileOwnerGroupMod($filename, $user){
|
||||
return (chown($filename, $user) &&
|
||||
chgrp($filename, $user) &&
|
||||
chmod($filename, 0640));
|
||||
}
|
||||
|
||||
public static function upgradeConfigFiles(){
|
||||
|
||||
$configFiles = array(AirtimeIni200::CONF_FILE_AIRTIME,
|
||||
AirtimeIni200::CONF_FILE_PYPO,
|
||||
AirtimeIni200::CONF_FILE_RECORDER,
|
||||
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
||||
AirtimeIni200::CONF_FILE_MEDIAMONITOR,
|
||||
AirtimeIni200::CONF_FILE_API_CLIENT);
|
||||
|
||||
// Backup the config files
|
||||
$suffix = date("Ymdhis")."-2.0.0";
|
||||
foreach ($configFiles as $conf) {
|
||||
// do not back up monit cfg
|
||||
if (file_exists($conf)) {
|
||||
echo "Backing up $conf to $conf$suffix.bak".PHP_EOL;
|
||||
//copy($conf, $conf.$suffix.".bak");
|
||||
exec("cp -p $conf $conf$suffix.bak"); //use cli version to preserve file attributes
|
||||
}
|
||||
}
|
||||
|
||||
$default_suffix = "200";
|
||||
AirtimeIni200::CreateIniFiles($default_suffix);
|
||||
AirtimeIni200::MergeConfigFiles($configFiles, $suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates the /etc/airtime configuration folder
|
||||
* and copies the default config files to it.
|
||||
*/
|
||||
public static function CreateIniFiles($suffix)
|
||||
{
|
||||
if (!file_exists("/etc/airtime/")){
|
||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||
echo "Could not create /etc/airtime/ directory. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!copy(__DIR__."/airtime.conf.$suffix", AirtimeIni200::CONF_FILE_AIRTIME)){
|
||||
echo "Could not copy airtime.conf to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/pypo.cfg.$suffix", AirtimeIni200::CONF_FILE_PYPO)){
|
||||
echo "Could not copy pypo.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/recorder.cfg.$suffix", AirtimeIni200::CONF_FILE_RECORDER)){
|
||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
/*if (!copy(__DIR__."/liquidsoap.cfg.$suffix", AirtimeIni200::CONF_FILE_LIQUIDSOAP)){
|
||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}*/
|
||||
if (!copy(__DIR__."/api_client.cfg.$suffix", AirtimeIni200::CONF_FILE_API_CLIENT)){
|
||||
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Airtime200Upgrade::connectToDatabase();
|
||||
AirtimeInstall::SetDefaultTimezone();
|
||||
|
||||
AirtimeInstall::InstallBinaries();
|
||||
AirtimeInstall::CreateSymlinksToUtils();
|
||||
|
||||
/* Airtime 2.0.0 starts interpreting all database times in UTC format. Prior to this, all the times
|
||||
* were stored using the local time zone. Let's convert to UTC time. */
|
||||
ConvertToUtc::setPhpDefaultTimeZoneToSystemTimezone();
|
||||
ConvertToUtc::convert_cc_playlist();
|
||||
ConvertToUtc::convert_cc_schedule();
|
||||
ConvertToUtc::convert_cc_show_days();
|
||||
ConvertToUtc::convert_cc_show_instances();
|
||||
|
||||
// merging/updating config files
|
||||
echo "* Updating configFiles\n";
|
||||
AirtimeIni200::changeConfigFilePermissions();
|
||||
AirtimeIni200::upgradeConfigFiles();
|
||||
|
||||
$values = parse_ini_file(AirtimeIni200::CONF_FILE_AIRTIME, true);
|
||||
$phpDir = $values['general']['airtime_dir'];
|
||||
Airtime200Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||
|
||||
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
||||
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005', '20110629143017', '20110711161043', '20110713161043');
|
||||
foreach($migrations as $migration) {
|
||||
AirtimeInstall::BypassMigrations(__DIR__, $migration);
|
||||
}
|
||||
}
|
||||
|
||||
AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110925171256');
|
||||
|
||||
AirtimeInstall::SetDefaultStreamSetting();
|
||||
|
||||
AirtimeInstall::GetOldLiquidsoapCfgAndUpdate();
|
||||
|
||||
AirtimeUpgrade::RemoveOldMonitFile();
|
||||
|
||||
// restart monit
|
||||
exec("service monit restart");
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
require_once('DB.php');
|
||||
|
||||
/* These are helper functions that are common to each upgrade such as
|
||||
* creating connections to a database, backing up config files etc.
|
||||
*/
|
||||
|
@ -16,42 +14,41 @@ class UpgradeCommon{
|
|||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
const CONF_BACKUP_SUFFIX = "202";
|
||||
const VERSION_NUMBER = "2.0.2";
|
||||
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
{
|
||||
$sql = "SELECT valstr from cc_pref WHERE keystr = 'timezone'";
|
||||
|
||||
$result = self::queryDb($sql);
|
||||
$timezone = $result['valstr'];
|
||||
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
|
||||
public static function connectToDatabase($p_exitOnError = true)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -65,7 +62,7 @@ class UpgradeCommon{
|
|||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
echo "Upgrading database, may take several minutes, please wait".PHP_EOL;
|
||||
|
||||
|
||||
$appDir = self::GetAirtimeSrcDir();
|
||||
$command = "php --php-ini $dir/../../airtime-php.ini ".
|
||||
"$appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
|
@ -186,9 +183,9 @@ class UpgradeCommon{
|
|||
private static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
|
@ -237,16 +234,17 @@ class UpgradeCommon{
|
|||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function queryDb($p_sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->getRow($p_sql, $fetchmode=DB_FETCHMODE_ASSOC);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "Error executing $sql. Exiting.";
|
||||
public static function queryDb($p_sql){
|
||||
$con = Propel::getConnection();
|
||||
|
||||
try {
|
||||
$result = $con->exec($p_sql);
|
||||
} catch (Exception $e) {
|
||||
echo "Error executing $p_sql. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,586 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/models' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(__DIR__.'/../../../airtime_mvc/application/configs' . PATH_SEPARATOR . get_include_path());
|
||||
require_once 'conf.php';
|
||||
require_once 'DB.php';
|
||||
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init(__DIR__."/../../../airtime_mvc/application/configs/airtime-conf.php");
|
||||
|
||||
class AirtimeInstall{
|
||||
const CONF_DIR_BINARIES = "/usr/lib/airtime";
|
||||
|
||||
public static function SetDefaultTimezone()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$defaultTimezone = date_default_timezone_get();
|
||||
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function GetUtilsSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../utils";
|
||||
}
|
||||
|
||||
public static function InstallBinaries()
|
||||
{
|
||||
echo "* Installing binaries to ".AirtimeInstall::CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec("mkdir -p ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
exec("cp -R ".AirtimeInstall::GetUtilsSrcDir()." ".AirtimeInstall::CONF_DIR_BINARIES);
|
||||
}
|
||||
|
||||
public static function CreateSymlinksToUtils()
|
||||
{
|
||||
echo "* Installing airtime-log".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log";
|
||||
copy(AirtimeInstall::GetUtilsSrcDir()."/airtime-log.php", AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-log.php");
|
||||
|
||||
exec("ln -s $dir /usr/bin/airtime-log");
|
||||
}
|
||||
|
||||
public static function SetDefaultStreamSetting()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
echo "* Setting up default stream setting".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_pref(keystr, valstr) VALUES('stream_type', 'ogg, mp3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('stream_bitrate', '24, 32, 48, 64, 96, 128, 160, 192, 224, 256, 320');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('num_of_streams', '3');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('max_bitrate', '128');
|
||||
INSERT INTO cc_pref(keystr, valstr) VALUES('plan_level', 'disabled');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('output_sound_device', 'false', 'boolean');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('icecast_vorbis_metadata', 'false', 'boolean');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_output', 'icecast', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_type', 'ogg', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_bitrate', '128', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_host', '127.0.0.1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_port', '8000', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_pass', 'hackme', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_mount', 'airtime_128', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_url', 'http://airtime.sourcefabric.org', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_description', 'Airtime Radio! Stream #1', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s1_genre', 'genre', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s2_genre', '', 'string');
|
||||
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_output', 'disabled', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_type', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_bitrate', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_host', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_port', '', 'integer');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_user', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_pass', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_mount', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_url', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_description', '', 'string');
|
||||
INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_genre', '', 'string');";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function BypassMigrations($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction --add migrations:version $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function MigrateTablesToVersion($dir, $version)
|
||||
{
|
||||
$appDir = AirtimeInstall::GetAirtimeSrcDir();
|
||||
$command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
|
||||
"--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
|
||||
"--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
|
||||
"--no-interaction migrations:migrate $version";
|
||||
system($command);
|
||||
}
|
||||
|
||||
public static function GetAirtimeSrcDir()
|
||||
{
|
||||
return __DIR__."/../../../airtime_mvc";
|
||||
}
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static function GetOldLiquidsoapCfgAndUpdate(){
|
||||
global $CC_DBC;
|
||||
echo "* Retrieving old liquidsoap configuration".PHP_EOL;
|
||||
$map = array();
|
||||
$fh = fopen("/etc/airtime/liquidsoap.cfg", 'r');
|
||||
$newConfigMap = array();
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$map[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
$newConfigMap['output_sound_device'] = $map['output_sound_device'];
|
||||
$newConfigMap['icecast_vorbis_metadata'] = $map['output_icecast_vorbis_metadata'];
|
||||
$newConfigMap['log_file'] = $map['log_file'];
|
||||
|
||||
$count = 1;
|
||||
if( $map['output_icecast_vorbis'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_vorbis'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "ogg";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_icecast_mp3'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'icecast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['icecast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['icecast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['icecast_pass'];
|
||||
$newConfigMap['s'.$count.'_mount'] = $map['mount_point_mp3'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['icecast_url'];
|
||||
$newConfigMap['s'.$count.'_description'] = $map['icecast_description'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['icecast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
if($map['output_shoutcast'] == 'true'){
|
||||
$newConfigMap['s'.$count.'_output'] = 'shoutcast';
|
||||
$newConfigMap['s'.$count.'_host'] = $map['shoutcast_host'];
|
||||
$newConfigMap['s'.$count.'_port'] = $map['shoutcast_port'];
|
||||
$newConfigMap['s'.$count.'_pass'] = $map['shoutcast_pass'];
|
||||
$newConfigMap['s'.$count.'_url'] = $map['shoutcast_url'];
|
||||
$newConfigMap['s'.$count.'_genre'] = $map['shoutcast_genre'];
|
||||
$newConfigMap['s'.$count.'_type'] = "mp3";
|
||||
$newConfigMap['s'.$count.'_bitrate'] = "128";
|
||||
$count++;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
foreach( $newConfigMap as $key=>$val){
|
||||
if(substr($val, 0, 1) == '"' && substr($val, strlen($val)-1,1)){
|
||||
$val = ltrim($val, '"');
|
||||
$val = rtrim($val, '"');
|
||||
}
|
||||
$sql .= "UPDATE cc_stream_setting SET value='$val' WHERE keyname='$key';";
|
||||
}
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Airtime200Upgrade{
|
||||
|
||||
public static function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// Database config
|
||||
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
|
||||
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
|
||||
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
|
||||
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
|
||||
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
|
||||
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
}
|
||||
|
||||
public static function InstallAirtimePhpServerCode($phpDir)
|
||||
{
|
||||
|
||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||
|
||||
// delete old files
|
||||
exec("rm -rf ".$phpDir);
|
||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||
exec("mkdir -p ".$phpDir);
|
||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||
}
|
||||
|
||||
public static function RemoveOldMonitFile(){
|
||||
unlink("/etc/monit/conf.d/airtime-monit.cfg");
|
||||
}
|
||||
}
|
||||
|
||||
class ConvertToUtc{
|
||||
|
||||
public static function setPhpDefaultTimeZoneToSystemTimezone(){
|
||||
//we can get the default system timezone on debian/ubuntu by reading "/etc/timezone"
|
||||
$filename = "/etc/timezone";
|
||||
$handle = fopen($filename, "r");
|
||||
$contents = trim(fread($handle, filesize($filename)));
|
||||
echo "System timezone detected as: $contents".PHP_EOL;
|
||||
fclose($handle);
|
||||
|
||||
date_default_timezone_set($contents);
|
||||
}
|
||||
|
||||
public static function convert_cc_playlist(){
|
||||
/* cc_playlist has a field that keeps track of when the playlist was last modified. */
|
||||
$playlists = CcPlaylistQuery::create()->find();
|
||||
|
||||
foreach ($playlists as $pl){
|
||||
$dt = new DateTime($pl->getDbMtime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$pl->setDbMtime($dt);
|
||||
|
||||
$pl->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_schedule(){
|
||||
/* cc_schedule has start and end fields that need to be changed to UTC. */
|
||||
$schedules = CcScheduleQuery::create()->find();
|
||||
|
||||
foreach ($schedules as $s){
|
||||
$dt = new DateTime($s->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($s->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$s->setDbEnds($dt);
|
||||
|
||||
$s->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_days(){
|
||||
/* cc_show_days has first_show, last_show and start_time fields that need to be changed to UTC. */
|
||||
$showDays = CcShowDaysQuery::create()->find();
|
||||
|
||||
foreach ($showDays as $sd){
|
||||
$dt = new DateTime($sd->getDbFirstShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbFirstShow($dt->format("Y-m-d"));
|
||||
$sd->setDbStartTime($dt->format("H:i:s"));
|
||||
|
||||
$dt = new DateTime($sd->getDbLastShow()." ".$sd->getDbStartTime(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$sd->setDbLastShow($dt->format("Y-m-d"));
|
||||
|
||||
$sd->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function convert_cc_show_instances(){
|
||||
/* convert_cc_show_instances has starts and ends fields that need to be changed to UTC. */
|
||||
$showInstances = CcShowInstancesQuery::create()->find();
|
||||
|
||||
foreach ($showInstances as $si){
|
||||
$dt = new DateTime($si->getDbStarts(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbStarts($dt);
|
||||
|
||||
$dt = new DateTime($si->getDbEnds(), new DateTimeZone(date_default_timezone_get()));
|
||||
$dt->setTimezone(new DateTimeZone("UTC"));
|
||||
$si->setDbEnds($dt);
|
||||
|
||||
$si->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AirtimeIni200{
|
||||
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
const CONF_FILE_PYPO = "/etc/airtime/pypo.cfg";
|
||||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
|
||||
const CONF_FILE_MEDIAMONITOR = "/etc/airtime/media-monitor.cfg";
|
||||
const CONF_FILE_API_CLIENT = "/etc/airtime/api_client.cfg";
|
||||
|
||||
const CONF_PYPO_GRP = "pypo";
|
||||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
|
||||
/**
|
||||
* This function updates an INI style config file.
|
||||
*
|
||||
* A property and the value the property should be changed to are
|
||||
* supplied. If the property is not found, then no changes are made.
|
||||
*
|
||||
* @param string $p_filename
|
||||
* The path the to the file.
|
||||
* @param string $p_property
|
||||
* The property to look for in order to change its value.
|
||||
* @param string $p_value
|
||||
* The value the property should be changed to.
|
||||
*
|
||||
*/
|
||||
public static function UpdateIniValue($p_filename, $p_property, $p_value)
|
||||
{
|
||||
$lines = file($p_filename);
|
||||
$n=count($lines);
|
||||
foreach ($lines as &$line) {
|
||||
if ($line[0] != "#"){
|
||||
$key_value = explode("=", $line);
|
||||
$key = trim($key_value[0]);
|
||||
|
||||
if ($key == $p_property){
|
||||
$line = "$p_property = $p_value".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fp=fopen($p_filename, 'w');
|
||||
for($i=0; $i<$n; $i++){
|
||||
fwrite($fp, $lines[$i]);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
continue;
|
||||
}else{
|
||||
$info = explode('=', $line, 2);
|
||||
$values[trim($info[0])] = trim($info[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function MergeConfigFiles($configFiles, $suffix) {
|
||||
foreach ($configFiles as $conf) {
|
||||
// we want to use new liquidsoap.cfg so don't merge
|
||||
// also for monit
|
||||
if( $conf == AirtimeIni200::CONF_FILE_LIQUIDSOAP){
|
||||
continue;
|
||||
}
|
||||
if (file_exists("$conf$suffix.bak")) {
|
||||
|
||||
if($conf === AirtimeIni200::CONF_FILE_AIRTIME) {
|
||||
// Parse with sections
|
||||
$newSettings = parse_ini_file($conf, true);
|
||||
$oldSettings = parse_ini_file("$conf$suffix.bak", true);
|
||||
}
|
||||
else {
|
||||
$newSettings = AirtimeIni200::ReadPythonConfig($conf);
|
||||
$oldSettings = AirtimeIni200::ReadPythonConfig("$conf$suffix.bak");
|
||||
}
|
||||
|
||||
$settings = array_keys($newSettings);
|
||||
|
||||
foreach($settings as $section) {
|
||||
if(isset($oldSettings[$section])) {
|
||||
if(is_array($oldSettings[$section])) {
|
||||
$sectionKeys = array_keys($newSettings[$section]);
|
||||
foreach($sectionKeys as $sectionKey) {
|
||||
// skip airtim_dir as we want to use new value
|
||||
if($sectionKey != "airtime_dir"){
|
||||
if(isset($oldSettings[$section][$sectionKey])) {
|
||||
AirtimeIni200::UpdateIniValue($conf, $sectionKey, $oldSettings[$section][$sectionKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
AirtimeIni200::UpdateIniValue($conf, $section, $oldSettings[$section]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Re: http://dev.sourcefabric.org/browse/CC-2797
|
||||
* We don't want config files to be world-readable so we
|
||||
* set the strictest permissions possible. */
|
||||
public static function changeConfigFilePermissions(){
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_AIRTIME, self::CONF_WWW_DATA_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_API_CLIENT, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of api_client.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_PYPO, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of pypo.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_RECORDER, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of recorder.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_LIQUIDSOAP, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of liquidsoap.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!self::ChangeFileOwnerGroupMod(AirtimeIni200::CONF_FILE_MEDIAMONITOR, self::CONF_PYPO_GRP)){
|
||||
echo "Could not set ownership of media-monitor.cfg to 'pypo'. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static function ChangeFileOwnerGroupMod($filename, $user){
|
||||
return (chown($filename, $user) &&
|
||||
chgrp($filename, $user) &&
|
||||
chmod($filename, 0640));
|
||||
}
|
||||
|
||||
public static function upgradeConfigFiles(){
|
||||
|
||||
$configFiles = array(AirtimeIni200::CONF_FILE_AIRTIME,
|
||||
AirtimeIni200::CONF_FILE_PYPO,
|
||||
AirtimeIni200::CONF_FILE_RECORDER,
|
||||
AirtimeIni200::CONF_FILE_LIQUIDSOAP,
|
||||
AirtimeIni200::CONF_FILE_MEDIAMONITOR,
|
||||
AirtimeIni200::CONF_FILE_API_CLIENT);
|
||||
|
||||
// Backup the config files
|
||||
$suffix = date("Ymdhis")."-2.0.0";
|
||||
foreach ($configFiles as $conf) {
|
||||
// do not back up monit cfg
|
||||
if (file_exists($conf)) {
|
||||
echo "Backing up $conf to $conf$suffix.bak".PHP_EOL;
|
||||
//copy($conf, $conf.$suffix.".bak");
|
||||
exec("cp -p $conf $conf$suffix.bak"); //use cli version to preserve file attributes
|
||||
}
|
||||
}
|
||||
|
||||
$default_suffix = "200";
|
||||
AirtimeIni200::CreateIniFiles($default_suffix);
|
||||
AirtimeIni200::MergeConfigFiles($configFiles, $suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates the /etc/airtime configuration folder
|
||||
* and copies the default config files to it.
|
||||
*/
|
||||
public static function CreateIniFiles($suffix)
|
||||
{
|
||||
if (!file_exists("/etc/airtime/")){
|
||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||
echo "Could not create /etc/airtime/ directory. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!copy(__DIR__."/airtime.conf.$suffix", AirtimeIni200::CONF_FILE_AIRTIME)){
|
||||
echo "Could not copy airtime.conf to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/pypo.cfg.$suffix", AirtimeIni200::CONF_FILE_PYPO)){
|
||||
echo "Could not copy pypo.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/recorder.cfg.$suffix", AirtimeIni200::CONF_FILE_RECORDER)){
|
||||
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
/*if (!copy(__DIR__."/liquidsoap.cfg.$suffix", AirtimeIni200::CONF_FILE_LIQUIDSOAP)){
|
||||
echo "Could not copy liquidsoap.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}*/
|
||||
if (!copy(__DIR__."/api_client.cfg.$suffix", AirtimeIni200::CONF_FILE_API_CLIENT)){
|
||||
echo "Could not copy airtime-monit.cfg to /etc/monit/conf.d/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Airtime200Upgrade::connectToDatabase();
|
||||
AirtimeInstall::SetDefaultTimezone();
|
||||
|
||||
AirtimeInstall::InstallBinaries();
|
||||
AirtimeInstall::CreateSymlinksToUtils();
|
||||
|
||||
/* Airtime 2.0.0 starts interpreting all database times in UTC format. Prior to this, all the times
|
||||
* were stored using the local time zone. Let's convert to UTC time. */
|
||||
ConvertToUtc::setPhpDefaultTimeZoneToSystemTimezone();
|
||||
ConvertToUtc::convert_cc_playlist();
|
||||
ConvertToUtc::convert_cc_schedule();
|
||||
ConvertToUtc::convert_cc_show_days();
|
||||
ConvertToUtc::convert_cc_show_instances();
|
||||
|
||||
// merging/updating config files
|
||||
echo "* Updating configFiles\n";
|
||||
AirtimeIni200::changeConfigFilePermissions();
|
||||
AirtimeIni200::upgradeConfigFiles();
|
||||
|
||||
$values = parse_ini_file(AirtimeIni200::CONF_FILE_AIRTIME, true);
|
||||
$phpDir = $values['general']['airtime_dir'];
|
||||
Airtime200Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||
|
||||
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
||||
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005', '20110629143017', '20110711161043', '20110713161043');
|
||||
foreach($migrations as $migration) {
|
||||
AirtimeInstall::BypassMigrations(__DIR__, $migration);
|
||||
}
|
||||
}
|
||||
|
||||
AirtimeInstall::MigrateTablesToVersion(__DIR__, '20110925171256');
|
||||
|
||||
AirtimeInstall::SetDefaultStreamSetting();
|
||||
|
||||
AirtimeInstall::GetOldLiquidsoapCfgAndUpdate();
|
||||
|
||||
AirtimeUpgrade::RemoveOldMonitFile();
|
||||
|
||||
// restart monit
|
||||
exec("service monit restart");
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
require_once('DB.php');
|
||||
|
||||
/* These are helper functions that are common to each upgrade such as
|
||||
/*
|
||||
* These are helper functions that are common to each upgrade such as
|
||||
* creating connections to a database, backing up config files etc.
|
||||
*/
|
||||
class UpgradeCommon{
|
||||
class UpgradeCommon {
|
||||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
const CONF_FILE_PYPO = "/etc/airtime/pypo.cfg";
|
||||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
|
@ -17,35 +16,41 @@ class UpgradeCommon{
|
|||
const CONF_WWW_DATA_GRP = "www-data";
|
||||
const CONF_BACKUP_SUFFIX = "200";
|
||||
const VERSION_NUMBER = "2.0.0";
|
||||
|
||||
|
||||
/**
|
||||
* Check if the connection to the database is working.
|
||||
* Return true if it is working, false if not.
|
||||
*
|
||||
* @param boolean $p_exitOnError
|
||||
* $return boolean
|
||||
*/
|
||||
public static function connectToDatabase($p_exitOnError = true)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo $CC_DBC->getMessage().PHP_EOL;
|
||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
}
|
||||
try {
|
||||
$con = Propel::getConnection();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function DbTableExists($p_name)
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT * FROM ".$p_name;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
$con = Propel::getConnection();
|
||||
try {
|
||||
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||
$con->query($sql);
|
||||
} catch (PDOException $e){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function GetAirtimeSrcDir()
|
||||
|
@ -176,9 +181,9 @@ class UpgradeCommon{
|
|||
private static function ReadPythonConfig($p_filename)
|
||||
{
|
||||
$values = array();
|
||||
|
||||
|
||||
$fh = fopen($p_filename, 'r');
|
||||
|
||||
|
||||
while(!feof($fh)){
|
||||
$line = fgets($fh);
|
||||
if(substr(trim($line), 0, 1) == '#' || trim($line) == ""){
|
||||
|
|
Loading…
Reference in New Issue