From 9762f6ffa3d2d182eccc7efdabcd9ff35b73cc7e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 27 Sep 2014 19:41:20 -0400 Subject: [PATCH] CRM-15382 - Ensure dynamic resources are rebuilt after flushing --- CRM/Admin/Form/WordReplacements.php | 2 +- CRM/Core/BAO/WordReplacement.php | 15 ++++++++------- CRM/Core/Invoke.php | 10 ++++------ CRM/Core/Resources.php | 12 ++++++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CRM/Admin/Form/WordReplacements.php b/CRM/Admin/Form/WordReplacements.php index 21a1d99c06..f432dede18 100644 --- a/CRM/Admin/Form/WordReplacements.php +++ b/CRM/Admin/Form/WordReplacements.php @@ -44,7 +44,7 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { // but that's no longer the canonical store. Re-sync from canonical store to ensure // that we display that latest data. This is inefficient - at some point, we // should rewrite this UI. - CRM_Core_BAO_WordReplacement::rebuild(); + CRM_Core_BAO_WordReplacement::rebuild(FALSE); $this->_soInstance = CRM_Utils_Array::value('instance', $_GET); $this->assign('soInstance', $this->_soInstance); diff --git a/CRM/Core/BAO/WordReplacement.php b/CRM/Core/BAO/WordReplacement.php index 9da2ebf36a..ed023400aa 100644 --- a/CRM/Core/BAO/WordReplacement.php +++ b/CRM/Core/BAO/WordReplacement.php @@ -195,7 +195,7 @@ WHERE domain_id = %1 /** * Rebuild */ - static function rebuild() { + static function rebuild($clearCaches = TRUE) { $id = CRM_Core_Config::domainID(); $stringOverride = self::getAllAsConfigArray($id); $params = array('locale_custom_strings' => serialize($stringOverride)); @@ -203,12 +203,13 @@ WHERE domain_id = %1 if ($wordReplacementSettings) { CRM_Core_Config::singleton()->localeCustomStrings = $stringOverride; - // Reset navigation - CRM_Core_BAO_Navigation::resetNavigation(); - // Clear js string cache - CRM_Core_Resources::singleton()->flushStrings(); - // Clear dynamic js files which may contain localization - CRM_Utils_File::flushDynamicResources(); + // Partially mitigate the inefficiency introduced in CRM-13187 by doing this conditionally + if ($clearCaches) { + // Reset navigation + CRM_Core_BAO_Navigation::resetNavigation(); + // Clear js localization + CRM_Core_Resources::singleton()->flushStrings()->rebuildDynamicResources(); + } return TRUE; } diff --git a/CRM/Core/Invoke.php b/CRM/Core/Invoke.php index 44936afb14..a1e5f726f9 100644 --- a/CRM/Core/Invoke.php +++ b/CRM/Core/Invoke.php @@ -399,14 +399,12 @@ class CRM_Core_Invoke { // also cleanup module permissions $config->cleanupPermissions(); - // also rebuild word replacement cache - CRM_Core_BAO_WordReplacement::rebuild(); - - // Clear dynamic js files - CRM_Utils_File::flushDynamicResources(); + // rebuild word replacement cache - pass false to prevent operations redundant with this fn + CRM_Core_BAO_WordReplacement::rebuild(FALSE); CRM_Core_BAO_Setting::updateSettingsFromMetaData(); - CRM_Core_Resources::singleton()->resetCacheCode(); + // Clear js caches + CRM_Core_Resources::singleton()->flushStrings()->rebuildDynamicResources(); CRM_Case_XMLRepository::singleton(TRUE); // also rebuild triggers if requested explicitly diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 2bbfcc4711..3a49c60fa5 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -432,12 +432,14 @@ class CRM_Core_Resources { if ($this->cacheCodeKey) { CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, $this->cacheCodeKey); } + return $this; } public function resetCacheCode() { $this->setCacheCode(CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC)); // Also flush cms resource cache if needed CRM_Core_Config::singleton()->userSystem->clearResourceCache(); + return $this; } /** @@ -521,6 +523,16 @@ class CRM_Core_Resources { */ public function flushStrings() { $this->cache->flush(); + return $this; + } + + /** + * Deletes and rebuilds dynamic resource files + */ + public function rebuildDynamicResources() { + CRM_Utils_File::flushDynamicResources(); + $this->addLocalizationJs(); + return $this; } /** -- 2.25.1