From 004dcb4f585a2d7109b8c52a3b20332e31caec81 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 15 May 2017 12:20:15 +0800 Subject: [PATCH] MDL-58936 core: ensure 'page->context' is not null When using $page->context it calls magic_get_context() in lib/pagelib.php. This method sets the context to context_system::instance() if it is currently null and returns that as the context. However, when installing a new site context_system::instance() also returns null. --- lib/outputrequirementslib.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 04062459b95..e52b517cf96 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -315,6 +315,12 @@ class page_requirements_manager { $iconsystem = \core\output\icon_system::instance(); + // It is possible that the $page->context is null, so we can't use $page->context->id. + $contextid = null; + if (!is_null($page->context)) { + $contextid = $page->context->id; + } + $this->M_cfg = array( 'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above. 'sesskey' => sesskey(), @@ -326,7 +332,7 @@ class page_requirements_manager { 'admin' => $CFG->admin, 'svgicons' => $page->theme->use_svg_icons(), 'usertimezone' => usertimezone(), - 'contextid' => $page->context->id, + 'contextid' => $contextid, ); if ($CFG->debugdeveloper) { $this->M_cfg['developerdebug'] = true;