diff --git a/question/type/shortanswer/db/upgrade.php b/question/type/shortanswer/db/upgrade.php index 745d8af7d55..99dbc153f70 100644 --- a/question/type/shortanswer/db/upgrade.php +++ b/question/type/shortanswer/db/upgrade.php @@ -39,6 +39,25 @@ function xmldb_qtype_shortanswer_upgrade($oldversion) { // Moodle v2.4.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2013011799) { + // Find duplicate rows before they break the 2013011803 step below. + $problemids = $DB->get_recordset_sql(" + SELECT question, MIN(id) as recordidtokeep + FROM {question_shortanswer} + GROUP BY question + HAVING COUNT(1) > 1 + "); + foreach ($problemids as $problem) { + $DB->delete_records_select('question_shortanswer', + 'question = ? AND id > ?', + array($problem->question, $problem->recordidtokeep)); + } + $problemids->close(); + + // Shortanswer savepoint reached. + upgrade_plugin_savepoint(true, 2013011799, 'qtype', 'shortanswer'); + } + if ($oldversion < 2013011800) { // Define field answers to be dropped from question_shortanswer.