MDL-40370 qtype_shortanswer: unique index upgrade problem.
Eliminate duplicate rows before we try to add a unique index. We arbitrarily keep the duplicate row with the lowest id.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user