diff --git a/question/type/ordering/db/upgrade.php b/question/type/ordering/db/upgrade.php index 7c1ea3f9863..0e0292472e3 100644 --- a/question/type/ordering/db/upgrade.php +++ b/question/type/ordering/db/upgrade.php @@ -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; } diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index 188b094feea..6fa6a0cc47b 100644 --- a/question/type/ordering/version.php +++ b/question/type/ordering/version.php @@ -27,4 +27,4 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'qtype_ordering'; $plugin->maturity = MATURITY_STABLE; -$plugin->version = 2013062100; +$plugin->version = 2013062800;