mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
Merge branch 'w28_MDL-34057_m24_styledebug' of git://github.com/skodak/moodle
This commit is contained in:
commit
e977b391b7
1 changed files with 28 additions and 20 deletions
|
@ -626,30 +626,38 @@ class theme_config {
|
||||||
if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
|
if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) {
|
||||||
define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
|
define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php
|
||||||
}
|
}
|
||||||
// Prepare the CSS optimiser if it is to be used
|
$candidatedir = "$CFG->cachedir/theme/$this->name";
|
||||||
$optimiser = null;
|
$candidatesheet = "$candidatedir/designer.ser";
|
||||||
$candidatesheet = "$CFG->cachedir/theme/$this->name/designer.ser";
|
$rebuild = true;
|
||||||
if (!empty($CFG->enablecssoptimiser) && $this->supportscssoptimisation) {
|
if (file_exists($candidatesheet) and filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
|
||||||
require_once($CFG->dirroot.'/lib/csslib.php');
|
|
||||||
$optimiser = new css_optimiser;
|
|
||||||
}
|
|
||||||
if (!file_exists($candidatesheet)) {
|
|
||||||
$css = $this->css_content($optimiser);
|
|
||||||
check_dir_exists(dirname($candidatesheet));
|
|
||||||
file_put_contents($candidatesheet, serialize($css));
|
|
||||||
|
|
||||||
} else if (filemtime($candidatesheet) > time() - THEME_DESIGNER_CACHE_LIFETIME) {
|
|
||||||
if ($css = file_get_contents($candidatesheet)) {
|
if ($css = file_get_contents($candidatesheet)) {
|
||||||
$css = unserialize($css);
|
$css = unserialize($css);
|
||||||
} else {
|
if (is_array($css)) {
|
||||||
unlink($candidatesheet);
|
$rebuild = false;
|
||||||
$css = $this->css_content($optimiser);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($rebuild) {
|
||||||
|
// Prepare the CSS optimiser if it is to be used,
|
||||||
|
// please note that it may be very slow and is therefore strongly discouraged in theme designer mode.
|
||||||
|
$optimiser = null;
|
||||||
|
if (!empty($CFG->enablecssoptimiser) && $this->supportscssoptimisation) {
|
||||||
|
require_once($CFG->dirroot.'/lib/csslib.php');
|
||||||
|
$optimiser = new css_optimiser;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
unlink($candidatesheet);
|
|
||||||
$css = $this->css_content($optimiser);
|
$css = $this->css_content($optimiser);
|
||||||
file_put_contents($candidatesheet, serialize($css));
|
|
||||||
|
// We do not want any errors here because this may fail easily because of the concurrent access.
|
||||||
|
$prevabort = ignore_user_abort(true);
|
||||||
|
check_dir_exists($candidatedir);
|
||||||
|
$tempfile = tempnam($candidatedir, 'tmpdesigner');
|
||||||
|
file_put_contents($tempfile, serialize($css));
|
||||||
|
$reporting = error_reporting(0);
|
||||||
|
chmod($tempfile, $CFG->filepermissions);
|
||||||
|
unlink($candidatesheet); // Do not rely on rename() deleting original, they may decide to change it at any time as usually.
|
||||||
|
rename($tempfile, $candidatesheet);
|
||||||
|
error_reporting($reporting);
|
||||||
|
ignore_user_abort($prevabort);
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseurl = $CFG->httpswwwroot.'/theme/styles_debug.php';
|
$baseurl = $CFG->httpswwwroot.'/theme/styles_debug.php';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue