Skip to content
Browse files

Merge branch 'w38_MDL-32572_m23_authdbduplicates' of git://github.com…

…/skodak/moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents 85aa469 + 88fbc9a commit 631aedabb4f1e656ac401a5fa1f8bc45deb3a297 @stronk7 stronk7 committed Sep 18, 2012
Showing with 21 additions and 7 deletions.
  1. +21 −7 auth/db/auth.php
View
28 auth/db/auth.php
@@ -65,7 +65,7 @@ function user_login($username, $password) {
$authdb->Close();
// user exists externally
// check username/password internally
- if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
+ if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id, 'auth'=>$this->authtype))) {
return validate_internal_user_password($user, $password);
}
} else {
@@ -191,8 +191,16 @@ function get_userinfo($username) {
* @return bool True on success
*/
function user_update_password($user, $newpassword) {
+ global $DB;
+
if ($this->is_internal()) {
- return update_internal_user_password($user, $newpassword);
+ $puser = $DB->get_record('user', array('id'=>$user->id), '*', MUST_EXIST);
+ if (update_internal_user_password($puser, $newpassword)) {
+ $user->password = $puser->password;
+ return true;
+ } else {
+ return false;
+ }
} else {
// we should have never been called!
return false;
@@ -346,7 +354,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);
@@ -372,9 +380,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()) {
@@ -383,7 +398,6 @@ function sync_users($do_updates=false, $verbose=false) {
}
}
}
- $transaction->allow_commit();
unset($add_users); // free mem
}
return 0;

0 comments on commit 631aeda

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