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.
This commit is contained in:
Mark Nelson 2017-05-15 12:20:15 +08:00
parent 17fb1d84a2
commit 004dcb4f58

View File

@ -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;