MDL-73396 core_user: prioritize active users when retrieving by email

Updated get_users_by_email() to return active users at the
start of the returned array, suspended users last.
This commit is contained in:
Niko Hoogeveen
2025-12-10 14:21:51 -05:00
parent a5b3ac7e43
commit 307ed32403
+8 -1
View File
@@ -156,7 +156,14 @@ class user {
$mnethostid = $CFG->mnet_localhost_id;
}
return $DB->get_record('user', ['email' => $email, 'mnethostid' => $mnethostid], $fields, $strictness);
// Build SQL query to prioritise active users.
$sql = "SELECT $fields
FROM {user}
WHERE email = :email AND mnethostid = :mnethostid
ORDER BY suspended ASC, timecreated DESC";
$params = ['email' => $email, 'mnethostid' => $mnethostid];
// Return the first user matching the query criteria.
return $DB->get_record_sql($sql, $params, $strictness);
}
/**