From 29c6006fc1b4c737ccefa7710473ec9b626192c0 Mon Sep 17 00:00:00 2001 From: Paul Baranowski Date: Wed, 22 Jun 2011 17:29:00 -0400 Subject: [PATCH] CC-2420: Reinstall fails. Fixed bug where reinstalling the database tables would crash the installer. Fixed the usage message that prints out for airtime-install so that it shows the correct command. Added code documentation for why things work the way that they do. --- install/include/AirtimeInstall.php | 15 ++++-------- install/include/airtime-db-install.php | 18 ++++++++++++++ install/include/airtime-install.php | 33 ++++++++++++++++++-------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/install/include/AirtimeInstall.php b/install/include/AirtimeInstall.php index ff7ec7737..9f2109e9f 100644 --- a/install/include/AirtimeInstall.php +++ b/install/include/AirtimeInstall.php @@ -10,6 +10,8 @@ class AirtimeInstall const CONF_DIR_WWW = "/var/www/airtime"; const CONF_DIR_LOG = "/var/log/airtime"; + public static $databaseTablesCreated = false; + public static function GetAirtimeSrcDir() { return __DIR__."/../../airtime_mvc"; @@ -106,12 +108,11 @@ class AirtimeInstall 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; + " with corresponding permissions.".PHP_EOL; if ($p_exitOnError) { exit(1); } } else { - echo "* Connected to database".PHP_EOL; $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); } } @@ -148,15 +149,6 @@ class AirtimeInstall $success = chown($rp, "pypo"); $success = chmod($rp, 02777); $CC_CONFIG['storageDir'] = $rp; - - //add stor directory to MusiDirs - $sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$rp', 'stor')"; - $result = $CC_DBC->query($sql); - if (PEAR::isError($result)) { - echo "* Failed inserting {$rp} in cc_music_dirs".PHP_EOL; - echo "* Message {$result->getMessage()}".PHP_EOL; - exit(1); - } } public static function CreateDatabaseUser() @@ -236,6 +228,7 @@ class AirtimeInstall //$command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql"; $command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql 2>/dev/null"; @exec($command, $output, $results); + AirtimeInstall::$databaseTablesCreated = true; } public static function BypassMigrations($dir, $version) diff --git a/install/include/airtime-db-install.php b/install/include/airtime-db-install.php index c339b4e6d..d3649d541 100644 --- a/install/include/airtime-db-install.php +++ b/install/include/airtime-db-install.php @@ -1,4 +1,9 @@ query($sql); + if (PEAR::isError($result)) { + echo "* Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL; + echo "* Message {$result->getMessage()}".PHP_EOL; + exit(1); + } +} \ No newline at end of file diff --git a/install/include/airtime-install.php b/install/include/airtime-install.php index 223a433b9..2cda6da54 100644 --- a/install/include/airtime-install.php +++ b/install/include/airtime-install.php @@ -4,9 +4,10 @@ * @copyright 2011 Sourcefabric O.P.S. * @license http://www.gnu.org/licenses/gpl.txt * - * Checks if a previous version of Airtime is currently installed, upgrades Airtime if so. - * Performs a new install (new configs, database install) if a version of Airtime is not found - * If the current version is found to be installed the User is presented with the help menu and can choose -r to reinstall. + * Checks if a previous version of Airtime is currently installed and upgrades Airtime if so. + * Performs a new install (new configs, database install) if a version of Airtime is not found. + * If the current version is found to be installed the user is presented with the help menu and can + * choose -r to reinstall. */ set_include_path(__DIR__.'/../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path()); @@ -22,31 +23,40 @@ $version = AirtimeInstall::GetVersionInstalled(); require_once('Zend/Loader/Autoloader.php'); $autoloader = Zend_Loader_Autoloader::getInstance(); +function printUsage($opts) +{ + $msg = $opts->getUsageMessage(); + echo PHP_EOL."Usage: airtime-install [options]"; + echo substr($msg, strpos($msg, "\n")).PHP_EOL; +} + try { $opts = new Zend_Console_Getopt( array( 'help|h' => 'Displays usage information.', 'overwrite|o' => 'Overwrite any existing config files.', 'preserve|p' => 'Keep any existing config files.', - 'no-db|n' => 'Turn off database install.', + 'no-db|n' => 'Turn off database install.', 'reinstall|r' => 'Force a fresh install of this Airtime Version' ) ); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { - exit($e->getMessage() ."\n\n". $e->getUsageMessage()); + print $e->getMessage() .PHP_EOL; + printUsage($opts); + exit(1); } if (isset($opts->h)) { - echo $opts->getUsageMessage(); + printUsage($opts); exit(1); } // The current version is already installed. if(isset($version) && ($version != false) && ($version == AIRTIME_VERSION) && !isset($opts->r)) { echo "Airtime $version is already installed.".PHP_EOL; - echo $opts->getUsageMessage(); + printUsage($opts); exit(1); } // A previous version exists - if so, upgrade. @@ -122,6 +132,8 @@ echo "* Airtime Version: ".AIRTIME_VERSION.PHP_EOL; if ($db_install) { if($newInstall) { + // This is called with "system" so that we can pass in a parameter. See the file itself + // for why we need to do this. system('php '.__DIR__.'/airtime-db-install.php y'); AirtimeInstall::DbConnect(true); } else { @@ -137,11 +149,12 @@ AirtimeInstall::CreateZendPhpLogFile(); AirtimeInstall::SetUniqueId(); -$h = rand(0,23); -$m = rand(0,59); +// Create CRON task to run every day. Time of day is initialized to a random time. +$hour = rand(0,23); +$minute = rand(0,59); $fp = fopen('/etc/cron.d/airtime-crons','a'); -fwrite($fp, "$m $h * * * root /usr/lib/airtime/utils/phone_home_stat\n"); +fwrite($fp, "$minute $hour * * * root /usr/lib/airtime/utils/phone_home_stat\n"); fclose($fp); /* FINISHED AIRTIME PHP INSTALLER */