Skip to content
Permalink
Browse files

Merge branch 'w32_MDL-13363_m24_dbuserundelete' of git://github.com/s…

…kodak/moodle
  • Loading branch information...
Aparup Banerjee
Aparup Banerjee committed Aug 8, 2012
2 parents e432bf2 + f0364be commit 80742be46a9d4d2a1582c7c88d51c6092c10aa13
Showing with 14 additions and 18 deletions.
  1. +14 −18 auth/db/auth.php
@@ -349,39 +349,35 @@ function sync_users($do_updates=false, $verbose=false) {
$transaction = $DB->start_delegated_transaction();
foreach($add_users as $user) {
$username = $user;
$user = $this->get_userinfo_asobj($user);
// Do not try to undelete users here, instead select suspending if you ever expect users will reappear.
// prep a few params
$user = $this->get_userinfo_asobj($user);
$user->username = $username;
$user->confirmed = 1;
$user->auth = $this->authtype;
$user->mnethostid = $CFG->mnet_localhost_id;
if (empty($user->lang)) {
$user->lang = $CFG->lang;
}
// maybe the user has been deleted before
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'=>$old_user->username, 'id'=>$old_user->id)));
}
} else {
$user->timecreated = time();
$user->timemodified = $user->timecreated;
$user->timecreated = time();
$user->timemodified = $user->timecreated;
try {
$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)));
}
// if relevant, tag for password generation
if ($this->is_internal()) {
set_user_preference('auth_forcepasswordchange', 1, $id);
set_user_preference('create_password', 1, $id);
} catch (moodle_exception $e) {
if ($verbose) {
mtrace("\t".get_string('auth_dbinsertusererror', 'auth_db', $user->username));
}
}
// if relevant, tag for password generation
if ($this->is_internal()) {
set_user_preference('auth_forcepasswordchange', 1, $id);
set_user_preference('create_password', 1, $id);
}
}
$transaction->allow_commit();
unset($add_users); // free mem

0 comments on commit 80742be

Please sign in to comment.
You can’t perform that action at this time.