mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Update DB classes to use new config format
This commit is contained in:
parent
6876eac464
commit
e28856bfbb
9 changed files with 70 additions and 88 deletions
|
|
@ -139,11 +139,15 @@ class DB
|
|||
* @param string $db_type type of db
|
||||
* @return DB return DB object instance
|
||||
*/
|
||||
function getInstance($db_type = NULL)
|
||||
public static function getInstance($db_type = NULL)
|
||||
{
|
||||
if(!$db_type)
|
||||
{
|
||||
$db_type = Context::getDBType();
|
||||
$db_type = config('db.master.type');
|
||||
if (config('db.master.engine') === 'innodb')
|
||||
{
|
||||
$db_type .= '_innodb';
|
||||
}
|
||||
}
|
||||
if(!$db_type && Context::isInstalled())
|
||||
{
|
||||
|
|
@ -157,7 +161,7 @@ class DB
|
|||
if(!isset($GLOBALS['__DB__'][$db_type]))
|
||||
{
|
||||
$class_name = 'DB' . ucfirst($db_type);
|
||||
$class_file = _XE_PATH_ . "classes/db/$class_name.class.php";
|
||||
$class_file = RX_BASEDIR . "classes/db/$class_name.class.php";
|
||||
if(!file_exists($class_file))
|
||||
{
|
||||
return new Object(-1, 'msg_db_not_setted');
|
||||
|
|
@ -165,7 +169,7 @@ class DB
|
|||
|
||||
// get a singletone instance of the database driver class
|
||||
require_once($class_file);
|
||||
$GLOBALS['__DB__'][$db_type] = call_user_func(array($class_name, 'create'));
|
||||
$GLOBALS['__DB__'][$db_type] = new $class_name;
|
||||
$GLOBALS['__DB__'][$db_type]->db_type = $db_type;
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +180,7 @@ class DB
|
|||
* returns instance of db
|
||||
* @return DB return DB object instance
|
||||
*/
|
||||
function create()
|
||||
public static function create()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
|
@ -185,7 +189,7 @@ class DB
|
|||
* constructor
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
$this->count_cache_path = _XE_PATH_ . $this->count_cache_path;
|
||||
$this->cache_file = _XE_PATH_ . $this->cache_file;
|
||||
|
|
@ -1010,7 +1014,7 @@ class DB
|
|||
{
|
||||
$this->_connect($type);
|
||||
}
|
||||
$this->connection = 'Master ' . $this->master_db['db_hostname'];
|
||||
$this->connection = 'Master ' . $this->master_db['host'];
|
||||
return $this->master_db["resource"];
|
||||
}
|
||||
|
||||
|
|
@ -1024,7 +1028,7 @@ class DB
|
|||
$this->_connect($type, $indx);
|
||||
}
|
||||
|
||||
$this->connection = 'Slave ' . $this->slave_db[$indx]['db_hostname'];
|
||||
$this->connection = 'Slave ' . $this->slave_db[$indx]['host'];
|
||||
return $this->slave_db[$indx]["resource"];
|
||||
}
|
||||
|
||||
|
|
@ -1219,23 +1223,11 @@ class DB
|
|||
*/
|
||||
function _setDBInfo()
|
||||
{
|
||||
$db_info = Context::getDBInfo();
|
||||
$this->master_db = $db_info->master_db;
|
||||
if($db_info->master_db["db_hostname"] == $db_info->slave_db[0]["db_hostname"]
|
||||
&& $db_info->master_db["db_port"] == $db_info->slave_db[0]["db_port"]
|
||||
&& $db_info->master_db["db_userid"] == $db_info->slave_db[0]["db_userid"]
|
||||
&& $db_info->master_db["db_password"] == $db_info->slave_db[0]["db_password"]
|
||||
&& $db_info->master_db["db_database"] == $db_info->slave_db[0]["db_database"]
|
||||
)
|
||||
{
|
||||
$this->slave_db[0] = &$this->master_db;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->slave_db = $db_info->slave_db;
|
||||
}
|
||||
$this->prefix = $db_info->master_db["db_table_prefix"];
|
||||
$this->use_prepared_statements = $db_info->use_prepared_statements;
|
||||
$db_info = config('db');
|
||||
$this->master_db = $db_info['master'];
|
||||
$this->slave_db = $db_info ? array_values($db_info) : null;
|
||||
$this->prefix = $this->master_db['prefix'];
|
||||
$this->use_prepared_statements = config('use_prepared_statements');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1301,7 +1293,7 @@ class DB
|
|||
$connection["is_connected"] = TRUE;
|
||||
|
||||
// Save connection info for db logs
|
||||
$this->connection = ucfirst($type) . ' ' . $connection["db_hostname"];
|
||||
$this->connection = ucfirst($type) . ' ' . $connection['host'];
|
||||
|
||||
// regist $this->close callback
|
||||
register_shutdown_function(array($this, "close"));
|
||||
|
|
|
|||
|
|
@ -55,15 +55,6 @@ class DBCubrid extends DB
|
|||
$this->_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of this class
|
||||
* @return DBCubrid return DBCubrid object instance
|
||||
*/
|
||||
function create()
|
||||
{
|
||||
return new DBCubrid;
|
||||
}
|
||||
|
||||
/**
|
||||
* DB Connect
|
||||
* this method is private
|
||||
|
|
@ -73,7 +64,7 @@ class DBCubrid extends DB
|
|||
function __connect($connection)
|
||||
{
|
||||
// attempts to connect
|
||||
$result = @cubrid_connect($connection["db_hostname"], $connection["db_port"], $connection["db_database"], $connection["db_userid"], $connection["db_password"]);
|
||||
$result = @cubrid_connect($connection['host'], $connection['port'], $connection['database'], $connection['user'], $connection['pass']);
|
||||
|
||||
// check connections
|
||||
if(!$result)
|
||||
|
|
|
|||
|
|
@ -48,15 +48,6 @@ class DBMssql extends DB
|
|||
$this->_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of this class
|
||||
* @return DBMssql return DBMssql object instance
|
||||
*/
|
||||
function create()
|
||||
{
|
||||
return new DBMssql;
|
||||
}
|
||||
|
||||
/**
|
||||
* DB Connect
|
||||
* this method is private
|
||||
|
|
@ -68,7 +59,11 @@ class DBMssql extends DB
|
|||
//sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
//sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
//sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
|
||||
$result = @sqlsrv_connect($connection["db_hostname"], array('Database' => $connection["db_database"], 'UID' => $connection["db_userid"], 'PWD' => $connection["db_password"]));
|
||||
$result = @sqlsrv_connect($connection['host'], array(
|
||||
'Database' => $connection['database'],
|
||||
'UID' => $connection['user'],
|
||||
'PWD' => $connection['pass'],
|
||||
));
|
||||
|
||||
if(!$result)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,13 +58,13 @@ class DBMysql extends DB
|
|||
function __connect($connection)
|
||||
{
|
||||
// Ignore if no DB information exists
|
||||
if(strpos($connection["db_hostname"], ':') === false && $connection["db_port"])
|
||||
if(strpos($connection['host'], ':') === false && $connection['port'])
|
||||
{
|
||||
$connection["db_hostname"] .= ':' . $connection["db_port"];
|
||||
$connection['host'] .= ':' . $connection['port'];
|
||||
}
|
||||
|
||||
// Attempt to connect
|
||||
$result = @mysql_connect($connection["db_hostname"], $connection["db_userid"], $connection["db_password"]);
|
||||
$result = @mysql_connect($connection['host'], $connection['user'], $connection['pass']);
|
||||
if(!$result)
|
||||
{
|
||||
exit('Unable to connect to DB.');
|
||||
|
|
@ -84,11 +84,11 @@ class DBMysql extends DB
|
|||
}
|
||||
|
||||
// Set charset
|
||||
$this->charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8';
|
||||
$this->charset = isset($connection['charset']) ? $connection['charset'] : 'utf8';
|
||||
mysql_set_charset($this->charset, $result);
|
||||
|
||||
// select db
|
||||
@mysql_select_db($connection["db_database"], $result);
|
||||
@mysql_select_db($connection['database'], $result);
|
||||
if(mysql_error())
|
||||
{
|
||||
$this->setError(mysql_errno(), mysql_error());
|
||||
|
|
|
|||
|
|
@ -24,20 +24,13 @@ class DBMysqli extends DBMysql
|
|||
function __connect($connection)
|
||||
{
|
||||
// Attempt to connect
|
||||
if($connection["db_port"])
|
||||
if($connection['port'])
|
||||
{
|
||||
$result = @mysqli_connect($connection["db_hostname"]
|
||||
, $connection["db_userid"]
|
||||
, $connection["db_password"]
|
||||
, $connection["db_database"]
|
||||
, $connection["db_port"]);
|
||||
$result = @mysqli_connect($connection['host'], $connection['user'], $connection['pass'], $connection['database'], $connection['port']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = @mysqli_connect($connection["db_hostname"]
|
||||
, $connection["db_userid"]
|
||||
, $connection["db_password"]
|
||||
, $connection["db_database"]);
|
||||
$result = @mysqli_connect($connection['host'], $connection['user'], $connection['pass'], $connection['database']);
|
||||
}
|
||||
$error = mysqli_connect_errno();
|
||||
if($error)
|
||||
|
|
@ -45,7 +38,7 @@ class DBMysqli extends DBMysql
|
|||
$this->setError($error, mysqli_connect_error());
|
||||
return;
|
||||
}
|
||||
$this->charset = isset($connection["db_charset"]) ? $connection["db_charset"] : 'utf8';
|
||||
$this->charset = isset($connection['charset']) ? $connection['charset'] : 'utf8';
|
||||
mysqli_set_charset($result, $this->charset);
|
||||
return $result;
|
||||
}
|
||||
|
|
@ -89,6 +82,11 @@ class DBMysqli extends DBMysql
|
|||
*/
|
||||
function __query($query, $connection)
|
||||
{
|
||||
if ($connection === null)
|
||||
{
|
||||
debug_print_backtrace();
|
||||
exit;
|
||||
}
|
||||
if($this->use_prepared_statements == 'Y')
|
||||
{
|
||||
// 1. Prepare query
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ class CubridTableWithHint extends Table
|
|||
$result = '';
|
||||
|
||||
// Retrieve table prefix, to add it to index name
|
||||
$db_info = Context::getDBInfo();
|
||||
$prefix = $db_info->master_db["db_table_prefix"];
|
||||
$prefix = config('db.master.prefix');
|
||||
|
||||
foreach($this->index_hints_list as $index_hint)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -100,6 +100,17 @@ class Config
|
|||
$data = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all system configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function setAll($config)
|
||||
{
|
||||
self::$_config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert previous configuration files to the current format and return it.
|
||||
*
|
||||
|
|
@ -345,8 +356,11 @@ class Config
|
|||
*/
|
||||
public static function save($config = null)
|
||||
{
|
||||
$config = ($config === null) ? self::$_config : $config;
|
||||
$buff = '<?php' . "\n" . '// Rhymix System Configuration' . "\n" . 'return ' . self::serialize($config) . ';' . "\n";
|
||||
if ($config)
|
||||
{
|
||||
self::setAll($config);
|
||||
}
|
||||
$buff = '<?php' . "\n" . '// Rhymix System Configuration' . "\n" . 'return ' . self::serialize(self::$_config) . ';' . "\n";
|
||||
return \FileHandler::writeFile(RX_BASEDIR . 'files/config/config.php', $buff) ? true : false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,20 +33,15 @@ class installController extends install
|
|||
$config = Context::gets('db_type', 'db_host', 'db_port', 'db_user', 'db_pass', 'db_database', 'db_prefix');
|
||||
|
||||
// Create a temporary setting object.
|
||||
$db_info = new stdClass();
|
||||
$db_info->master_db = array();
|
||||
$db_info->master_db['db_type'] = $config->db_type;
|
||||
$db_info->master_db['db_hostname'] = $config->db_host;
|
||||
$db_info->master_db['db_port'] = $config->db_port;
|
||||
$db_info->master_db['db_userid'] = $config->db_user;
|
||||
$db_info->master_db['db_password'] = $config->db_pass;
|
||||
$db_info->master_db['db_database'] = $config->db_database;
|
||||
$db_info->master_db['db_table_prefix'] = $config->db_prefix;
|
||||
$db_info->slave_db = array($db_info->master_db);
|
||||
$db_info->default_url = Context::getRequestUri();
|
||||
$db_info->lang_type = Context::getLangType();
|
||||
$db_info->use_mobile_view = 'Y';
|
||||
Context::setDBInfo($db_info);
|
||||
Rhymix\Framework\Config::set('db.master', array(
|
||||
'type' => $config->db_type,
|
||||
'host' => $config->db_host,
|
||||
'port' => $config->db_port,
|
||||
'user' => $config->db_user,
|
||||
'pass' => $config->db_pass,
|
||||
'database' => $config->db_database,
|
||||
'prefix' => $config->db_prefix,
|
||||
));
|
||||
|
||||
// Check connection to the DB.
|
||||
$oDB = DB::getInstance();
|
||||
|
|
@ -180,6 +175,7 @@ class installController extends install
|
|||
$config['url']['default'] = Context::getRequestUri();
|
||||
|
||||
// Load the new configuration.
|
||||
Rhymix\Framework\Config::setAll($config);
|
||||
Context::loadDBInfo($config);
|
||||
|
||||
// Check DB.
|
||||
|
|
@ -223,7 +219,7 @@ class installController extends install
|
|||
}
|
||||
|
||||
// Save the new configuration.
|
||||
Rhymix\Framework\Config::save($config);
|
||||
Rhymix\Framework\Config::save();
|
||||
|
||||
// Unset temporary session variables.
|
||||
unset($_SESSION['use_rewrite']);
|
||||
|
|
@ -231,12 +227,9 @@ class installController extends install
|
|||
|
||||
// Redirect to the home page.
|
||||
$this->setMessage('msg_install_completed');
|
||||
if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
|
||||
{
|
||||
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('');
|
||||
$this->setRedirectUrl($returnUrl);
|
||||
}
|
||||
|
||||
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : RX_BASEURL;
|
||||
$this->setRedirectUrl($returnUrl);
|
||||
return new Object();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ class installView extends install
|
|||
}
|
||||
else
|
||||
{
|
||||
header("location: ./");
|
||||
exit;
|
||||
$this->setRedirectUrl(RX_BASEURL);
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue