Answers.Body: <p>Module available: <a href="https://github.com/adam-devapp/drupal-pantheon-civicrm-cache-clear/tree/master/civicrm_cache_clear" rel="nofollow">https://github.com/adam-devapp/drupal-pantheon-civicrm-cache-clear/tree/master/civicrm_cache_clear</a></p>
  
  <p>Needed to be in Drupal, as CiviCRM extensions won't work if the path changes underneath them.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-21T10:36:46.100Z
Answers.LastActivityDate: 2016-10-21T10:36:46.100Z
Answers.UserDisplayName: Adam
Answers.Body: <p>I've come up with this function to clear cache, when file paths change.</p>
  
  <pre>
  function cacheoff_civicrm_config(&$config) {
  
    // 1. Get document root from the server
    // 2. Compare to a set path in the cache
    // If 2. doesn't start with 1., then regenerate cache
    // This means the file path has changed
  
    $templateDir = $config->customTemplateDir;
    $document_root = $_SERVER['DOCUMENT_ROOT'];
  
    if (!substr($templateDir, 0, strlen($document_root)) === $document_root) {
  
      CRM_Core_Error::debug( "Path changed: " . $document_root . " doesn't match " . $templateDir ); 
      CRM_Core_Config::clearDBCache();
  
    }
    _cacheoff_civix_civicrm_config($config);
  }
  </pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-19T01:05:47.233Z
Answers.Text: I've found that this doesn't fix the problem (CiviCRM 4.4). The module path is cached, so the hook never gets run. Looking at a solution on the latest CiviCRM 4.6.11 now.
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-12T07:01:04.393Z
Answers.LastActivityDate: 2016-01-12T07:01:04.393Z
Answers.UserDisplayName: Adam
Answers.Body: <p>As you have found out, the hook civicrm_config is just the way to do that :-)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-12T10:42:27.923Z
Answers.LastActivityDate: 2016-01-12T10:42:27.923Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>What is the best way to override changes to CRM_Core_Config without modifying the original. Have tried through inheritance, but generates the following code:</p>
  
  <blockquote>
    <p>Fatal error: Cannot redeclare class CRM_Core_Config ....../code/sites/all/civiphp/CRM/Core/Config.php on line 854</p>
  </blockquote>
  
  <p>It isn't possible to dynamically load and unload the class, so I was thinking of writing a module which modifies the object after it has loaded via a hook. At least this would survive upgrades.</p>
  
  <p>• <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config</a></p>
  
Tags: <configuration>
Title: What is the best way to override changes to CRM_Core_Config?
ThreadText: # What is the best way to override changes to CRM_Core_Config?
  
  (Asked by: username_0 on 2016-01-12)
  
  What is the best way to override changes to CRM\_Core\_Config without modifying the original. Have tried through inheritance, but generates the following code:
  
  > Fatal error: Cannot redeclare class CRM\_Core\_Config ....../code/sites/all/civiphp/CRM/Core/Config.php on line 854
  
  It isn't possible to dynamically load and unload the class, so I was thinking of writing a module which modifies the object after it has loaded via a hook. At least this would survive upgrades.
  
  • <http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config>
  
  **Tags:** configuration
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2016-10-21. Score: 0 | Accepted answer
  
  Module available: <https://github.com/username_0-devapp/drupal-pantheon-civicrm-cache-clear/tree/master/civicrm_cache_clear>
  
  Needed to be in Drupal, as CiviCRM extensions won't work if the path changes underneath them.
  
  
  ---
  
  ### Answer by username_0 on 2016-01-12. Score: 1
  
  I've come up with this function to clear cache, when file paths change.
  
  ```
  
  function cacheoff_civicrm_config(&$config) {
  
    // 1. Get document root from the server
    // 2. Compare to a set path in the cache
    // If 2. doesn't start with 1., then regenerate cache
    // This means the file path has changed
  
    $templateDir = $config->customTemplateDir;
    $document_root = $_SERVER['DOCUMENT_ROOT'];
  
    if (!substr($templateDir, 0, strlen($document_root)) === $document_root) {
  
      CRM_Core_Error::debug( "Path changed: " . $document_root . " doesn't match " . $templateDir ); 
      CRM_Core_Config::clearDBCache();
  
    }
    _cacheoff_civix_civicrm_config($config);
  }
  
  ```
  
  > **Comments:**
  > **username_0**: I've found that this doesn't fix the problem (CiviCRM 4.4). The module path is cached, so the hook never gets run. Looking at a solution on the latest CiviCRM 4.6.11 now.  
  
  ---
  
  ### Answer by username_1 on 2016-01-12. Score: 1
  
  As you have found out, the hook civicrm\_config is just the way to do that :-)
  
  
  ---
  
  