MDL-31914 Ensure that completion criteria are deleted when removing a course module
Conflicts: lib/db/upgrade.php version.php
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
14ffb91959
commit
ede323e2b3
@@ -2930,6 +2930,8 @@ function delete_course_module($id) {
|
||||
// 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));
|
||||
$DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
|
||||
'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
|
||||
|
||||
delete_context(CONTEXT_MODULE, $cm->id);
|
||||
return $DB->delete_records('course_modules', array('id'=>$cm->id));
|
||||
|
||||
@@ -402,5 +402,25 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2012042300.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012042300.02) {
|
||||
require_once($CFG->libdir . '/completion/completion_criteria.php');
|
||||
// Delete orphaned criteria which were left when modules were removed
|
||||
if ($DB->get_dbfamily() === 'mysql') {
|
||||
$sql = "DELETE cc FROM {course_completion_criteria} cc
|
||||
LEFT JOIN {course_modules} cm ON cm.id = cc.moduleinstance
|
||||
WHERE cm.id IS NULL AND cc.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY;
|
||||
} else {
|
||||
$sql = "DELETE FROM {course_completion_criteria}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 'x' FROM {course_modules}
|
||||
WHERE {course_modules}.id = {course_completion_criteria}.moduleinstance)
|
||||
AND cc.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY;
|
||||
}
|
||||
$DB->execute($sql);
|
||||
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2012042300.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$version = 2012042300.01; // YYYYMMDD = weekly release date of this DEV branch
|
||||
$version = 2012042300.02; // YYYYMMDD = weekly release date of this DEV branch
|
||||
// RR = release increments - 00 in DEV branches
|
||||
// .XX = incremental changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user