mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-79205 webservice: gracefully handle invalid functions in docs.
This commit is contained in:
parent
206c3a66e7
commit
6e9e73aba0
@ -32,13 +32,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,
|
||||
@ -53,6 +46,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);
|
||||
|
1
lib/external/classes/external_api.php
vendored
1
lib/external/classes/external_api.php
vendored
@ -46,6 +46,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|bool 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