From fdaea8ad644bf835a3225f4bdf64ecc6ba36aeb7 Mon Sep 17 00:00:00 2001 From: John Okely Date: Fri, 2 Dec 2016 14:34:18 +0800 Subject: [PATCH] MDL-57193 auth_db: Use a recordset and array_key_exists --- auth/db/auth.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 46ecbaa76a7..1473437bdb6 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -308,12 +308,15 @@ class auth_plugin_db extends auth_plugin_base { FROM {user} u WHERE u.auth=:authtype AND u.deleted=0 AND u.mnethostid=:mnethostid $suspendselect"; $params['mnethostid'] = $CFG->mnet_localhost_id; - $internalusers = $DB->get_records_sql($sql, $params); - foreach ($internalusers as $internaluser) { - if (!in_array($internaluser->username, $userlist)) { + $internalusersrs = $DB->get_recordset_sql($sql, $params); + foreach ($internalusersrs as $internaluser) { + // Arrange the associative array. + $usernamelist = array_flip($userlist); + if (!array_key_exists($internaluser->username, $usernamelist)) { $removeusers[] = $internaluser; } } + $internalusersrs->close(); } else { $sql = "SELECT u.id, u.username FROM {user} u