mirror of
https://github.com/moodle/moodle.git
synced 2025-07-07 15:35:33 +02:00
MDL-79863 qtype_ordering: qtype/ordering fix error upgrading when there are duplicate questionids in qtype_ordering_options table
This commit is contained in:
committed by
Mathew May
parent
9805054bf2
commit
e73cdf3714
@ -125,6 +125,20 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure there are no duplicate "questionid" fields in "qtype_ordering_options" table
|
||||||
|
$select = 'questionid, COUNT(*) AS countduplicates, MAX(id) AS maxid';
|
||||||
|
$from = '{qtype_ordering_options}';
|
||||||
|
$group = 'questionid';
|
||||||
|
$having = 'countduplicates > ?';
|
||||||
|
$params = array(1);
|
||||||
|
if ($records = $DB->get_records_sql("SELECT $select FROM $from GROUP BY $group HAVING $having", $params)) {
|
||||||
|
foreach ($records as $record) {
|
||||||
|
$select = 'id <> ? AND questionid = ?';
|
||||||
|
$params = array($record->maxid, $record->questionid);
|
||||||
|
$DB->delete_records_select('qtype_ordering_options', $select, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// restore index on questionid field
|
// restore index on questionid field
|
||||||
$table = new xmldb_table('qtype_ordering_options');
|
$table = new xmldb_table('qtype_ordering_options');
|
||||||
$index = new xmldb_index('qtypordeopti_que_uix', XMLDB_INDEX_UNIQUE, array('questionid'));
|
$index = new xmldb_index('qtypordeopti_que_uix', XMLDB_INDEX_UNIQUE, array('questionid'));
|
||||||
|
@ -30,6 +30,6 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
$plugin->cron = 0;
|
$plugin->cron = 0;
|
||||||
$plugin->component = 'qtype_ordering';
|
$plugin->component = 'qtype_ordering';
|
||||||
$plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200
|
$plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200
|
||||||
$plugin->release = '2015-01-19 (15)';
|
$plugin->release = '2015-01-23 (16)';
|
||||||
$plugin->version = 2015011915;
|
$plugin->version = 2015012316;
|
||||||
$plugin->requires = 2010112400; // Moodle 2.0
|
$plugin->requires = 2010112400; // Moodle 2.0
|
||||||
|
Reference in New Issue
Block a user