Commit 348754d5 authored by totten's avatar totten

CRM-16373 - Config - Migrate `userFrameworkUsersTableName` to settings

There was some code to initialize this field on Joomla and WordPress, but it
appears to be pointless -- the value is only used within the Drupal UF.
More generally, this is a good thing - we should use CMS API's rather than
peeking into their schema.
parent b8feed6e
......@@ -48,14 +48,17 @@ class CRM_Admin_Form_Setting_UF extends CRM_Admin_Form_Setting {
$this->_uf = $config->userFramework;
if ($this->_uf == 'WordPress') {
$this->_settings = array('wpBasePage' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME);
$this->_settings['wpBasePage'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
}
CRM_Utils_System::setTitle(
ts('Settings - %1 Integration', array(1 => $this->_uf))
);
$this->addElement('text', 'userFrameworkUsersTableName', ts('%1 Users Table Name', array(1 => $this->_uf)));
if ($config->userSystem->is_drupal) {
$this->_settings['userFrameworkUsersTableName'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
}
// find out if drupal has its database prefixed
global $databases;
$drupal_prefix = '';
......
......@@ -303,18 +303,6 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
else {
$this->cleanURL = 0;
}
if ($userFramework == 'Joomla') {
/** @var object|null $mainframe */
global $mainframe;
$dbprefix = $mainframe ? $mainframe->getCfg('dbprefix') : 'jos_';
$this->userFrameworkUsersTableName = $dbprefix . 'users';
}
elseif ($userFramework == 'WordPress') {
global $wpdb;
$dbprefix = $wpdb ? $wpdb->prefix : '';
$this->userFrameworkUsersTableName = $dbprefix . 'users';
}
}
/**
......
......@@ -225,7 +225,6 @@ class CRM_Core_Config_Variables extends CRM_Core_Config_Defaults {
* Default user framework. This basically makes Drupal 7 the default
*/
public $userFramework = 'Drupal';
public $userFrameworkUsersTableName = 'users';
public $userFrameworkClass = 'CRM_Utils_System_Drupal';
public $userHookClass = 'CRM_Utils_Hook_Drupal';
......
......@@ -299,6 +299,14 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase {
$base_url = str_replace('http://', 'https://', $base_url);
}
protected function getUsersTableName() {
$userFrameworkUsersTableName = Civi::settings()->get('userFrameworkUsersTableName');
if (empty($userFrameworkUsersTableName)) {
$userFrameworkUsersTableName = 'users';
}
return $userFrameworkUsersTableName;
}
/**
* @inheritDoc
*/
......@@ -340,9 +348,10 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase {
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$name = $dbDrupal->escapeSimple($strtolower($name));
$userFrameworkUsersTableName = $this->getUsersTableName();
$sql = "
SELECT u.*
FROM {$config->userFrameworkUsersTableName} u
FROM {$userFrameworkUsersTableName} u
WHERE LOWER(u.name) = '$name'
AND u.status = 1
";
......
......@@ -310,7 +310,8 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase {
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$dbpassword = md5($password);
$name = $dbDrupal->escapeSimple($strtolower($name));
$sql = 'SELECT u.* FROM ' . $config->userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '$name' AND u.pass = '$dbpassword' AND u.status = 1";
$userFrameworkUsersTableName = $this->getUsersTableName();
$sql = 'SELECT u.* FROM ' . $userFrameworkUsersTableName . " u WHERE LOWER(u.name) = '$name' AND u.pass = '$dbpassword' AND u.status = 1";
$query = $dbDrupal->query($sql);
$user = NULL;
......
......@@ -738,6 +738,25 @@ return array(
'CRM_Logging_Schema::onToggle',
),
),
'userFrameworkUsersTableName' => array(
'add' => '4.7',
'help_text' => NULL,
'is_domain' => 1,
'is_contact' => 0,
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'userFrameworkUsersTableName',
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'html_attributes' => array(
'size' => '32',
'maxlength' => '64',
),
'default' => NULL,
'title' => 'Drupal Users Table Name',
'description' => '',
),
'wpLoadPhp' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment