mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-79205 webservice: gracefully handle invalid functions in docs.
This commit is contained in:
parent
8ac8ea416a
commit
b1abcd1f42
@ -29,13 +29,6 @@ require_once($CFG->dirroot . '/webservice/lib.php');
|
||||
|
||||
admin_externalpage_setup('webservicedocumentation');
|
||||
|
||||
// get all the function descriptions
|
||||
$functions = $DB->get_records('external_functions', array(), 'name');
|
||||
$functiondescs = array();
|
||||
foreach ($functions as $function) {
|
||||
$functiondescs[$function->name] = external_api::external_function_info($function);
|
||||
}
|
||||
|
||||
// TODO: MDL-76078 - Incorrect inter-communication, core cannot have plugin dependencies like this.
|
||||
|
||||
//display the documentation for all documented protocols,
|
||||
@ -50,6 +43,19 @@ $printableformat = optional_param('print', false, PARAM_BOOL);
|
||||
/// OUTPUT
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Get all the function descriptions.
|
||||
$functions = $DB->get_records('external_functions', [], 'name');
|
||||
$functiondescs = [];
|
||||
foreach ($functions as $function) {
|
||||
|
||||
// Skip invalid or otherwise incorrectly defined functions, otherwise the entire page is rendered inaccessible.
|
||||
try {
|
||||
$functiondescs[$function->name] = external_api::external_function_info($function);
|
||||
} catch (Throwable $exception) {
|
||||
echo $OUTPUT->notification($exception->getMessage(), \core\output\notification::NOTIFY_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$renderer = $PAGE->get_renderer('core', 'webservice');
|
||||
echo $renderer->documentation_html($functiondescs,
|
||||
$printableformat, $protocols, array(), $PAGE->url);
|
||||
|
@ -64,6 +64,7 @@ class external_api {
|
||||
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
|
||||
* MUST_EXIST means throw exception if no record or multiple records found
|
||||
* @return stdClass description or false if not found or exception thrown
|
||||
* @throws coding_exception for any property and/or method that is missing or invalid
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
public static function external_function_info($function, $strictness=MUST_EXIST) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user