CRM-15382 - Ensure dynamic resources are rebuilt after flushing
authorColeman Watts <coleman@civicrm.org>
Sat, 27 Sep 2014 23:41:20 +0000 (19:41 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 27 Sep 2014 23:41:20 +0000 (19:41 -0400)
CRM/Admin/Form/WordReplacements.php
CRM/Core/BAO/WordReplacement.php
CRM/Core/Invoke.php
CRM/Core/Resources.php

index 21a1d99c068d588ecb9fddd1b8252b5018325aef..f432dede188839bdf5064df4512cc871ee287ef4 100644 (file)
@@ -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);
index 9da2ebf36a6bcb2872d7553dbcc91c1564a7e4fe..ed023400aaea0a2dbc2079163f51c9d7002747c7 100644 (file)
@@ -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;
     }
index 44936afb146bf8bf10450cde48c3abe86ac3ae89..a1e5f726f99271cbc1c067f70b9cc6632e8c36a6 100644 (file)
@@ -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
index 2bbfcc4711616c835875a8135c94ae4f247afc19..3a49c60fa527a2ef99926ac2f9ce1caa35c9b3af 100644 (file)
@@ -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;
   }
 
   /**