From 8387b02821101ce14aaa58dfdfe251c827eae360 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Fri, 21 Feb 2025 12:29:33 +0800 Subject: [PATCH] MDL-84532 qtype_ordering: Update query to use $DB->sql_compare_text() The change introduced in MDL-46739, which modified the 'value' column in the 'user_preferences' database table from CHAR to TEXT, caused the upgrade query to fail due to the '=' comparison operator being used on this column in the WHERE clause. This fix updates the query to use $DB->sql_compare_text() instead. --- question/type/ordering/db/upgrade.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/question/type/ordering/db/upgrade.php b/question/type/ordering/db/upgrade.php index 9d01b143820..5a2b822106c 100644 --- a/question/type/ordering/db/upgrade.php +++ b/question/type/ordering/db/upgrade.php @@ -319,8 +319,9 @@ function xmldb_qtype_ordering_upgrade($oldversion) { // 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]); + $wheresql = 'name = ? AND ' . $DB->sql_compare_text('value') . ' = ?'; + $params = ['qtype_ordering_selectcount', '0']; + $DB->set_field_select('user_preferences', 'value', 2, $wheresql, $params); upgrade_plugin_savepoint(true, 2023092911, 'qtype', 'ordering'); } @@ -359,8 +360,9 @@ function xmldb_qtype_ordering_upgrade($oldversion) { // 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]); + $wheresql = 'name = ? AND ' . $DB->sql_compare_text('value') . ' = ?'; + $params = ['qtype_ordering_selectcount', '0']; + $DB->set_field_select('user_preferences', 'value', 2, $wheresql, $params); upgrade_plugin_savepoint(true, 2024040401, 'qtype', 'ordering'); }