Permalink
Browse files

MDL-30718 add missing timecraeted and timeupdated, fix user undeleting

  • Loading branch information...
1 parent a1d2463 commit 6ac158e9e350560e269040da5726b64fb5881dc7 @skodak skodak committed Dec 27, 2011
Showing with 13 additions and 5 deletions.
  1. +13 −5 auth/db/auth.php
View
18 auth/db/auth.php
@@ -255,6 +255,7 @@ function sync_users($do_updates=false, $verbose=false) {
$updateuser = new stdClass();
$updateuser->id = $user->id;
$updateuser->auth = 'nologin';
+ $updateuser->timemodified = time();
$DB->update_record('user', $updateuser);
if ($verbose) {
mtrace("\t".get_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
@@ -352,7 +353,6 @@ function sync_users($do_updates=false, $verbose=false) {
// prep a few params
$user->username = $username;
- $user->modified = time();
$user->confirmed = 1;
$user->auth = $this->authtype;
$user->mnethostid = $CFG->mnet_localhost_id;
@@ -361,14 +361,17 @@ function sync_users($do_updates=false, $verbose=false) {
}
// 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));
+ 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));
if ($verbose) {
- mtrace("\t".get_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)));
+ mtrace("\t".get_string('auth_dbreviveduser', 'auth_db', array('name'=>$old_user->username, 'id'=>$old_user->id)));
}
} else {
+ $user->timecreated = time();
+ $user->timemodified = $user->timecreated;
$id = $DB->insert_record ('user', $user); // it is truly a new user
if ($verbose) {
mtrace("\t".get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)));
@@ -477,6 +480,7 @@ function update_user_record($username, $updatekeys=false) {
// Ensure userid is not overwritten
$userid = $user->id;
+ $updated = false;
if ($newinfo = $this->get_userinfo($username)) {
$newinfo = truncate_userinfo($newinfo);
@@ -495,10 +499,14 @@ function update_user_record($username, $updatekeys=false) {
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));
}

0 comments on commit 6ac158e

Please sign in to comment.