MDL-53274 core: in AJAX throw exception if page context was not set

This commit is contained in:
Marina Glancy
2016-03-18 08:08:50 +08:00
parent fed66ad9e2
commit 67fc782fe8
+5
View File
@@ -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 '