CC-2281 Install script should check for pre-installed versions and prompt user to upgrade/full installation

adding upgrade/install command option.
This commit is contained in:
Naomi 2011-05-19 14:06:27 -04:00
parent b48220f0ea
commit e7589f6007
2 changed files with 63 additions and 4 deletions

View File

@ -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();

View File

@ -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;
}