Commit e7b8261d authored by totten's avatar totten

CRM-20600 - AssetBuiler - Add separate setting, `assetCache`

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.
parent b20ea913
......@@ -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,
);
/**
......
......@@ -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;
}
......
......@@ -37,6 +37,27 @@
*/
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',
......
......@@ -51,6 +51,11 @@
<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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment