diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7b64921ae3c..2747982b6ac 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2853,10 +2853,6 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($cm->id); } - $PAGE->set_cm($cm, $course); // Set's up global $COURSE. - $PAGE->set_pagelayout('incourse'); - } else { - $PAGE->set_course($course); // Set's up global $COURSE. } } else { // Do not touch global $COURSE via $PAGE->set_course(), @@ -2960,6 +2956,13 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ // Do not bother admins with any formalities. if (is_siteadmin()) { + // Set the global $COURSE. + if ($cm) { + $PAGE->set_cm($cm, $course); + $PAGE->set_pagelayout('incourse'); + } else if (!empty($courseorid)) { + $PAGE->set_course($course); + } // Set accesstime or the user will appear offline which messes up messaging. user_accesstime_log($course->id); return; @@ -3017,6 +3020,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ if ($preventredirect) { throw new require_login_exception('Course is hidden'); } + $PAGE->set_context(null); // We need to override the navigation URL as the course won't have been added to the navigation and thus // the navigation will mess up when trying to find it. navigation_node::override_active_url(new moodle_url('/')); @@ -3037,6 +3041,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ if ($preventredirect) { throw new require_login_exception('Invalid course login-as access'); } + $PAGE->set_context(null); echo $OUTPUT->header(); notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot .'/'); } @@ -3151,6 +3156,14 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ redirect($url, get_string('activityiscurrentlyhidden')); } + // Set the global $COURSE. + if ($cm) { + $PAGE->set_cm($cm, $course); + $PAGE->set_pagelayout('incourse'); + } else if (!empty($courseorid)) { + $PAGE->set_course($course); + } + // Finally access granted, update lastaccess times. user_accesstime_log($course->id); } diff --git a/mod/forum/tests/externallib_test.php b/mod/forum/tests/externallib_test.php index c4405b47757..6d0764001b6 100644 --- a/mod/forum/tests/externallib_test.php +++ b/mod/forum/tests/externallib_test.php @@ -370,7 +370,6 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { } catch (moodle_exception $e) { $this->assertEquals('requireloginerror', $e->errorcode); } - $this->assertDebuggingCalled(); } /**