From 3bebbe6e51e7bb405f2f22df512e25d61187e38a Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 8 Apr 2016 13:01:06 +0800 Subject: [PATCH] NOBUG: Fix busted webservices context handling. $PAGE->context must be set even if the context is site. --- lib/ajax/service.php | 1 - lib/externallib.php | 9 ++++----- lib/moodlelib.php | 2 +- lib/pagelib.php | 13 +++++++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/ajax/service.php b/lib/ajax/service.php index e72f165..fa06b7d 100644 --- a/lib/ajax/service.php +++ b/lib/ajax/service.php @@ -41,7 +41,6 @@ if ($requests === null) { } $responses = array(); - foreach ($requests as $request) { $response = array(); $methodname = clean_param($request['methodname'], PARAM_ALPHANUMEXT); diff --git a/lib/externallib.php b/lib/externallib.php index 002d572..2dce5a1 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -359,7 +359,7 @@ class external_api { * @since Moodle 2.0 */ public static function validate_context($context) { - global $CFG; + global $CFG, $PAGE; if (empty($context)) { throw new invalid_parameter_exception('Context does not exist'); @@ -382,10 +382,9 @@ class external_api { } } - if ($context->contextlevel >= CONTEXT_COURSE) { - list($context, $course, $cm) = get_context_info_array($context->id); - require_login($course, false, $cm, false, true); - } + $PAGE->reset_theme_and_output(); + list($context, $course, $cm) = get_context_info_array($context->id); + require_login($course, false, $cm, false, true); } /** diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 44dc966..c3819cf 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2635,7 +2635,7 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ if ($cm) { $PAGE->set_cm($cm, $course); $PAGE->set_pagelayout('incourse'); - } else if (!empty($courseorid)) { + } else { $PAGE->set_course($course); } // Set accesstime or the user will appear offline which messes up messaging. diff --git a/lib/pagelib.php b/lib/pagelib.php index 33466f5..56d2dc9 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1561,6 +1561,19 @@ class moodle_page { } /** + * Reset the theme and output for a new context. This only makes sense from + * external::validate_context(). Do not cheat. + * + * @return string the name of the theme that should be used on this page. + */ + public function reset_theme_and_output() { + $this->_theme = null; + $this->_wherethemewasinitialised = null; + $this->_course = null; + $this->_context = null; + } + + /** * Work out the theme this page should use. * * This depends on numerous $CFG settings, and the properties of this page. -- 2.4.9 (Apple Git-60)