Merge branch 'MDL-80985-add-purge-course-caches-option-main' of https://github.com/jwcatau/moodle

This commit is contained in:
Andrew Nicols 2024-04-11 10:41:13 +08:00
commit 5c16854483
No known key found for this signature in database
GPG key ID: 6D1E3157C8CFBF14
4 changed files with 204 additions and 1 deletions

View file

@ -1191,7 +1191,7 @@ function purge_all_caches() {
* 'other' Purge all other caches?
*/
function purge_caches($options = []) {
$defaults = array_fill_keys(['muc', 'theme', 'lang', 'js', 'template', 'filter', 'other'], false);
$defaults = array_fill_keys(['muc', 'courses', '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 {
@ -1200,6 +1200,14 @@ function purge_caches($options = []) {
if ($options['muc']) {
cache_helper::purge_all();
}
if ($options['courses']) {
if ($options['courses'] === true) {
$courseids = [];
} else {
$courseids = preg_split('/\s*,\s*/', $options['courses'], -1, PREG_SPLIT_NO_EMPTY);
}
course_modinfo::purge_course_caches($courseids);
}
if ($options['theme']) {
theme_reset_all_caches();
}