From e132aa26d50fa8e5f20cdb9a5f4d13983185fc41 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 53b2c002025..c7b3c203916 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,