diff --git a/admin/webservice/documentation.php b/admin/webservice/documentation.php index 9ccca8b14eb..265ec883d6c 100644 --- a/admin/webservice/documentation.php +++ b/admin/webservice/documentation.php @@ -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); diff --git a/lib/externallib.php b/lib/externallib.php index 666b49940cf..551b329ba18 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -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) {