MDL-62801 themes: Remove old mustache caches when new one generated

This commit is contained in:
Michael Hawkins 2018-06-27 11:04:33 +08:00
parent f61ee4e857
commit 3f2ed99d26

View File

@ -84,8 +84,20 @@ class renderer_base {
$themename = $this->page->theme->name;
$themerev = theme_get_revision();
// Create new localcache directory.
$cachedir = make_localcache_directory("mustache/$themerev/$themename");
// Remove old localcache directories.
$mustachecachedirs = glob("{$CFG->localcachedir}/mustache/*", GLOB_ONLYDIR);
foreach ($mustachecachedirs as $localcachedir) {
$cachedrev = [];
preg_match("/\/mustache\/([0-9]+)$/", $localcachedir, $cachedrev);
$cachedrev = isset($cachedrev[1]) ? intval($cachedrev[1]) : 0;
if ($cachedrev > 0 && $cachedrev < $themerev) {
fulldelete($localcachedir);
}
}
$loader = new \core\output\mustache_filesystem_loader();
$stringhelper = new \core\output\mustache_string_helper();
$quotehelper = new \core\output\mustache_quote_helper();