require_once __DIR__ . '/AirtimeIni.php'; require_once __DIR__ . '/AirtimeInstall.php'; require_once 'propel/runtime/lib/Propel.php'; Propel::init(AirtimeInstall::GetAirtimeSrcDir() . "/application/configs/db-conf.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. */ if (getenv("AIRTIME_INSTALL_DEBUG") === "1") { echo "Press Enter to Continue" . PHP_EOL; fgets(STDIN); } } AirtimeInstall::DbConnect(true); $con = Propel::getConnection(); $version = AirtimeInstall::GetVersionInstalled(); echo "******************************** Upgrade Begin *********************************" . PHP_EOL; global $CC_CONFIG; $user = $CC_CONFIG['dsn']['username']; $password = $CC_CONFIG['dsn']['password']; $host = $CC_CONFIG['dsn']['hostspec']; $database = $CC_CONFIG['dsn']['database']; $airtime_version = AIRTIME_VERSION; $target_dir = trim(getenv("HOME")); if (strlen($target_dir) == 0) { $target_dir = "/tmp"; } $target_file = "/airtime_{$airtime_version}.sql"; $target_path = $target_dir . $target_file;
//------------------------------------------------------------------------ //close connection for any process id using airtime database since we are about to drop the database. $sql = "SELECT pg_cancel_backend(procpid) FROM pg_stat_activity WHERE datname = 'airtime';"; $command = "echo \"{$sql}\" | su postgres -c psql"; @exec($command, $output); $CC_CONFIG = Config::getConfig(); echo " * Dropping the database '" . $CC_CONFIG["dsn"]["database"] . "'..." . PHP_EOL; //dropdb returns 1 if other sessions are using the database, otherwise returns 0 $command = "su postgres -c \"dropdb " . $CC_CONFIG["dsn"]["database"] . "\""; @exec($command, $output, $dbDeleteFailed); //------------------------------------------------------------------------ // Delete DB tables // We do this if dropping the database fails above. //------------------------------------------------------------------------ if ($dbDeleteFailed) { $connected = AirtimeInstall::DbConnect(false); if ($connected) { echo " * Couldn't delete the database, so deleting all the DB tables..." . PHP_EOL; $con = Propel::getConnection(); $sql = "select * from pg_tables where tableowner = 'airtime'"; try { $rows = $con->query($sql)->fetchAll(); } catch (Exception $e) { $rows = array(); } foreach ($rows as $row) { $tablename = $row["tablename"]; echo " * Removing database table {$tablename}..."; $sql = "DROP TABLE {$tablename} CASCADE"; AirtimeInstall::InstallQuery($sql, false); AirtimeInstall::DropSequence($tablename . "_id");