Skip to content

Commit

Permalink
Updates for Legacy compatibility and 1 minor bug change.
Browse files Browse the repository at this point in the history
Now use getConnection for Doctrine connection and getDatabaseConnection
for legacy connection.  Converted XMF assignments for this and added
global $xoopsDB to search.php
  • Loading branch information
redheadedrod committed Oct 15, 2013
1 parent f10637b commit dd887a4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
26 changes: 7 additions & 19 deletions htdocs/class/database/databasefactory.php
Expand Up @@ -37,20 +37,16 @@ class XoopsDatabaseFactory
*
* Legacy support function
*
* NOTE: Persistance connection is not included. XOOPS_DB_PCONNECT is ignored.
*
* NOTE: retLegacy was added as a temporary stop gap to return getDatabaseConnection back to legacy.
* it will be removed once the core is seperated properly and getConnection is for new database
* and getDatabaseConnection is set for legacy support. Get database is depreciated and will be
* removed.
* NOTE: Persistance connection is not supported nor needed with Doctrine.
* XOOPS_DB_PCONNECT is ignored.
*
*
* @static
* @staticvar XoopsDatabase The only instance of database class
*
* @return XoopsDatabase Reference to the only instance of database class
*/
public static function getDatabaseConnection($retLegacy = false)
public static function getDatabaseConnection()
{
static $legacy;
$file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php';
Expand All @@ -70,16 +66,7 @@ public static function getDatabaseConnection($retLegacy = false)
if (is_null($legacy->conn)) {
trigger_error('notrace:Unable to connect to database', E_USER_ERROR);
}
// Following lines are temporary as mentioned in note 2.
if ($retLegacy) {
return $legacy;
} else {
//Will remove next 3 lines once included in proper location.
global $xoopsDB; // Legacy support
$GLOBALS['xoopsDB'] =& $xoopsDB;
$xoopsDB = $legacy;
return $legacy->conn;
}
return $legacy;
}


Expand All @@ -106,16 +93,17 @@ public static function getConnection($options = null)
if (!isset($instance)) {
$config = new \Doctrine\DBAL\Configuration();
$config->setSQLLogger(new XoopsDebugStack());
$driver = 'pdo_' . XOOPS_DB_TYPE;
$connectionParams = array(
'dbname' => XOOPS_DB_NAME,
'user' => XOOPS_DB_USER,
'password' => XOOPS_DB_PASS,
'host' => XOOPS_DB_HOST,
'charset' => XOOPS_DB_CHARSET,
'driver' => 'pdo_' . XOOPS_DB_TYPE,
'driver' => $driver,
'wrapperClass' => 'XoopsConnection',
);
// Support for all of doctrine connector
// Support for other doctrine databases
if (defined('XOOPS_DB_PORT')){
$connectionParams['port'] = XOOPS_DB_PORT;
}
Expand Down
5 changes: 5 additions & 0 deletions htdocs/include/common.php
Expand Up @@ -25,6 +25,9 @@
global $xoops;
$GLOBALS['xoops'] =& $xoops;

//Legacy support
global $xoopsDB;
$GLOBALS['xoopsDB'] =& $xoopsDB;
/**
* YOU SHOULD NEVER USE THE FOLLOWING TO CONSTANTS, THEY WILL BE REMOVED
*/
Expand Down Expand Up @@ -95,6 +98,8 @@
* Requires XOOPS_DB_PROXY;
*/
$xoops->db();
//For Legacy support
$xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(true);
/**
* Get xoops configs
* Requires functions and database loaded
Expand Down
1 change: 1 addition & 0 deletions htdocs/modules/page/class/plugin/search.php
Expand Up @@ -26,6 +26,7 @@ class PageSearchPlugin extends Xoops_Module_Plugin_Abstract implements SearchPlu
public function search($queries, $andor, $limit, $start, $uid)
{
$xoops = Xoops::getInstance();
global $xoopsDB;
$sql = "SELECT content_id, content_title, content_shorttext, content_text, content_author, content_create FROM " . $xoopsDB->prefix("page_content") . " WHERE content_status != 0";

if ( $uid != 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/xoops_lib/Xmf/Module/Helper/GenericHelper.php
Expand Up @@ -220,7 +220,7 @@ private function _initHandler($name)
$class = ucfirst(strtolower($this->dirname))
. ucfirst(strtolower($name)) . 'Handler';
if (class_exists($class)) {
$db = \XoopsDatabaseFactory::getDatabaseConnection();
$db = \XoopsDatabaseFactory::getConnection();
$this->_handlers[$name] = new $class($db);
$this->addLog("Loading class '{$class}'");
} else {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/xoops_lib/Xmf/Module/Permission.php
Expand Up @@ -67,7 +67,7 @@ public function init()
}
$this->mid = $this->module->getVar('mid');
$this->dirname = $this->module->getVar('dirname');
$this->db = \XoopsDatabaseFactory::getDatabaseConnection();
$this->db = \XoopsDatabaseFactory::getConnection();
$this->perm = new \XoopsGroupPermHandler($this->db);
if (class_exists('Xoops', false)) {
$this->xoops = \Xoops::getInstance();
Expand Down
6 changes: 5 additions & 1 deletion htdocs/xoops_lib/Xoops.php
Expand Up @@ -118,6 +118,7 @@ class Xoops
*/
private $_db;


/**
* Actual Xoops OS
*/
Expand All @@ -134,6 +135,8 @@ private function __construct()
$this->pathTranslation();

$this->_db = $this->db();


}

/**
Expand All @@ -154,10 +157,11 @@ static public function getInstance()

/**
* @return XoopsConnection
* @todo remove legacy database lines
*/
public function db()
{
return XoopsDatabaseFactory::getDatabaseConnection();
return XoopsDatabaseFactory::getConnection();
}

/**
Expand Down

0 comments on commit dd887a4

Please sign in to comment.