From c60d03a7b625ee63a019deec499ff062f75230b6 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 29 Apr 2024 12:09:17 +0200 Subject: [PATCH] MDL-81717 h5p: Improve robustness content type fetching Strengthen code to ensure retrieval of all content types, despite failures. --- h5p/classes/core.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/h5p/classes/core.php b/h5p/classes/core.php index 8c6935dd598..6bedab9b7e2 100644 --- a/h5p/classes/core.php +++ b/h5p/classes/core.php @@ -273,8 +273,16 @@ class core extends H5PCore { $librarykey = static::libraryToString($library); + if (is_null($factory->get_storage()->h5pC->librariesJsonData)) { + // There was an error fetching the content type. + debugging('Error fetching content type: ' . $librarykey); + return null; + } + $libraryjson = $factory->get_storage()->h5pC->librariesJsonData[$librarykey]; - if (!array_key_exists('libraryId', $libraryjson)) { + if (is_null($libraryjson) || !array_key_exists('libraryId', $libraryjson)) { + // There was an error fetching the content type. + debugging('Error fetching content type: ' . $librarykey); return null; } -- 2.11.4.GIT