MDL-79205 webservice: gracefully handle invalid functions in docs.

This commit is contained in:
Paul Holden 2023-08-31 14:48:58 +01:00
parent 206c3a66e7
commit 6e9e73aba0
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
2 changed files with 14 additions and 7 deletions

View File

@ -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);

View File

@ -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) {