From: Tim Otten Date: Tue, 9 Feb 2016 23:52:48 +0000 (-0800) Subject: CRM-17957 - Extension classloader - Reset whenever the mapper resets X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=85c7eb6797b7d58ccaed2cbd566317f11cec0ae0;p=civicrm-core.git CRM-17957 - Extension classloader - Reset whenever the mapper resets --- diff --git a/CRM/Extension/ClassLoader.php b/CRM/Extension/ClassLoader.php index 7097d8d371..2485cae3cb 100644 --- a/CRM/Extension/ClassLoader.php +++ b/CRM/Extension/ClassLoader.php @@ -68,10 +68,7 @@ class CRM_Extension_ClassLoader { } public function __destruct() { - if ($this->loader) { - $this->loader->unregister(); - $this->loader = NULL; - } + $this->unregister(); } /** @@ -80,12 +77,11 @@ class CRM_Extension_ClassLoader { */ public function register() { // In pre-installation environments, don't bother with caching. - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || \CRM_Utils_System::isInUpgradeMode()) { + if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { return $this->buildClassLoader()->register(); } - $envId = \CRM_Core_Config_Runtime::getId(); - $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedExtLoader.{$envId}.php"; + $file = $this->getCacheFile(); if (file_exists($file)) { $loader = require $file; } @@ -129,4 +125,29 @@ class CRM_Extension_ClassLoader { return $loader; } + public function unregister() { + if ($this->loader) { + $this->loader->unregister(); + $this->loader = NULL; + } + } + + public function refresh() { + $this->unregister(); + $file = $this->getCacheFile(); + if (file_exists($file)) { + unlink($file); + } + $this->register(); + } + + /** + * @return string + */ + protected function getCacheFile() { + $envId = \CRM_Core_Config_Runtime::getId(); + $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedExtLoader.{$envId}.php"; + return $file; + } + } diff --git a/CRM/Extension/Mapper.php b/CRM/Extension/Mapper.php index 9c99b8a762..b08c6f636c 100644 --- a/CRM/Extension/Mapper.php +++ b/CRM/Extension/Mapper.php @@ -415,6 +415,8 @@ class CRM_Extension_Mapper { if ($this->cache) { $this->cache->delete($this->cacheKey . '/moduleFiles'); } + // FIXME: How can code so code wrong be so right? + CRM_Extension_System::singleton()->getClassLoader()->refresh(); } }