From 4459cd26a5612789e2d30404d95583c0c43d34e2 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Sat, 6 Jul 2013 17:15:55 +1200 Subject: [PATCH] Update CRM_Utils_System_Drupal6::loadBootStrap() based on CRM_Utils_System_Drupal::loadBootStrap(). --- CRM/Utils/System/Drupal6.php | 88 ++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 66a2d1999c..81d7565361 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -650,26 +650,43 @@ SELECT name, mail * @param boolean|string $realPath path to script */ function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { - $uid = CRM_Utils_Array::value('uid', $params); - $name = CRM_Utils_Array::value('name', $params, FALSE) ? $params['name'] : trim(CRM_Utils_Array::value('name', $_REQUEST)); - $pass = CRM_Utils_Array::value('pass', $params, FALSE) ? $params['pass'] : trim(CRM_Utils_Array::value('pass', $_REQUEST)); - //take the cms root path. $cmsPath = $this->cmsRootPath($realPath); + if (!file_exists("$cmsPath/includes/bootstrap.inc")) { - echo '
Sorry, unable to locate bootstrap.inc.'; - exit(); + if ($throwError) { + echo '
Sorry, could not locate bootstrap.inc\n'; + exit(); + } + return FALSE; } - + // load drupal bootstrap chdir($cmsPath); + define('DRUPAL_ROOT', $cmsPath); + + // For drupal multi-site CRM-11313 + if ($realPath && strpos($realPath, 'sites/all/modules/') === FALSE) { + preg_match('@sites/([^/]*)/modules@s', $realPath, $matches); + if (!empty($matches[1])) { + $_SERVER['HTTP_HOST'] = $matches[1]; + } + } require_once 'includes/bootstrap.inc'; - @drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + // explicitly setting error reporting, since we cannot handle drupal related notices + error_reporting(1); if (!function_exists('module_exists') || !module_exists('civicrm')) { - echo '
Sorry, could not load drupal bootstrap.'; - exit(); + if ($throwError) { + echo '
Sorry, could not load drupal bootstrap.'; + exit(); + } + return FALSE; } + // seems like we've bootstrapped drupal + $config = CRM_Core_Config::singleton(); + // lets also fix the clean url setting // CRM-6948 $config->cleanURL = (int) variable_get('clean_url', '0'); @@ -683,25 +700,50 @@ SELECT name, mail if (!$loadUser) { return TRUE; } - //load user, we need to check drupal permissions. - if ($name) { - $user = user_authenticate(array('name' => $name, 'pass' => $pass)); - if (empty($user->uid)) { - echo '
Sorry, unrecognized username or password.'; - exit(); + + // If $uid is passed in, authentication has been done already. + $uid = CRM_Utils_Array::value('uid', $params); + if (!$uid) { + //load user, we need to check drupal permissions. + $name = CRM_Utils_Array::value('name', $params, FALSE) ? $params['name'] : trim(CRM_Utils_Array::value('name', $_REQUEST)); + $pass = CRM_Utils_Array::value('pass', $params, FALSE) ? $params['pass'] : trim(CRM_Utils_Array::value('pass', $_REQUEST)); + + if ($name) { + $uid = user_authenticate(array('name' => $name, 'pass' => $pass)); + if (!$uid) { + if ($throwError) { + echo '
Sorry, unrecognized username or password.'; + exit(); + } + return FALSE; + } } } - elseif ($uid) { - $account = user_load(array('uid' => $uid)); - if (empty($account->uid)) { - echo '
Sorry, unrecognized user id.'; - exit(); - } - else { + + if ($uid) { + $account = user_load($uid); + if ($account && $account->uid) { global $user; $user = $account; + return TRUE; } } + + if ($throwError) { + echo '
Sorry, can not load CMS user account.'; + exit(); + } + + // CRM-6948: When using loadBootStrap, it's implicit that CiviCRM has already loaded its settings + // which means that define(CIVICRM_CLEANURL) was correctly set. + // So we correct it + $config = CRM_Core_Config::singleton(); + $config->cleanURL = (int)variable_get('clean_url', '0'); + + // CRM-8655: Drupal wasn't available during bootstrap, so hook_civicrm_config never executes + CRM_Utils_Hook::config($config); + + return FALSE; } /** -- 2.25.1