MDL-69687 Course: remove_course_contents orphaned completion data
[moodle.git] / lib / moodlelib.php
index fde434d..b571bb7 100644 (file)
@@ -5306,6 +5306,7 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
                     if ($cm->id) {
                         // Delete cm and its context - orphaned contexts are purged in cron in case of any race condition.
                         context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
+                        $DB->delete_records('course_modules_completion', ['coursemoduleid' => $cm->id]);
                         $DB->delete_records('course_modules', array('id' => $cm->id));
                         rebuild_course_cache($cm->course, true);
                     }