mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-66367 core: added templaterev variable
This commit is contained in:
parent
5beb388516
commit
e63395bbed
@ -50,6 +50,7 @@ class purge_caches extends \moodleform {
|
||||
$mform->createElement('advcheckbox', 'theme', '', get_string('purgethemecache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'lang', '', get_string('purgelangcache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'js', '', get_string('purgejscache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'template', '', get_string('purgetemplates', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'filter', '', get_string('purgefiltercache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'muc', '', get_string('purgemuc', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'other', '', get_string('purgeothercaches', 'admin'))
|
||||
|
@ -277,6 +277,7 @@ preferences,moodle|/user/preferences.php|t/preferences',
|
||||
|
||||
$setting = new admin_setting_configcheckbox('cachetemplates', new lang_string('cachetemplates', 'admin'),
|
||||
new lang_string('cachetemplates_help', 'admin'), 1);
|
||||
$setting->set_updatedcallback('template_reset_all_caches');
|
||||
$temp = new admin_settingpage('templates', new lang_string('templates', 'admin'));
|
||||
$temp->add($setting);
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
@ -1043,6 +1043,7 @@ $string['purgemuc'] = 'All MUC caches';
|
||||
$string['purgeothercaches'] = 'All file and miscellaneous caches';
|
||||
$string['purgeselectedcaches'] = 'Purge selected caches';
|
||||
$string['purgeselectedcachesfinished'] = 'The selected caches were purged.';
|
||||
$string['purgetemplates'] = 'Templates';
|
||||
$string['purgethemecache'] = 'Themes';
|
||||
$string['requestcategoryselection'] = 'Enable category selection';
|
||||
$string['restorecourse'] = 'Restore course';
|
||||
|
@ -284,9 +284,10 @@ function xmldb_main_install() {
|
||||
set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
|
||||
set_role_contextlevels($userrole, get_default_contextlevels('user'));
|
||||
|
||||
// Init theme and JS revisions
|
||||
// Init theme, JS and template revisions.
|
||||
set_config('themerev', time());
|
||||
set_config('jsrev', time());
|
||||
set_config('templaterev', time());
|
||||
|
||||
// No admin setting for this any more, GD is now required, remove in Moodle 2.6.
|
||||
set_config('gdversion', 2);
|
||||
|
@ -1648,7 +1648,7 @@ function purge_all_caches() {
|
||||
* 'other' Purge all other caches?
|
||||
*/
|
||||
function purge_caches($options = []) {
|
||||
$defaults = array_fill_keys(['muc', 'theme', 'lang', 'js', 'filter', 'other'], false);
|
||||
$defaults = array_fill_keys(['muc', 'theme', 'lang', 'js', 'template', 'filter', 'other'], false);
|
||||
if (empty(array_filter($options))) {
|
||||
$options = array_fill_keys(array_keys($defaults), true); // Set all options to true.
|
||||
} else {
|
||||
@ -1666,6 +1666,9 @@ function purge_caches($options = []) {
|
||||
if ($options['js']) {
|
||||
js_reset_all_caches();
|
||||
}
|
||||
if ($options['template']) {
|
||||
template_reset_all_caches();
|
||||
}
|
||||
if ($options['filter']) {
|
||||
reset_text_filters_cache();
|
||||
}
|
||||
|
@ -413,6 +413,25 @@ class page_requirements_manager {
|
||||
return $jsrev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the correct Template revision to use for this load.
|
||||
*
|
||||
* @return int the templaterev to use.
|
||||
*/
|
||||
protected function get_templaterev() {
|
||||
global $CFG;
|
||||
|
||||
if (empty($CFG->cachetemplates)) {
|
||||
$templaterev = -1;
|
||||
} else if (empty($CFG->templaterev)) {
|
||||
$templaterev = 1;
|
||||
} else {
|
||||
$templaterev = $CFG->templaterev;
|
||||
}
|
||||
|
||||
return $templaterev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the specified JavaScript file is linked to from this page.
|
||||
*
|
||||
@ -2104,6 +2123,23 @@ class YUI_config {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate all server and client side template caches.
|
||||
*/
|
||||
function template_reset_all_caches() {
|
||||
global $CFG;
|
||||
|
||||
$next = time();
|
||||
if (isset($CFG->templaterev) and $next <= $CFG->templaterev and $CFG->templaterev - $next < 60 * 60) {
|
||||
// This resolves problems when reset is requested repeatedly within 1s,
|
||||
// the < 1h condition prevents accidental switching to future dates
|
||||
// because we might not recover from it.
|
||||
$next = $CFG->templaterev + 1;
|
||||
}
|
||||
|
||||
set_config('templaterev', $next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate all server and client side JS caches.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user