MDL-78888 tool_uploaduser: case-insensitive email matching on upload.

This commit is contained in:
Paul Holden 2023-11-16 10:34:38 +00:00
parent 580c009cac
commit accb66f905
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164

View File

@ -461,9 +461,22 @@ class process {
return;
}
$matchparam = $this->get_match_on_email() ? ['email' => $user->email] : ['username' => $user->username];
if ($existinguser = $DB->get_records('user', $matchparam + ['mnethostid' => $user->mnethostid])) {
if (is_array($existinguser) && count($existinguser) !== 1) {
if ($this->get_match_on_email()) {
// Case-insensitive query for the given email address.
$userselect = $DB->sql_equal('email', ':email', false);
$userparams = ['email' => $user->email];
} else {
$userselect = 'username = :username';
$userparams = ['username' => $user->username];
}
// Match the user, also accounting for multiple records by email.
$existinguser = $DB->get_records_select('user', "{$userselect} AND mnethostid = :mnethostid",
$userparams + ['mnethostid' => $user->mnethostid]);
$existingusercount = count($existinguser);
if ($existingusercount > 0) {
if ($existingusercount !== 1) {
$this->upt->track('status', get_string('duplicateemail', 'tool_uploaduser', $user->email), 'warning');
$this->userserrors++;
return;