Skip to content

Commit

Permalink
MDL-41093 qtype match: unique index upgrade problem.
Browse files Browse the repository at this point in the history
Eliminate duplicate rows before we try to add a unique index. We
arbitrarily keep the duplicate row with the lowest id.
  • Loading branch information
timhunt committed Aug 15, 2013
1 parent 838d78a commit 89b04be
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions question/type/match/db/upgrade.php
Expand Up @@ -44,6 +44,25 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Moodle v2.4.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2013012099) {
// Find duplicate rows before they break the 2013012103 step below.
$problemids = $DB->get_recordset_sql("
SELECT question, MIN(id) AS recordidtokeep
FROM {question_match}
GROUP BY question
HAVING COUNT(1) > 1
");
foreach ($problemids as $problem) {
$DB->delete_records_select('question_match',
'question = ? AND id > ?',
array($problem->question, $problem->recordidtokeep));
}
$problemids->close();

// Shortanswer savepoint reached.
upgrade_plugin_savepoint(true, 2013012099, 'qtype', 'match');
}

if ($oldversion < 2013012100) {

// Define table question_match to be renamed to qtype_match_options.
Expand Down

0 comments on commit 89b04be

Please sign in to comment.