From da92cfbeee108999ad9e89e60c4a307c5b108ccb Mon Sep 17 00:00:00 2001 From: Tasio Date: Mon, 21 Jul 2025 10:50:37 +0200 Subject: [PATCH] MDL-86043 core: keep SQL consistent with other Moodle versions. This change resolves issues with Oracle in Moodle 4.5. It has been ported to newer Moodle versions as it improves the existing SQL and helps maintain consistency across different Moodle versions. --- public/lib/classes/task/send_new_user_passwords_task.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/lib/classes/task/send_new_user_passwords_task.php b/public/lib/classes/task/send_new_user_passwords_task.php index 57002c2c5a8..32ec30cf365 100644 --- a/public/lib/classes/task/send_new_user_passwords_task.php +++ b/public/lib/classes/task/send_new_user_passwords_task.php @@ -55,6 +55,7 @@ class send_new_user_passwords_task extends scheduled_task { mtrace('Creating passwords for new users...'); $userfieldsapi = \core_user\fields::for_name(); $usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects; + [$sort, $sortparams] = users_order_by_sql('u'); $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted, u.suspended, u.emailstop, u.mnethostid, u.mailformat, $usernamefields, u.username, u.lang, @@ -66,7 +67,8 @@ class send_new_user_passwords_task extends scheduled_task { AND u.email <> '' AND u.suspended = 0 AND u.auth <> 'nologin' - AND u.deleted = 0"); + AND u.deleted = 0 + ORDER BY $sort ASC", $sortparams); // Note: we can not send emails to suspended accounts. foreach ($newusers as $newuser) {