From 67fc782fe8cfa4c827de3c840bf3f5388e3f3f34 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 29 Feb 2016 09:18:21 +0800 Subject: [PATCH] MDL-53274 core: in AJAX throw exception if page context was not set --- lib/pagelib.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/pagelib.php b/lib/pagelib.php index 811234f24cc..fafd4470f58 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -443,10 +443,15 @@ class moodle_page { * @return context the main context to which this page belongs. */ protected function magic_get_context() { + global $CFG; if (is_null($this->_context)) { if (CLI_SCRIPT or NO_MOODLE_COOKIES) { // Cli scripts work in system context, do not annoy devs with debug info. // Very few scripts do not use cookies, we can safely use system as default context there. + } else if (AJAX_SCRIPT && $CFG->debugdeveloper) { + // Throw exception inside AJAX script in developer mode, otherwise the debugging message may be missed. + throw new coding_exception('$PAGE->context was not set. You may have forgotten ' + .'to call require_login() or $PAGE->set_context()'); } else { debugging('Coding problem: $PAGE->context was not set. You may have forgotten ' .'to call require_login() or $PAGE->set_context(). The page may not display '