From 9ba17166fe43206968f8ea8e1f04cc876f74dfd5 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Mon, 30 Mar 2020 14:15:00 +0800 Subject: [PATCH] MDL-68263 course: Fix error when modules are not fully uninstalled --- .../repository/content_item_readonly_repository.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/course/classes/local/repository/content_item_readonly_repository.php b/course/classes/local/repository/content_item_readonly_repository.php index 8152c6ddb2e19..3704b9765eb90 100644 --- a/course/classes/local/repository/content_item_readonly_repository.php +++ b/course/classes/local/repository/content_item_readonly_repository.php @@ -185,7 +185,7 @@ private function legacy_item_inherit_missing(\stdClass $legacyitem, content_item * @return array the array of content items. */ public function find_all(): array { - global $OUTPUT, $DB; + global $OUTPUT, $DB, $CFG; // Get all modules so we know which plugins are enabled and able to add content. // Only module plugins may add content items. @@ -194,6 +194,10 @@ public function find_all(): array { // Now, generate the content_items. foreach ($modules as $modid => $mod) { + // Exclude modules if the code doesn't exist. + if (!file_exists("$CFG->dirroot/mod/$mod->name/lib.php")) { + continue; + } // Create the content item for the module itself. // If the module chooses to implement the hook, this may be thrown away. $help = $this->get_core_module_help_string($mod->name); @@ -241,7 +245,7 @@ public function find_all(): array { * @return array the array of content_item objects */ public function find_all_for_course(\stdClass $course, \stdClass $user): array { - global $OUTPUT, $DB; + global $OUTPUT, $DB, $CFG; // Get all modules so we know which plugins are enabled and able to add content. // Only module plugins may add content items. @@ -253,7 +257,10 @@ public function find_all_for_course(\stdClass $course, \stdClass $user): array { // Now, generate the content_items. foreach ($modules as $modid => $mod) { - + // Exclude modules if the code doesn't exist. + if (!file_exists("$CFG->dirroot/mod/$mod->name/lib.php")) { + continue; + } // Create the content item for the module itself. // If the module chooses to implement the hook, this may be thrown away. $help = $this->get_core_module_help_string($mod->name);