Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-17443

On Drupal, global $base_url not set during a REST call

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Incomplete
    • Affects Version/s: 4.4.13
    • Fix Version/s: None
    • Component/s: CiviCRM API
    • Labels:
      None
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      May be related to CRM-17413 in that it concerns the REST bootstrap procedure.

      I have a custom API function that does some Drupal-specific stuff, including the use of the url() function. I noticed that this was returning URLs without a base, even with the "absolute" option. (It works when called from drush.) I then found this was because the global $base_url was not set (or was empty).

      Further debugging:
      This variable is normally initialised in drupal_settings_initialize() in Drupal's includes/bootstrap.inc. This contains a line

      if (isset($base_url)) {
      

      which, if I changed the isset to !empty, caused a base path to be set. Something similar is achieved by inserting

      if (empty($GLOBALS['base_url'])) {
        unset($GLOBALS['base_url']);
      }
      

      before the drupal_bootstrap line in CRM_Utils_System_Drupal.

      However, this still isn't right: a spurious /sites/all/modules/civicrm/extern is inserted that doesn't appear with drush. This is fixed with

      unset($_SERVER['SCRIPT_NAME']);
      

      (before CRM_Utils_System::loadBootStrap in CRM_Utils_REST) as the path from that variable is also used by drupal_settings_initialize to construct the base_url. I then get the paths I want out of url().

      These changes feel like a bit of a hack though.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              DaveFF David Knoll
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: