CC-3751: Remove db.php requirement in the upgrade script
- fixed
This commit is contained in:
parent
af1b5d3f7a
commit
5b816d1fad
|
@ -15,7 +15,7 @@ class AirtimeDatabaseUpgrade{
|
||||||
UpgradeCommon::MigrateTablesToVersion(__DIR__, '20120411174904');
|
UpgradeCommon::MigrateTablesToVersion(__DIR__, '20120411174904');
|
||||||
|
|
||||||
$sql = "INSERT INTO cc_pref(\"keystr\", \"valstr\") VALUES('scheduled_play_switch', 'on')";
|
$sql = "INSERT INTO cc_pref(\"keystr\", \"valstr\") VALUES('scheduled_play_switch', 'on')";
|
||||||
UpgradeCommon::nonSelectQueryDb($sql);
|
UpgradeCommon::queryDb($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('DB.php');
|
|
||||||
|
|
||||||
/* These are helper functions that are common to each upgrade such as
|
/* These are helper functions that are common to each upgrade such as
|
||||||
* creating connections to a database, backing up config files etc.
|
* creating connections to a database, backing up config files etc.
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +18,7 @@ class UpgradeCommon{
|
||||||
{
|
{
|
||||||
$sql = "SELECT valstr from cc_pref WHERE keystr = 'timezone'";
|
$sql = "SELECT valstr from cc_pref WHERE keystr = 'timezone'";
|
||||||
|
|
||||||
$result = self::selectQueryDb($sql);
|
$result = self::queryDb($sql);
|
||||||
$timezone = $result['valstr'];
|
$timezone = $result['valstr'];
|
||||||
|
|
||||||
date_default_timezone_set($timezone);
|
date_default_timezone_set($timezone);
|
||||||
|
@ -29,29 +26,28 @@ class UpgradeCommon{
|
||||||
|
|
||||||
public static function connectToDatabase($p_exitOnError = true)
|
public static function connectToDatabase($p_exitOnError = true)
|
||||||
{
|
{
|
||||||
global $CC_DBC, $CC_CONFIG;
|
try {
|
||||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
$con = Propel::getConnection();
|
||||||
if (PEAR::isError($CC_DBC)) {
|
} catch (Exception $e) {
|
||||||
echo $CC_DBC->getMessage().PHP_EOL;
|
echo $e->getMessage().PHP_EOL;
|
||||||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
|
||||||
echo "Database connection problem.".PHP_EOL;
|
echo "Database connection problem.".PHP_EOL;
|
||||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
echo "Check if database exists with corresponding permissions.".PHP_EOL;
|
||||||
" with corresponding permissions.".PHP_EOL;
|
|
||||||
if ($p_exitOnError) {
|
if ($p_exitOnError) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
return false;
|
||||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function DbTableExists($p_name)
|
public static function DbTableExists($p_name)
|
||||||
{
|
{
|
||||||
global $CC_DBC;
|
$con = Propel::getConnection();
|
||||||
$sql = "SELECT * FROM ".$p_name;
|
try {
|
||||||
$result = $CC_DBC->GetOne($sql);
|
$sql = "SELECT * FROM ".$p_name." LIMIT 1";
|
||||||
if (PEAR::isError($result)) {
|
$con->query($sql);
|
||||||
|
} catch (PDOException $e){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -238,27 +234,16 @@ class UpgradeCommon{
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function selectQueryDb($p_sql){
|
public static function queryDb($p_sql){
|
||||||
global $CC_DBC;
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
$result = $CC_DBC->getRow($p_sql, $fetchmode=DB_FETCHMODE_ASSOC);
|
try {
|
||||||
if (PEAR::isError($result)) {
|
$result = $con->exec($p_sql);
|
||||||
echo "Error executing $sql. Exiting.";
|
} catch (Exception $e) {
|
||||||
|
echo "Error executing $p_sql. Exiting.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function nonSelectQueryDb($p_sql){
|
|
||||||
global $CC_DBC;
|
|
||||||
|
|
||||||
$result = $CC_DBC->query($p_sql);
|
|
||||||
if (PEAR::isError($result)) {
|
|
||||||
echo "Error executing $sql. Exiting.";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue