From bfdcf4b4900d7b8e47c802efe76cea2acee99d4f Mon Sep 17 00:00:00 2001 From: raortegar Date: Tue, 20 May 2025 11:08:12 +0200 Subject: [PATCH] MDL-74900 core_course: Exception in module deletion if missing instance --- course/lib.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/course/lib.php b/course/lib.php index 1557e5729bd..d295a3d0f07 100644 --- a/course/lib.php +++ b/course/lib.php @@ -763,6 +763,11 @@ function course_delete_module($cmid, $async = false) { } } + if (empty($cm->instance)) { + throw new moodle_exception('cannotdeletemodulemissinginstance', '', '', null, + "Cannot delete course module with ID $cm->id because it does not have a valid activity instance."); + } + // Call the delete_instance function, if it returns false throw an exception. if (!$deleteinstancefunction($cm->instance)) { throw new moodle_exception('cannotdeletemoduleinstance', '', '', null,