From d2170cb542805a4e4ef905877320cf1cd976fcff Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 15 May 2012 01:59:57 +0800 Subject: [PATCH] MDL-29538 core_condition: moved the deletion of the course_modules_availability information above the deletion of the course modules --- lib/moodlelib.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a220a7053ff..b6601543ca5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4515,6 +4515,19 @@ function remove_course_contents($courseid, $showfeedback = true, array $options echo $OUTPUT->notification($strdeleted.get_string('completion', 'completion'), 'notifysuccess'); } + // 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)); + $DB->delete_records_select('course_modules_avail_fields', + 'coursemoduleid IN (SELECT id from {course_modules} WHERE course = ?)', + array($courseid)); + // Remove all data from gradebook - this needs to be done before course modules // because while deleting this information, the system may need to reference // the course modules that own the grades.