Skip to content

Commit

Permalink
We should be able to support multiple databases by using SMF’s databa…
Browse files Browse the repository at this point in the history
…se layer. At this time Postgresql is untested

Signed-off-by: jdarwood007 <unmonitored+github@sleepycode.com>
  • Loading branch information
jdarwood007 committed Apr 29, 2017
1 parent f096e19 commit 57d27f8
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions Auth_SMF.php
Expand Up @@ -112,6 +112,8 @@
$smf_settings['db_passwd'] = $db_passwd;
$smf_settings['db_prefix'] = $db_prefix;
$smf_settings['debug_wiki'] = $wgSMFDebug;
$smf_settings['sourcedir'] = $sourcedir;
$smf_settings['db_type'] = $db_type;

/**
* Check the SMF cookie and automatically log the user into the wiki.
Expand Down Expand Up @@ -977,25 +979,25 @@ public function isGroupAllowed($username, &$user)
*/
public function connect()
{
global $smf_settings;
global $smf_settings, $smcFunc;

// Connect to database.
$this->conn = @mysql_pconnect($smf_settings['db_server'], $smf_settings['db_user'],
$smf_settings['db_passwd'], true);
$db_type = !empty($smf_settings['db_type']) && file_exists($smf_settings['sourcedir'] . '/Subs-Db-' . $smf_settings['db_type'] . '.php') ? $smf_settings['db_type'] : 'mysql';

// Check if we are connected to the database.
if (!$this->conn)
$this->mysqlerror("SMF was unable to connect to the database.<br />\n");
if (!defined('SMF'))
define('SMF', 'WIKI');
if (!isset($smcFunc))
$smcFunc = array();

// Select database: this assumes the wiki and smf are in the same database.
$db_selected = @mysql_select_db($smf_settings['db_name'], $this->conn);
require_once($smf_settings['sourcedir'] . '/Subs-Db-' . $smf_settings['db_type'] . '.php');

// Check if we were able to select the database.
if (!$db_selected)
$this->mysqlerror("SMF was unable to connect to the database.<br />\n");
$this->conn = smf_db_initiate($smf_settings['db_server'], $smf_settings['db_name'], $smf_settings['db_user'], $smf_settings['db_passwd'], $smf_settings['db_prefix']);

// As of now, we don't suport anything other than UTF8 with SMF.
mysql_query('SET NAMES UTF8', $this->conn);
$smcFunc['db_query']('set_character_set', '
SET NAMES UTF8',
array(
)
);
}

/**
Expand All @@ -1006,7 +1008,7 @@ public function connect()
*/
public function query($query)
{
$request = mysql_query($query, $this->conn);
$request = $smcFunc['db_query']('', $query, array(), $this->conn);

if(!$request)
$this->mysqlerror('Unable to view external table.');
Expand Down Expand Up @@ -1059,3 +1061,25 @@ function wfProfileSMFID($user, &$saveOptions)

return true;
}

/**
* Because we don't fully load SMF, this doesn't exist, so handle this should an error occur..
*
* @param string $query
* @return resource
*/
if (!function_exists('display_db_error'))
{
function display_db_error()
{
global $wgSMFDebug;

echo $message . "<br /><br />\n\n";

// Only if we are debugging.
if ($wgSMFDebug)
echo 'mySQL error number: ', mysql_errno(), "<br />\n", 'mySQL error message: ', mysql_error(), "<br /><br />\n\n";

exit;
}
}

0 comments on commit 57d27f8

Please sign in to comment.