From 348754d5baf83293564406b5770f01edf647b74b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 22 Aug 2015 04:29:06 -0700 Subject: [PATCH] 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. --- CRM/Admin/Form/Setting/UF.php | 7 +++++-- CRM/Core/Config.php | 12 ------------ CRM/Core/Config/Variables.php | 1 - CRM/Utils/System/Drupal.php | 11 ++++++++++- CRM/Utils/System/Drupal6.php | 3 ++- settings/Core.setting.php | 19 +++++++++++++++++++ 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/CRM/Admin/Form/Setting/UF.php b/CRM/Admin/Form/Setting/UF.php index 391a071678..760ecf227a 100644 --- a/CRM/Admin/Form/Setting/UF.php +++ b/CRM/Admin/Form/Setting/UF.php @@ -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 = ''; diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 72cb65e72e..c9d54c33fd 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -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'; - } } /** diff --git a/CRM/Core/Config/Variables.php b/CRM/Core/Config/Variables.php index 3514c11965..e94ffad414 100644 --- a/CRM/Core/Config/Variables.php +++ b/CRM/Core/Config/Variables.php @@ -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'; diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index e0543b1959..008b801cba 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -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 "; diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 935f0471e4..c557751d96 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -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; diff --git a/settings/Core.setting.php b/settings/Core.setting.php index f5c47c266a..a81f287158 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -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', -- 2.25.1