Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 23b7a0a5759d3916ca49d0fd81ebcbfe83fe2c09 1 parent 6d768d0
Petr Skoda skodak authored

Showing 1 changed file with 13 additions and 5 deletions. Show diff stats Hide diff stats

  1. +13 5 auth/db/auth.php
18 auth/db/auth.php
@@ -256,6 +256,7 @@ function sync_users($do_updates=false) {
256 256 $updateuser = new stdClass();
257 257 $updateuser->id = $user->id;
258 258 $updateuser->auth = 'nologin';
  259 + $updateuser->timemodified = time();
259 260 $DB->update_record('user', $updateuser);
260 261 echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
261 262 }
@@ -343,7 +344,6 @@ function sync_users($do_updates=false) {
343 344
344 345 // prep a few params
345 346 $user->username = $username;
346   - $user->modified = time();
347 347 $user->confirmed = 1;
348 348 $user->auth = $this->authtype;
349 349 $user->mnethostid = $CFG->mnet_localhost_id;
@@ -352,12 +352,15 @@ function sync_users($do_updates=false) {
352 352 }
353 353
354 354 // maybe the user has been deleted before
355   - if ($old_user = $DB->get_record('user', array('username'=>$user->username, 'deleted'=>1, 'mnethostid'=>$user->mnethostid))) {
356   - $user->id = $old_user->id;
357   - $DB->set_field('user', 'deleted', 0, array('username'=>$user->username));
358   - echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
  355 + if ($old_user = $DB->get_record('user', array('username'=>$user->username, 'deleted'=>1, 'mnethostid'=>$user->mnethostid, 'auth'=>$user->auth))) {
  356 + // note: this undeleting is deprecated and will be eliminated soon
  357 + $DB->set_field('user', 'deleted', 0, array('id'=>$old_user->id));
  358 + $DB->set_field('user', 'timemodified', time(), array('id'=>$old_user->id));
  359 + echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$old_user->username, 'id'=>$old_user->id)); echo "\n";
359 360
360 361 } else {
  362 + $user->timecreated = time();
  363 + $user->timemodified = $user->timecreated;
361 364 $id = $DB->insert_record ('user',$user); // it is truly a new user
362 365 echo "\t"; print_string('auth_dbinsertuser','auth_db',array('name'=>$user->username, 'id'=>$id)); echo "\n";
363 366 // if relevant, tag for password generation
@@ -463,6 +466,7 @@ function update_user_record($username, $updatekeys=false) {
463 466
464 467 // Ensure userid is not overwritten
465 468 $userid = $user->id;
  469 + $updated = false;
466 470
467 471 if ($newinfo = $this->get_userinfo($username)) {
468 472 $newinfo = truncate_userinfo($newinfo);
@@ -481,10 +485,14 @@ function update_user_record($username, $updatekeys=false) {
481 485 if (!empty($this->config->{'field_updatelocal_' . $key})) {
482 486 if (isset($user->{$key}) and $user->{$key} != $value) { // only update if it's changed
483 487 $DB->set_field('user', $key, $value, array('id'=>$userid));
  488 + $updated = true;
484 489 }
485 490 }
486 491 }
487 492 }
  493 + if ($updated) {
  494 + $DB->set_field('user', 'timemodified', time(), array('id'=>$userid));
  495 + }
488 496 return $DB->get_record('user', array('id'=>$userid, 'deleted'=>0));
489 497 }
490 498

0 comments on commit 23b7a0a

Please sign in to comment.
Something went wrong with that request. Please try again.