From ab7ee8fa1d03071f20e4d23b99af6046a736d97c Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 17 Aug 2021 18:00:11 +0200 Subject: [PATCH] MDL-72358 contenttype_h5p: Improve error handling In MoodleCloud it was raised that, in some cases, loading the content bank, from a course page, gives an "Invalid H5P content URL", not offering any way to delete the offending content or create new one. An extra-check has been added to the "is_view_allowed" method to guarantee the H5P API is called only if the H5P content has a file. --- contentbank/contenttype/h5p/classes/content.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contentbank/contenttype/h5p/classes/content.php b/contentbank/contenttype/h5p/classes/content.php index ea41ffbbdd0..e573a7029ed 100644 --- a/contentbank/contenttype/h5p/classes/content.php +++ b/contentbank/contenttype/h5p/classes/content.php @@ -42,6 +42,12 @@ class content extends \core_contentbank\content { public function is_view_allowed(): bool { // Force H5P content to be deployed. $fileurl = $this->get_file_url(); + if (empty($fileurl)) { + // This should never happen because H5P contents should have always a file. However, this extra-checked has been added + // to avoid the contentbank stop working if, for any unkonwn/weird reason, the file doesn't exist. + return false; + } + // Skip capability check when creating the H5P content (because it has been created by trusted users). $h5pplayer = new \core_h5p\player($fileurl, new \stdClass(), true, '', true); // Flush error messages.