Permalink
Browse files

MDL-28180 backup - take rid of dupes in course_completion_aggr_methd

  • Loading branch information...
stronk7 committed Dec 11, 2011
1 parent ff4a2dd commit 9de951556f1a95c099b30e77b290c0785ee0e6e2
Showing with 29 additions and 1 deletion.
  1. +28 −0 lib/db/upgrade.php
  2. +1 −1 version.php
View
@@ -6951,6 +6951,34 @@ function xmldb_main_upgrade($oldversion) {
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
+ if ($oldversion < 2011120500.02) {
+
+ upgrade_set_timeout(60*20); // This may take a while
+ // MDL-28180. Some missing restrictions in certain backup & restore operations
+ // were causing incorrect duplicates in the course_completion_aggr_methd table.
+ // This upgrade step takes rid of them.
+ $sql = 'SELECT course, criteriatype, MIN(id) AS minid
+ FROM {course_completion_aggr_methd}
+ GROUP BY course, criteriatype
+ HAVING COUNT(*) > 1';
+ $duprs = $DB->get_recordset_sql($sql);
+ foreach ($duprs as $duprec) {
+ // We need to handle NULLs in criteriatype diferently
+ if (is_null($duprec->criteriatype)) {
+ $where = 'course = ? AND criteriatype IS NULL AND id > ?';
+ $params = array($duprec->course, $duprec->minid);
+ } else {
+ $where = 'course = ? AND criteriatype = ? AND id > ?';
+ $params = array($duprec->course, $duprec->criteriatype, $duprec->minid);
+ }
+ $DB->delete_records_select('course_completion_aggr_methd', $where, $params);
+ }
+ $duprs->close();
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2011120500.02);
+ }
+
return true;
}
View
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011120500.01; // 20111205 = branching date YYYYMMDD - do not modify!
+$version = 2011120500.02; // 20111205 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

0 comments on commit 9de9515

Please sign in to comment.