1

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

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);
}
| improve this answer | |
  • 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. – Adam Jan 19 '16 at 1:05
1

As you have found out, the hook civicrm_config is just the way to do that :-)

| improve this answer | |
0

Module available: https://github.com/adam-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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.