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

File URL when CiviCRM detects Drupal doesn't match the path as set by [civicrm.files]

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 4.7.19
    • Fix Version/s: None
    • Component/s: Core CiviCRM
    • Labels:
      None
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No

      Description

      As I understand it the token

      [civicrm.files]
      

      is generated from the CIVICRM_TEMPLATE_COMPILEDIR constant, which could be any path (e.g. sites/default/files/private/civicrm).

      However, under Drupal at least, CiviCRM hardcodes the URL for that file to be sites/default/files/civicrm. So never the twain shall meet!

      In CRM/Utils/System/Base.php:

      public function getDefaultFileStorage() {
      global $civicrm_root;
      $config = CRM_Core_Config::singleton();
      $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
      
      $filesURL = NULL;
      $filesPath = NULL;
      
      if ($config->userFramework == 'Joomla') {
      // gross hack
      // we need to remove the administrator/ from the end
      $tempURL = str_replace("/administrator/", "/", $baseURL);
      $filesURL = $tempURL . "media/civicrm/";
      }
      elseif ($this->is_drupal) {
      $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
      if ($siteName) {
      $filesURL = $baseURL . "sites/$siteName/files/civicrm/";
      }
      else {
      $filesURL = $baseURL . "sites/default/files/civicrm/";
      }
      }
      elseif ($config->userFramework == 'UnitTests') {
      $filesURL = $baseURL . "sites/default/files/civicrm/";
      }
      else {
      throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
      }
      
      return array(
      'url' => $filesURL,
      'path' => CRM_Utils_File::baseFilePath(),
      );
      }
      

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              herb@freeform Herb
            • Votes:
              3 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: