From e864296f88893cbce44e2d7317ab30e0d79bdc14 Mon Sep 17 00:00:00 2001 From: Colin Beeby Date: Tue, 1 Apr 2025 14:30:28 +0100 Subject: [PATCH 1/2] Removed Text column compare prohibition --- lib/dml/moodle_database.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 9818372eaf1..537ba6aff90 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -686,7 +686,9 @@ protected function where_clause($table, ?array $conditions=null) { $column = $columns[$key]; if ($column->meta_type == 'X') { //ok so the column is a text column. sorry no text columns in the where clause conditions - throw new dml_exception('textconditionsnotallowed', $conditions); + //throw new dml_exception('textconditionsnotallowed', $conditions); + // Use sql_compare_text() for text columns + $key = $this->sql_compare_text($key); } } } From 3cf30c7404f3a485a9140e6ecbc73518014aa2f1 Mon Sep 17 00:00:00 2001 From: Colin Beeby Date: Tue, 1 Apr 2025 14:57:29 +0100 Subject: [PATCH 2/2] Using sql_compare_text in send_new_user_passwords --- lib/classes/task/send_new_user_passwords_task.php | 6 +++++- lib/dml/moodle_database.php | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/classes/task/send_new_user_passwords_task.php b/lib/classes/task/send_new_user_passwords_task.php index 678b29a40c7..6c27a97728f 100644 --- a/lib/classes/task/send_new_user_passwords_task.php +++ b/lib/classes/task/send_new_user_passwords_task.php @@ -44,8 +44,12 @@ public function get_name() { public function execute() { global $DB; + $select = $DB->sql_compare_text('name') . ' = ? AND ' . $DB->sql_compare_text('value') . ' = ?'; + $params = array('create_password', '1'); + // Generate new password emails for users - ppl expect these generated asap. - if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) { + //if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) { + if ($DB->count_records_select('user_preferences', $select, $params)) { mtrace('Creating passwords for new users...'); $userfieldsapi = \core_user\fields::for_name(); $usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects; diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 537ba6aff90..9818372eaf1 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -686,9 +686,7 @@ protected function where_clause($table, ?array $conditions=null) { $column = $columns[$key]; if ($column->meta_type == 'X') { //ok so the column is a text column. sorry no text columns in the where clause conditions - //throw new dml_exception('textconditionsnotallowed', $conditions); - // Use sql_compare_text() for text columns - $key = $this->sql_compare_text($key); + throw new dml_exception('textconditionsnotallowed', $conditions); } } }