diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 200e6157c3c..82bbb335eee 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6696,6 +6696,34 @@ FROM upgrade_main_savepoint(true, 2011070102.08); } + if ($oldversion < 2011070103.04) { + + 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, 2011070103.04); + } + return true; } diff --git a/version.php b/version.php index 81531b05a86..388102c6432 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011070103.03; // 20110701 = branching date YYYYMMDD - do not modify! +$version = 2011070103.04; // 20110701 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches // .XX = incremental changes