diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 68e1efccd33..84a1c2dfe34 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2850,10 +2850,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(), @@ -2957,6 +2953,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; @@ -3014,6 +3017,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('/')); @@ -3034,6 +3038,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 .'/'); } @@ -3148,6 +3153,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 b3f15ceeed9..557a905d91d 100644 --- a/mod/forum/tests/externallib_test.php +++ b/mod/forum/tests/externallib_test.php @@ -342,7 +342,6 @@ class mod_forum_external_testcase extends externallib_advanced_testcase { } catch (moodle_exception $e) { $this->assertEquals('requireloginerror', $e->errorcode); } - $this->assertDebuggingCalled(); } /**