mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-57193 auth_db: Fixed bug suspends all users if external DB has > 10k
This commit is contained in:
parent
a0352aa95e
commit
34949c1a55
1 changed files with 16 additions and 18 deletions
|
@ -301,17 +301,17 @@ class auth_plugin_db extends auth_plugin_base {
|
||||||
|
|
||||||
// Find obsolete users.
|
// Find obsolete users.
|
||||||
if (count($userlist)) {
|
if (count($userlist)) {
|
||||||
$remove_users = array();
|
$removeusers = array();
|
||||||
// All the drivers can cope with chunks of 10,000. See line 4491 of lib/dml/tests/dml_est.php
|
$params['authtype'] = $this->authtype;
|
||||||
$userlistchunks = array_chunk($userlist , 10000);
|
$sql = "SELECT u.id, u.username
|
||||||
foreach($userlistchunks as $userlistchunk) {
|
FROM {user} u
|
||||||
list($notin_sql, $params) = $DB->get_in_or_equal($userlistchunk, SQL_PARAMS_NAMED, 'u', false);
|
WHERE u.auth=:authtype AND u.deleted=0 AND u.mnethostid=:mnethostid $suspendselect";
|
||||||
$params['authtype'] = $this->authtype;
|
$params['mnethostid'] = $CFG->mnet_localhost_id;
|
||||||
$sql = "SELECT u.id, u.username
|
$internalusers = $DB->get_records_sql($sql, $params);
|
||||||
FROM {user} u
|
foreach ($internalusers as $internaluser) {
|
||||||
WHERE u.auth=:authtype AND u.deleted=0 AND u.mnethostid=:mnethostid $suspendselect AND u.username $notin_sql";
|
if (!in_array($internaluser->username, $userlist)) {
|
||||||
$params['mnethostid'] = $CFG->mnet_localhost_id;
|
$removeusers[] = $internaluser;
|
||||||
$remove_users = $remove_users + $DB->get_records_sql($sql, $params);
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT u.id, u.username
|
$sql = "SELECT u.id, u.username
|
||||||
|
@ -320,13 +320,13 @@ class auth_plugin_db extends auth_plugin_base {
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['authtype'] = $this->authtype;
|
$params['authtype'] = $this->authtype;
|
||||||
$params['mnethostid'] = $CFG->mnet_localhost_id;
|
$params['mnethostid'] = $CFG->mnet_localhost_id;
|
||||||
$remove_users = $DB->get_records_sql($sql, $params);
|
$removeusers = $DB->get_records_sql($sql, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($remove_users)) {
|
if (!empty($removeusers)) {
|
||||||
$trace->output(get_string('auth_dbuserstoremove','auth_db', count($remove_users)));
|
$trace->output(get_string('auth_dbuserstoremove', 'auth_db', count($removeusers)));
|
||||||
|
|
||||||
foreach ($remove_users as $user) {
|
foreach ($removeusers as $user) {
|
||||||
if ($this->config->removeuser == AUTH_REMOVEUSER_FULLDELETE) {
|
if ($this->config->removeuser == AUTH_REMOVEUSER_FULLDELETE) {
|
||||||
delete_user($user);
|
delete_user($user);
|
||||||
$trace->output(get_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)), 1);
|
$trace->output(get_string('auth_dbdeleteuser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)), 1);
|
||||||
|
@ -339,7 +339,7 @@ class auth_plugin_db extends auth_plugin_base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($remove_users);
|
unset($removeusers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!count($userlist)) {
|
if (!count($userlist)) {
|
||||||
|
@ -933,5 +933,3 @@ class auth_plugin_db extends auth_plugin_base {
|
||||||
return core_user::clean_data($user);
|
return core_user::clean_data($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue