CC-2279: Upgrade script for converting stor directory to new format
-make every function a static function and put into a class
This commit is contained in:
parent
aa1039413a
commit
232470c66b
|
@ -321,7 +321,7 @@ class AirtimeInstall{
|
||||||
INSERT INTO cc_country (isocode, name) VALUES ('ZWE', 'Zimbabwe ');";
|
INSERT INTO cc_country (isocode, name) VALUES ('ZWE', 'Zimbabwe ');";
|
||||||
|
|
||||||
echo "* Inserting data into country table".PHP_EOL;
|
echo "* Inserting data into country table".PHP_EOL;
|
||||||
execSqlQuery($sql);
|
Airtime190Upgrade::execSqlQuery($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ class AirtimeIni{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeConfigFiles(){
|
public static function upgradeConfigFiles(){
|
||||||
|
|
||||||
$configFiles = array(AirtimeIni::CONF_FILE_AIRTIME,
|
$configFiles = array(AirtimeIni::CONF_FILE_AIRTIME,
|
||||||
AirtimeIni::CONF_FILE_PYPO,
|
AirtimeIni::CONF_FILE_PYPO,
|
||||||
|
@ -443,7 +443,7 @@ class AirtimeIni{
|
||||||
* This function creates the /etc/airtime configuration folder
|
* This function creates the /etc/airtime configuration folder
|
||||||
* and copies the default config files to it.
|
* and copies the default config files to it.
|
||||||
*/
|
*/
|
||||||
function CreateIniFiles()
|
public static function CreateIniFiles()
|
||||||
{
|
{
|
||||||
if (!file_exists("/etc/airtime/")){
|
if (!file_exists("/etc/airtime/")){
|
||||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||||
|
@ -474,117 +474,122 @@ class AirtimeIni{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function InstallAirtimePhpServerCode($phpDir)
|
class Airtime190Upgrade{
|
||||||
{
|
|
||||||
|
|
||||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
public static function InstallAirtimePhpServerCode($phpDir)
|
||||||
|
{
|
||||||
|
|
||||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||||
exec("mkdir -p ".$phpDir);
|
|
||||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
function CopyUtils()
|
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||||
{
|
exec("mkdir -p ".$phpDir);
|
||||||
$utilsSrc = __DIR__."/../../../utils";
|
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||||
|
|
||||||
echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
|
|
||||||
exec("mkdir -p ".CONF_DIR_BINARIES);
|
|
||||||
exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Removes pypo, media-monitor, show-recorder and utils from system. These will
|
|
||||||
* be reinstalled by the main airtime-upgrade script.
|
|
||||||
*/
|
|
||||||
function UninstallBinaries()
|
|
||||||
{
|
|
||||||
echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
|
|
||||||
exec('rm -rf "'.CONF_DIR_BINARIES.'"');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function removeOldAirtimeImport(){
|
|
||||||
exec('rm -f "/usr/bin/airtime-import"');
|
|
||||||
exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
|
|
||||||
exec('rm -rf "/usr/lib/airtime/utils/airtime-import"');
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAirtimeImportSymLink(){
|
|
||||||
$dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
|
|
||||||
exec("ln -s $dir /usr/bin/airtime-import");
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectToDatabase(){
|
public static function CopyUtils()
|
||||||
global $CC_DBC, $CC_CONFIG;
|
{
|
||||||
|
$utilsSrc = __DIR__."/../../../utils";
|
||||||
|
|
||||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
|
||||||
|
exec("mkdir -p ".CONF_DIR_BINARIES);
|
||||||
// Database config
|
exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Old database had a "fullpath" column that stored the absolute path of each track. We have to
|
|
||||||
* change it so that the "fullpath" column has path relative to the "directory" column.
|
|
||||||
*/
|
|
||||||
function installMediaMonitor($values){
|
|
||||||
|
|
||||||
/* Handle Database Changes. */
|
|
||||||
$stor_dir = realpath($values['general']['base_files_dir']."/stor")."/";
|
|
||||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
|
||||||
$sql = "UPDATE cc_music_dirs SET directory='$stor_dir' WHERE type='stor'";
|
|
||||||
echo $sql.PHP_EOL;
|
|
||||||
execSqlQuery($sql);
|
|
||||||
|
|
||||||
$sql = "SELECT id FROM cc_music_dirs WHERE type='stor'";
|
|
||||||
echo $sql.PHP_EOL;
|
|
||||||
$rows = execSqlQuery($sql);
|
|
||||||
|
|
||||||
echo "Creating media-monitor log file";
|
|
||||||
mkdir("/var/log/airtime/media-monitor/", 755, true);
|
|
||||||
touch("/var/log/airtime/media-monitor/media-monitor.log");
|
|
||||||
|
|
||||||
/* create media monitor config: */
|
|
||||||
if (!copy(__DIR__."/../../../python_apps/media-monitor/media-monitor.cfg", AirtimeIni::CONF_FILE_MEDIAMONITOR)){
|
|
||||||
echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_MEDIAMONITOR, "api_key", $values["general"]["api_key"]);
|
|
||||||
|
|
||||||
echo "Reorganizing files in stor directory";
|
/* Removes pypo, media-monitor, show-recorder and utils from system. These will
|
||||||
$mediaMonitorUpgradePath = realpath(__DIR__."/../../../python_apps/media-monitor/media-monitor-upgrade.py");
|
* be reinstalled by the main airtime-upgrade script.
|
||||||
exec("su -c \"python $mediaMonitorUpgradePath\"", $output);
|
*/
|
||||||
print_r($output);
|
public static function UninstallBinaries()
|
||||||
|
{
|
||||||
|
echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
|
||||||
|
exec('rm -rf "'.CONF_DIR_BINARIES.'"');
|
||||||
|
}
|
||||||
|
|
||||||
$oldAndNewFileNames = json_decode($output[0]);
|
|
||||||
|
|
||||||
foreach ($oldAndNewFileNames as $pair){
|
public static function removeOldAirtimeImport(){
|
||||||
$relPathNew = pg_escape_string(substr($pair[1], strlen($stor_dir)));
|
exec('rm -f "/usr/bin/airtime-import"');
|
||||||
$absPathOld = pg_escape_string($pair[0]);
|
exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
|
||||||
$sql = "UPDATE cc_files SET filepath = '$relPathNew', directory=1 WHERE filepath = '$absPathOld'";
|
exec('rm -rf "/usr/lib/airtime/utils/airtime-import"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateAirtimeImportSymLink(){
|
||||||
|
$dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
|
||||||
|
exec("ln -s $dir /usr/bin/airtime-import");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Old database had a "fullpath" column that stored the absolute path of each track. We have to
|
||||||
|
* change it so that the "fullpath" column has path relative to the "directory" column.
|
||||||
|
*/
|
||||||
|
public static function installMediaMonitor($values){
|
||||||
|
|
||||||
|
/* Handle Database Changes. */
|
||||||
|
$stor_dir = realpath($values['general']['base_files_dir']."/stor")."/";
|
||||||
|
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||||
|
$sql = "UPDATE cc_music_dirs SET directory='$stor_dir' WHERE type='stor'";
|
||||||
echo $sql.PHP_EOL;
|
echo $sql.PHP_EOL;
|
||||||
execSqlQuery($sql);
|
Airtime190Upgrade::execSqlQuery($sql);
|
||||||
|
|
||||||
|
$sql = "SELECT id FROM cc_music_dirs WHERE type='stor'";
|
||||||
|
echo $sql.PHP_EOL;
|
||||||
|
$rows = Airtime190Upgrade::execSqlQuery($sql);
|
||||||
|
|
||||||
|
echo "Creating media-monitor log file";
|
||||||
|
mkdir("/var/log/airtime/media-monitor/", 755, true);
|
||||||
|
touch("/var/log/airtime/media-monitor/media-monitor.log");
|
||||||
|
|
||||||
|
/* create media monitor config: */
|
||||||
|
if (!copy(__DIR__."/../../../python_apps/media-monitor/media-monitor.cfg", AirtimeIni::CONF_FILE_MEDIAMONITOR)){
|
||||||
|
echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting.";
|
||||||
|
}
|
||||||
|
|
||||||
|
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_MEDIAMONITOR, "api_key", $values["general"]["api_key"]);
|
||||||
|
|
||||||
|
echo "Reorganizing files in stor directory";
|
||||||
|
$mediaMonitorUpgradePath = realpath(__DIR__."/../../../python_apps/media-monitor/media-monitor-upgrade.py");
|
||||||
|
exec("su -c \"python $mediaMonitorUpgradePath\"", $output);
|
||||||
|
print_r($output);
|
||||||
|
|
||||||
|
$oldAndNewFileNames = json_decode($output[0]);
|
||||||
|
|
||||||
|
foreach ($oldAndNewFileNames as $pair){
|
||||||
|
$relPathNew = pg_escape_string(substr($pair[1], strlen($stor_dir)));
|
||||||
|
$absPathOld = pg_escape_string($pair[0]);
|
||||||
|
$sql = "UPDATE cc_files SET filepath = '$relPathNew', directory=1 WHERE filepath = '$absPathOld'";
|
||||||
|
echo $sql.PHP_EOL;
|
||||||
|
Airtime190Upgrade::execSqlQuery($sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AirtimeInstall::CreateZendPhpLogFile();
|
AirtimeInstall::CreateZendPhpLogFile();
|
||||||
|
|
||||||
/* In version 1.9.0 we have have switched from daemontools to more traditional
|
/* In version 1.9.0 we have have switched from daemontools to more traditional
|
||||||
|
@ -624,19 +629,19 @@ foreach ($pathnames as $pn){
|
||||||
/* update Airtime Server PHP files */
|
/* update Airtime Server PHP files */
|
||||||
$values = parse_ini_file(AirtimeIni::CONF_FILE_AIRTIME, true);
|
$values = parse_ini_file(AirtimeIni::CONF_FILE_AIRTIME, true);
|
||||||
$phpDir = $values['general']['airtime_dir'];
|
$phpDir = $values['general']['airtime_dir'];
|
||||||
InstallAirtimePhpServerCode($phpDir);
|
Airtime190Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||||
|
|
||||||
/* update utils (/usr/lib/airtime) folder */
|
/* update utils (/usr/lib/airtime) folder */
|
||||||
UninstallBinaries();
|
Airtime190Upgrade::UninstallBinaries();
|
||||||
CopyUtils();
|
Airtime190Upgrade::CopyUtils();
|
||||||
|
|
||||||
/* James made a new airtime-import script, lets remove the old airtime-import php script,
|
/* James made a new airtime-import script, lets remove the old airtime-import php script,
|
||||||
*install the new airtime-import.py script and update the /usr/bin/symlink.
|
*install the new airtime-import.py script and update the /usr/bin/symlink.
|
||||||
*/
|
*/
|
||||||
removeOldAirtimeImport();
|
Airtime190Upgrade::removeOldAirtimeImport();
|
||||||
updateAirtimeImportSymLink();
|
Airtime190Upgrade::updateAirtimeImportSymLink();
|
||||||
|
|
||||||
connectToDatabase();
|
Airtime190Upgrade::connectToDatabase();
|
||||||
|
|
||||||
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
||||||
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005');
|
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005');
|
||||||
|
@ -654,7 +659,7 @@ AirtimeInstall::InsertCountryDataIntoDatabase();
|
||||||
/* create cron file for phone home stat */
|
/* create cron file for phone home stat */
|
||||||
AirtimeInstall::CreateCronFile();
|
AirtimeInstall::CreateCronFile();
|
||||||
|
|
||||||
installMediaMonitor($values);
|
Airtime190Upgrade::installMediaMonitor($values);
|
||||||
|
|
||||||
AirtimeIni::upgradeConfigFiles();
|
AirtimeIni::upgradeConfigFiles();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue