From e7589f6007cf8265f2711dac4a7b29361c7cca92 Mon Sep 17 00:00:00 2001 From: Naomi Date: Thu, 19 May 2011 14:06:27 -0400 Subject: [PATCH] CC-2281 Install script should check for pre-installed versions and prompt user to upgrade/full installation adding upgrade/install command option. --- install/airtime-install.php | 33 +++++++++++++++++++++++++++++ install/include/AirtimeInstall.php | 34 ++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/install/airtime-install.php b/install/airtime-install.php index 60847332b..8f4f0f568 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -11,9 +11,42 @@ echo "******************************** Install Begin *************************** require_once(dirname(__FILE__).'/include/AirtimeIni.php'); require_once(dirname(__FILE__).'/include/AirtimeInstall.php'); +require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/conf.php'); AirtimeInstall::ExitIfNotRoot(); +$version = AirtimeInstall::CheckForVersionBeforeInstall(); + +//a previous version exists. +if(isset($version) && $version != false && $version < AIRTIME_VERSION) { + + echo "Airtime version $version found.".PHP_EOL; + + try { + $opts = new Zend_Console_Getopt( + array( + 'upgrade|u' => 'Upgrades Airtime Application.', + 'install|i' => 'Installs Airtime Application.', + ) + ); + $opts->parse(); + } + catch (Zend_Console_Getopt_Exception $e) { + exit($e->getMessage() ."\n\n". $e->getUsageMessage()); + } + + $userAnswer = "x"; + while (!in_array($userAnswer, array("u", "U", "i", "I", ""))) { + echo PHP_EOL."You have an older version of Airtime Installed, would you like to (U)pgrade or do a fresh (I)nstall?"; + $userAnswer = trim(fgets(STDIN)); + } + if (in_array($userAnswer, array("u", "U"))) { + $command = "php airtime-upgrade.php"; + system($command); + exit(); + } +} + require_once('Zend/Loader/Autoloader.php'); $autoloader = Zend_Loader_Autoloader::getInstance(); diff --git a/install/include/AirtimeInstall.php b/install/include/AirtimeInstall.php index d5a148f08..b515ddf9f 100644 --- a/install/include/AirtimeInstall.php +++ b/install/include/AirtimeInstall.php @@ -34,6 +34,32 @@ class AirtimeInstall } } + public static function CheckForVersionBeforeInstall() + { + global $CC_DBC, $CC_CONFIG; + + try{ + $CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE); + } + catch(Exception $e){ + + } + + if (PEAR::isError($CC_DBC)) { + echo "New Airtime Install.".PHP_EOL; + } + 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)) { + return null; + } + return $version; + } + } public static function DbTableExists($p_name) { @@ -142,7 +168,7 @@ class AirtimeInstall } } - + public static function CreateDatabase() { global $CC_CONFIG; @@ -153,7 +179,7 @@ class AirtimeInstall $username = $CC_CONFIG['dsn']['username']; #$command = "echo \"CREATE DATABASE $database OWNER $username\" | su postgres -c psql 2>/dev/null"; $command = "su postgres -c \"createdb $database --owner $username\""; - + @exec($command, $output, $results); if ($results == 0) { echo "* Database '{$CC_CONFIG['dsn']['database']}' created.".PHP_EOL; @@ -166,9 +192,9 @@ class AirtimeInstall echo "* Database '{$CC_CONFIG['dsn']['database']}' already exists.".PHP_EOL; } } - + $databaseExisted = ($results != 0); - + return $databaseExisted; }