From 1573c3031bb4fe150b2502252e802a33c39876e3 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 5 Oct 2016 12:22:18 +0100 Subject: [PATCH] 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). --- lib/javascript.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/javascript.php b/lib/javascript.php index f8ad74c8dc9..7e7869fbac1 100644 --- a/lib/javascript.php +++ b/lib/javascript.php @@ -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();