Skip to content

Commit

Permalink
MDL-32572 skip problematic users in auth_db sync
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 18, 2012
1 parent 45a6d31 commit 3f22e75
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions auth/db/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function sync_users($do_updates=false, $verbose=false) {
if ($verbose) {
mtrace(get_string('auth_dbuserstoadd','auth_db',count($add_users)));
}
$transaction = $DB->start_delegated_transaction();
// Do not use transactions around this foreach, we want to skip problematic users, not revert everything.
foreach($add_users as $user) {
$username = $user;
$user = $this->get_userinfo_asobj($user);
Expand All @@ -372,9 +372,16 @@ function sync_users($do_updates=false, $verbose=false) {
} 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)));
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)));
}
} catch (moodle_exception $e) {
if ($verbose) {
mtrace("\t".get_string('auth_dbinsertusererror', 'auth_db', $user->username));
}
continue;
}
// if relevant, tag for password generation
if ($this->is_internal()) {
Expand All @@ -383,7 +390,6 @@ function sync_users($do_updates=false, $verbose=false) {
}
}
}
$transaction->allow_commit();
unset($add_users); // free mem
}
return 0;
Expand Down

0 comments on commit 3f22e75

Please sign in to comment.