mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-53772 externallib: Fix busted webservices context handling
Fix: $PAGE->context must be reset when calling validate_context Improve: Provide wrapper for calling an external function The wrapper correctly checks the function parameters and return type against the description of the external function, and stores the PAGE and COURSE global state variables, restoring them before the function returns. Fix: buggy unit tests. These tests are expecting debugging from a bug that was fixed, and calling web service functions with no user or session.
This commit is contained in:
parent
b611ade3ab
commit
56fa860ead
7 changed files with 258 additions and 164 deletions
|
@ -981,7 +981,6 @@ class moodle_page {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Ideally we should set context only once.
|
||||
if (isset($this->_context) && $context->id !== $this->_context->id) {
|
||||
$current = $this->_context->contextlevel;
|
||||
|
@ -993,11 +992,7 @@ class moodle_page {
|
|||
} else {
|
||||
// We do not want devs to do weird switching of context levels on the fly because we might have used
|
||||
// the context already such as in text filter in page title.
|
||||
// This is explicitly allowed for webservices though which may
|
||||
// call "external_api::validate_context on many contexts in a single request.
|
||||
if (!WS_SERVER) {
|
||||
debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
|
||||
}
|
||||
debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1560,6 +1555,22 @@ class moodle_page {
|
|||
$this->_wherethemewasinitialised = debug_backtrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
global $COURSE, $SITE;
|
||||
|
||||
$COURSE = clone($SITE);
|
||||
$this->_theme = null;
|
||||
$this->_wherethemewasinitialised = null;
|
||||
$this->_course = null;
|
||||
$this->_context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out the theme this page should use.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue