MDL-79863 qtype_ordering: Moodle.2x qtype/ordering fix any badly formed ordering questions that were added by earlier versions of GIFT/XML import

This commit is contained in:
Gordon Bateson
2024-04-04 10:59:14 +08:00
committed by Mathew May
parent 11492ba8c1
commit 78afb838c6
2 changed files with 33 additions and 1 deletions
+32
View File
@@ -20,11 +20,43 @@
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
defined('MOODLE_INTERNAL') || die();
function xmldb_qtype_ordering_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
$newversion = 2013062800;
if ($oldversion < $newversion) {
$select = 'qn.*, qo.id AS questionorderingid';
$from = '{question} qn LEFT JOIN {question_ordering} qo ON qn.id=qo.question';
$where = 'qn.qtype = ? AND qo.id IS NULL';
$params = array('ordering');
if ($questions = $DB->get_records_sql("SELECT $select FROM $from WHERE $where", $params)) {
foreach ($questions as $question) {
if ($answers = $DB->get_records('question_answers', array('question' => $question->id))) {
// add "options" for this ordering question
$question_ordering = (object)array(
'question' => $question->id,
'logical' => 1,
'studentsee' => min(6, count($answers)),
'correctfeedback' => '',
'partiallycorrectfeedback' => '',
'incorrectfeedback' => ''
);
$question_ordering->id = $DB->insert_record('question_ordering', $question_ordering);
} else {
// this is a faulty ordering question - remove it
$DB->delete_records('question', array('id' => $question->id));
$DB->delete_records('quiz_question_instances', array('question' => $question->id));
$DB->delete_records('reader_question_instances', array('question' => $question->id));
}
}
}
upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering');
}
return true;
}
+1 -1
View File
@@ -27,4 +27,4 @@ defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_ordering';
$plugin->maturity = MATURITY_STABLE;
$plugin->version = 2013062100;
$plugin->version = 2013062800;