MDL-82399 admin: allow selective purging of courses cache from UI.

Equivalent to the same functionality in the CLI tool in 5e05ad570f.
This commit is contained in:
Paul Holden 2024-07-05 13:35:09 +01:00
parent bcf06a0484
commit c78793beb3
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
4 changed files with 9 additions and 2 deletions

View File

@ -48,6 +48,7 @@ class purge_caches extends \moodleform {
$mform->addElement('header', 'purgecacheheader', get_string('purgeselectedcaches', 'admin'));
$checkboxes = [
$mform->createElement('advcheckbox', 'theme', '', get_string('purgethemecache', 'admin')),
$mform->createElement('advcheckbox', 'courses', '', get_string('purgecoursecache', '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')),

View File

@ -42,7 +42,11 @@ if ($data = $form->get_data()) {
purge_caches();
$message = get_string('purgecachesfinished', 'admin');
} else {
purge_caches($data->purgeselectedoptions);
// When passing selected options, ensure each is cast to boolean for strict comparison.
purge_caches(array_map(
fn($option) => (bool) $option,
$data->purgeselectedoptions,
));
$message = get_string('purgeselectedcachesfinished', 'admin');
}

View File

@ -1160,6 +1160,7 @@ $string['purgecachesconfirm'] = 'Moodle can cache themes, javascript, language s
$string['purgecachesfinished'] = 'All caches were purged.';
$string['purgecachesnoneselected'] = 'Select one or more caches to purge';
$string['purgecachespage'] = 'Purge caches';
$string['purgecoursecache'] = 'Courses';
$string['purgefiltercache'] = 'Text filters';
$string['purgejscache'] = 'JavaScript';
$string['purgelangcache'] = 'Language strings';

View File

@ -1194,10 +1194,11 @@ function purge_all_caches() {
*
* @param bool[] $options Specific parts of the cache to purge. Valid options are:
* 'muc' Purge MUC caches?
* 'courses' Purge all course caches, or specific course caches (CLI only)
* 'courses' Purge all course caches, or specific course caches
* 'theme' Purge theme cache?
* 'lang' Purge language string cache?
* 'js' Purge javascript cache?
* 'template' Purge template cache
* 'filter' Purge text filter cache?
* 'other' Purge all other caches?
*/