MDL-53695 lib/javascript.php: ensure full env for core_minify
This applies the same approach to generating minified js as is already used in theme/javascript.php and other scripts. When we need to do the minification, we load the full Moodle environment, so we can use the libraries. The reason this was required was because now the minifier uses autoloaded classes, which are not autoloaded when doing ABORT_AFTER_CONFIG. Fred persuaded me that it's probably safer to keep it that way, rather than alllow ABORT_AFTER_CONFIG scripts from autoloading the world and their dog (especially for resource serving scripts, they are intended to be lightweight when serving from cache).
This commit is contained in:
+9
-1
@@ -30,7 +30,6 @@ define('NO_DEBUG_DISPLAY', true);
|
||||
define('ABORT_AFTER_CONFIG', true);
|
||||
require('../config.php'); // this stops immediately at the beginning of lib/setup.php
|
||||
require_once("$CFG->dirroot/lib/jslib.php");
|
||||
require_once("$CFG->dirroot/lib/classes/minify.php");
|
||||
|
||||
if ($slashargument = min_get_slash_argument()) {
|
||||
$slashargument = ltrim($slashargument, '/');
|
||||
@@ -93,6 +92,15 @@ if ($rev > 0 and $rev < (time() + 60*60)) {
|
||||
js_send_cached($candidate, $etag);
|
||||
|
||||
} else {
|
||||
// The JS needs minfifying, so we're gonna have to load our full Moodle
|
||||
// environment to process it..
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
|
||||
define('NO_MOODLE_COOKIES', true); // Session not used here.
|
||||
define('NO_UPGRADE_CHECK', true); // Ignore upgrade check.
|
||||
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
js_write_cache_file_content($candidate, core_minify::js_files($jsfiles));
|
||||
// verify nothing failed in cache file creation
|
||||
clearstatcache();
|
||||
|
||||
Reference in New Issue
Block a user