From 46e12372790c26d5c69f742f01952636476ff554 Mon Sep 17 00:00:00 2001 From: Sam Marshall Date: Wed, 1 Sep 2010 17:02:56 +0000 Subject: [PATCH] Completion MDL-23995 Completion, availability data not deleted with modules/course --- course/lib.php | 5 +++++ lib/moodlelib.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/course/lib.php b/course/lib.php index 94a02429e93..ca65cf7051a 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2637,6 +2637,11 @@ function delete_course_module($id) { $grade_item->delete('moddelete'); } } + // Delete completion and availability data; it is better to do this even if the + // features are not turned on, in case they were turned on previously (these will be + // very quick on an empty table) + $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id)); + $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id)); delete_context(CONTEXT_MODULE, $cm->id); return $DB->delete_records('course_modules', array('id'=>$cm->id)); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index cd129a2029b..bef795ba0f1 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4023,6 +4023,16 @@ function remove_course_contents($courseid, $showfeedback=true) { remove_course_grades($courseid, $showfeedback); remove_grade_letters($context, $showfeedback); +/// Remove all data from availability and completion tables that is associated +/// with course-modules belonging to this course. Note this is done even if the +/// features are not enabled now, in case they were enabled previously + $DB->delete_records_select('course_modules_completion', + 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', + array($courseid)); + $DB->delete_records_select('course_modules_availability', + 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', + array($courseid)); + /// Delete every instance of every module if ($allmods = $DB->get_records('modules') ) {