Skip to content

Commit

Permalink
fix sync_users looking only for usernames when matching agains moodle…
Browse files Browse the repository at this point in the history
… mail
  • Loading branch information
phager-at committed Jun 8, 2022
1 parent d5e7080 commit 270a181
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions local/o365/classes/feature/usersync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,14 @@ public function sync_users(array $aadusers = array()) {
return true;
}

$select = 'SELECT LOWER(u.username) AS username,';
if (isset($aadsync['emailsync'])) {
$select .= ' LOWER(u.email) AS email,';
}
/* In order to find existing user accounts using isset($existingusers[$aadupn]) we have to index the array
* by email address if we match AAD UPNs against Moodle email addresses!
* TODO: We may run into problems if we have multiple accounts with the same mail address!
* See setting `allowaccountssameemail`.
*/
$select = isset($aadsync['emailsync']) ?
"SELECT LOWER(u.email) AS email, LOWER(u.username) AS username," :
"SELECT LOWER(u.username) AS username";

$sql = "$select
u.id as muserid,
Expand Down

0 comments on commit 270a181

Please sign in to comment.