From 23b7a0a5759d3916ca49d0fd81ebcbfe83fe2c09 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 27 Dec 2011 15:49:47 +0100 Subject: [PATCH] MDL-30718 add missing timecraeted and timeupdated, fix user undeleting --- auth/db/auth.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 931b4d26682..efc3c46b32d 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -256,6 +256,7 @@ class auth_plugin_db extends auth_plugin_base { $updateuser = new stdClass(); $updateuser->id = $user->id; $updateuser->auth = 'nologin'; + $updateuser->timemodified = time(); $DB->update_record('user', $updateuser); echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; } @@ -343,7 +344,6 @@ class auth_plugin_db extends auth_plugin_base { // prep a few params $user->username = $username; - $user->modified = time(); $user->confirmed = 1; $user->auth = $this->authtype; $user->mnethostid = $CFG->mnet_localhost_id; @@ -352,12 +352,15 @@ class auth_plugin_db extends auth_plugin_base { } // maybe the user has been deleted before - if ($old_user = $DB->get_record('user', array('username'=>$user->username, 'deleted'=>1, 'mnethostid'=>$user->mnethostid))) { - $user->id = $old_user->id; - $DB->set_field('user', 'deleted', 0, array('username'=>$user->username)); - echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n"; + if ($old_user = $DB->get_record('user', array('username'=>$user->username, 'deleted'=>1, 'mnethostid'=>$user->mnethostid, 'auth'=>$user->auth))) { + // note: this undeleting is deprecated and will be eliminated soon + $DB->set_field('user', 'deleted', 0, array('id'=>$old_user->id)); + $DB->set_field('user', 'timemodified', time(), array('id'=>$old_user->id)); + echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$old_user->username, 'id'=>$old_user->id)); echo "\n"; } else { + $user->timecreated = time(); + $user->timemodified = $user->timecreated; $id = $DB->insert_record ('user',$user); // it is truly a new user echo "\t"; print_string('auth_dbinsertuser','auth_db',array('name'=>$user->username, 'id'=>$id)); echo "\n"; // if relevant, tag for password generation @@ -463,6 +466,7 @@ class auth_plugin_db extends auth_plugin_base { // Ensure userid is not overwritten $userid = $user->id; + $updated = false; if ($newinfo = $this->get_userinfo($username)) { $newinfo = truncate_userinfo($newinfo); @@ -481,10 +485,14 @@ class auth_plugin_db extends auth_plugin_base { if (!empty($this->config->{'field_updatelocal_' . $key})) { if (isset($user->{$key}) and $user->{$key} != $value) { // only update if it's changed $DB->set_field('user', $key, $value, array('id'=>$userid)); + $updated = true; } } } } + if ($updated) { + $DB->set_field('user', 'timemodified', time(), array('id'=>$userid)); + } return $DB->get_record('user', array('id'=>$userid, 'deleted'=>0)); }