diff --git a/question/type/ordering/db/upgrade.php b/question/type/ordering/db/upgrade.php index 6c9bcd7d6b2..e97624f3ec9 100644 --- a/question/type/ordering/db/upgrade.php +++ b/question/type/ordering/db/upgrade.php @@ -32,8 +32,7 @@ function xmldb_qtype_ordering_upgrade($oldversion) { $dbman = $DB->get_manager(); - $newversion = 2013062800; - if ($oldversion < $newversion) { + if ($oldversion < 2013062800) { $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'; @@ -63,11 +62,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { } } } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2013062800, 'qtype', 'ordering'); } - $newversion = 2015011915; - if ($oldversion < $newversion) { + if ($oldversion < 2015011915) { // Rename "ordering" table for Moodle >= 2.5. $oldname = 'question_ordering'; @@ -151,11 +149,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { $dbman->add_index($table, $index); } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2015011915, 'qtype', 'ordering'); } - $newversion = 2015110725; - if ($oldversion < $newversion) { + if ($oldversion < 2015110725) { $table = new xmldb_table('qtype_ordering_options'); $fields = array( new xmldb_field('layouttype', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 0, 'questionid'), @@ -168,11 +165,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { $dbman->add_field($table, $field); } } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2015110725, 'qtype', 'ordering'); } - $newversion = 2015121734; - if ($oldversion < $newversion) { + if ($oldversion < 2015121734) { $table = new xmldb_table('qtype_ordering_options'); $fields = array( new xmldb_field('gradingtype', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 0, 'selectcount') @@ -187,11 +183,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { $DB->execute('UPDATE {qtype_ordering_options} SET gradingtype = selecttype', array()); } } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2015121734, 'qtype', 'ordering'); } - $newversion = 2016032949; - if ($oldversion < $newversion) { + if ($oldversion < 2016032949) { if ($dbman->table_exists('reader_question_instances')) { $select = 'rqi.question, COUNT(*) AS countquestion'; $from = '{reader_question_instances} rqi '. @@ -215,10 +210,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { $DB->set_field_select($table, 'selectcount', 6, $select, $params); // Six. } } + upgrade_plugin_savepoint(true, 2016032949, 'qtype', 'ordering'); } - $newversion = 2016081655; - if ($oldversion < $newversion) { + if ($oldversion < 2016081655) { $table = new xmldb_table('qtype_ordering_options'); $field = new xmldb_field('showgrading', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 1, 'gradingtype'); if ($dbman->field_exists($table, $field)) { @@ -226,11 +221,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { } else { $dbman->add_field($table, $field); } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2016081655, 'qtype', 'ordering'); } - $newversion = 2019071191; - if ($oldversion < $newversion) { + if ($oldversion < 2019071191) { // Add field "numberingstyle" to table "qtype_ordering_options". // This field was briefly called "answernumbering". @@ -255,11 +249,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { } else { $dbman->add_field($table, $field); } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2019071191, 'qtype', 'ordering'); } - $newversion = '2019073193'; - if ($oldversion < $newversion) { + if ($oldversion < 2019073193) { $table = 'qtype_ordering_options'; $field = 'numberingstyle'; $select = "$field = ? OR $field = ?"; @@ -278,11 +271,10 @@ function xmldb_qtype_ordering_upgrade($oldversion) { } } } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2019073193, 'qtype', 'ordering'); } - $newversion = '2022092000'; - if ($oldversion < $newversion) { + if ($oldversion < 2022092000) { $table = new xmldb_table('qtype_ordering_options'); $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 0); if ($dbman->field_exists($table, $field)) { @@ -290,7 +282,48 @@ function xmldb_qtype_ordering_upgrade($oldversion) { } else { $dbman->add_field($table, $field); } - upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering'); + upgrade_plugin_savepoint(true, 2022092000, 'qtype', 'ordering'); + } + + if ($oldversion < 2023092911) { + // The option to set "All" for the subset size ('selectcount') setting is no longer supported, therefore we need + // to update all data that references this option. + + // The 'selectcount' column from the 'qtype_ordering_options' table currently defines "0" as its default value. + // This value ("0") used to represent the removed "All" option for the 'selectcount' setting, therefore we need + // to update this to a new default of "2" which is the minimum number of items required to create a subset. + $table = new xmldb_table('qtype_ordering_options'); + $field = new xmldb_field('selectcount'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 2); + $dbman->change_field_default($table, $field); + + // We need to find all ordering question configurations that currently store the unsupported "0" (all) option + // for the 'selectcount' setting and the total number of answers that are related to each of these ordering + // questions. + $sql = "SELECT qoo.*, COUNT(DISTINCT(qa.id)) AS answerscount + FROM {qtype_ordering_options} qoo + JOIN {question_answers} qa ON qa.question = qoo.questionid + WHERE selectcount = :selectcount + GROUP BY qoo.id"; + $questionoptions = $DB->get_recordset_sql($sql, ['selectcount' => 0]); + foreach ($questionoptions as $questionoption) { + // Update the value of the 'selectcount' configuration option for the current ordering question and set it + // to the total number of answers related to this question. This way, we are making sure that the original + // behavior is preserved and all existing items (answers) related to the question will be included in the + // subset. + $questionoption->selectcount = $questionoption->answerscount; + unset($questionoption->answerscount); + $DB->update_record('qtype_ordering_options', $questionoption); + } + $questionoptions->close(); + + // Currently, a 'qtype_ordering_selectcount' user preference is set (or updated, if it already exists) each time + // a new ordering question is created. If there are user preferences that store the removed "0" (all) option, they + // need to be updated. In this case, replace it with "2" (minimum number of items required to create a subset). + $DB->set_field('user_preferences', 'value', 2, + ['name' => 'qtype_ordering_selectcount', 'value' => 0]); + + upgrade_plugin_savepoint(true, 2023092911, 'qtype', 'ordering'); } return true; diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index c8178841989..1f83cadedb5 100644 --- a/question/type/ordering/version.php +++ b/question/type/ordering/version.php @@ -29,5 +29,4 @@ $plugin->cron = 0; $plugin->component = 'qtype_ordering'; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2021051700; // Moodle 3.11. -$plugin->version = 2023092910; -$plugin->release = '2023-09-29 (10)'; +$plugin->version = 2024040400; // The current plugin version (Date: YYYYMMDDXX).