diff --git a/auth/db/auth.php b/auth/db/auth.php index 0eae7c33593..0463a2c7479 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -381,7 +381,7 @@ class auth_plugin_db extends auth_plugin_base { list($in_sql, $params) = $DB->get_in_or_equal($userlistchunk, SQL_PARAMS_NAMED, 'u', true); $params['authtype'] = $this->authtype; $params['mnethostid'] = $CFG->mnet_localhost_id; - $sql = "SELECT u.id, u.username + $sql = "SELECT u.id, u.username, u.suspended FROM {user} u WHERE u.auth = :authtype AND u.deleted = 0 AND u.mnethostid = :mnethostid AND u.username {$in_sql}"; $update_users = $update_users + $DB->get_records_sql($sql, $params); @@ -391,7 +391,7 @@ class auth_plugin_db extends auth_plugin_base { $trace->output("User entries to update: ".count($update_users)); foreach ($update_users as $user) { - if ($this->update_user_record($user->username, $updatekeys)) { + if ($this->update_user_record($user->username, $updatekeys, false, (bool) $user->suspended)) { $trace->output(get_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)), 1); } else { $trace->output(get_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id))." - ".get_string('skipped'), 1); diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index df4bc3f98ef..a87cc1174ab 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -547,7 +547,9 @@ class auth_plugin_ldap extends auth_plugin_base { // Save any custom profile field information profile_save_data($user); - $this->update_user_record($user->username); + $userinfo = $this->get_userinfo($user->username); + $this->update_user_record($user->username, false, false, $this->is_user_suspended((object) $userinfo)); + // This will also update the stored hash to the latest algorithm // if the existing hash is using an out-of-date algorithm (or the // legacy md5 algorithm). @@ -874,7 +876,9 @@ class auth_plugin_ldap extends auth_plugin_base { foreach ($users as $user) { echo "\t"; print_string('auth_dbupdatinguser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); - if (!$this->update_user_record($user->username, $updatekeys, true)) { + $userinfo = $this->get_userinfo($user->username); + if (!$this->update_user_record($user->username, $updatekeys, true, + $this->is_user_suspended((object) $userinfo))) { echo ' - '.get_string('skipped'); } echo "\n"; diff --git a/lib/authlib.php b/lib/authlib.php index fb31f19d1ee..28ce7e1c818 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -627,9 +627,10 @@ class auth_plugin_base { * @param array $updatekeys fields to update, false updates all fields. * @param bool $triggerevent set false if user_updated event should not be triggered. * This will not affect user_password_updated event triggering. + * @param bool $suspenduser Should the user be suspended? * @return stdClass|bool updated user record or false if there is no new info to update. */ - protected function update_user_record($username, $updatekeys = false, $triggerevent = false) { + protected function update_user_record($username, $updatekeys = false, $triggerevent = false, $suspenduser = false) { global $CFG, $DB; require_once($CFG->dirroot.'/user/profile/lib.php'); @@ -663,6 +664,8 @@ class auth_plugin_base { if (!empty($updatekeys)) { $newuser = new stdClass(); $newuser->id = $userid; + // The cast to int is a workaround for MDL-53959. + $newuser->suspended = (int) $suspenduser; $newuser->profile = array(); foreach ($updatekeys as $key) {