CRM-20600 - AssetBuiler - Add separate setting, `assetCache`
authorTim Otten <totten@civicrm.org>
Sat, 17 Jun 2017 05:16:15 +0000 (22:16 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 17 Jun 2017 05:16:15 +0000 (22:16 -0700)
The default value (`auto`) behaves the same as the current behavior: enable
caching in production mode, disable caching in debug mode.

But it also allows you to enable/disable caching independent of the
prod/debug mode.

CRM/Admin/Form/Setting/Debugging.php
Civi/Core/AssetBuilder.php
settings/Developer.setting.php
templates/CRM/Admin/Form/Setting/Debugging.tpl

index 528c120f74d5b5c77285d2e2c3915c1802e61455..b254b893eebeb1e0eee60058b74881a14d17c4c3 100644 (file)
@@ -40,6 +40,7 @@ class CRM_Admin_Form_Setting_Debugging extends CRM_Admin_Form_Setting {
     'debug_enabled' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
     'backtrace' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
     'fatalErrorHandler' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
+    'assetCache' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
   );
 
   /**
index f213e7a00d2986a457d56f581b9b2a86c2a1eb10..5c3c8263b072478e22200b67f57ee5c8862484da 100644 (file)
@@ -72,6 +72,18 @@ use Civi\Core\Exception\UnknownAssetException;
  */
 class AssetBuilder {
 
+  /**
+   * @return array
+   *   Array(string $value => string $label).
+   */
+  public static function getCacheModes() {
+    return array(
+      '0' => ts('Disable'),
+      '1' => ts('Enable'),
+      'auto' => ts('Auto'),
+    );
+  }
+
   protected $cacheEnabled;
 
   /**
@@ -80,7 +92,11 @@ class AssetBuilder {
    */
   public function __construct($cacheEnabled = NULL) {
     if ($cacheEnabled === NULL) {
-      $cacheEnabled = !\CRM_Core_Config::singleton()->debug;
+      $cacheEnabled = \Civi::settings()->get('assetCache');
+      if ($cacheEnabled === 'auto') {
+        $cacheEnabled = !\CRM_Core_Config::singleton()->debug;
+      }
+      $cacheEnabled = (bool) $cacheEnabled;
     }
     $this->cacheEnabled = $cacheEnabled;
   }
index 25042360f519440ad4d4884044482f2bc74c0ef6..3d7715e0893a042d0ca193b26214c3407efd73ac 100644 (file)
  */
 
 return array(
+  'assetCache' => array(
+    'group_name' => 'Developer Preferences',
+    'group' => 'developer',
+    'name' => 'assetCache',
+    'type' => 'String',
+    'quick_form_type' => 'Select',
+    'html_type' => 'Select',
+    'html_attributes' => array(
+      //'class' => 'crm-select2',
+    ),
+    'default' => 'auto',
+    'add' => '4.7',
+    'title' => 'Asset Caching',
+    'is_domain' => 1,
+    'is_contact' => 0,
+    'description' => 'Store computed JS/CSS content in cache files? (Note: In "Auto" mode, the "Debug" setting will determine whether to activate the cache.)',
+    'help_text' => NULL,
+    'pseudoconstant' => array(
+      'callback' => '\Civi\Core\AssetBuilder::getCacheModes',
+    ),
+  ),
   'userFrameworkLogging' => array(
     'group_name' => 'Developer Preferences',
     'group' => 'developer',
index d62b8556a0de56e0b209d32e117790f115840310..02f65c2101eb6a2de43f264876de70c60f7b52ed 100644 (file)
                 <td>{$form.fatalErrorHandler.html}<br />
                 <span class="description">{ts}Enter the path and class for a custom PHP error-handling function if you want to override built-in CiviCRM error handling for your site.{/ts}</span></td>
             </tr>
+            <tr class="crm-debugging-form-block-assetCache">
+                <td class="label">{$form.assetCache.label}</td>
+                <td>{$form.assetCache.html}<br />
+                <span class="description">{ts}Store computed JS/CSS content in cache files? (Note: In "Auto" mode, the "Debug" setting will determine whether to activate the cache.){/ts}</span></td>
+            </tr>
         </table>
         <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 <div class="spacer"></div>