Permalink
Browse files

MDL-43905 fix update of user login times

There needs to be only one event during user login.
The timemodified field is not supposed to be updated during login.
  • Loading branch information...
1 parent c5609f6 commit 4d7f209923c6426d853ce818de4e9c4e742314e6 @skodak skodak committed Jan 31, 2014
Showing with 8 additions and 13 deletions.
  1. +2 −4 auth/ldap/tests/plugin_test.php
  2. +4 −4 lib/moodlelib.php
  3. +2 −5 lib/tests/moodlelib_test.php
@@ -268,10 +268,8 @@ public function test_ldap_user_loggedin_event() {
$sink->close();
// Check that the event is valid.
- $this->assertCount(2, $events);
- $event = $events[0];
- $this->assertInstanceOf('\core\event\user_updated', $event);
- $event = $events[1];
+ $this->assertCount(1, $events);
+ $event = reset($events);
$this->assertInstanceOf('\core\event\user_loggedin', $event);
$this->assertEquals('user', $event->objecttable);
$this->assertEquals('2', $event->objectid);
View
@@ -3397,9 +3397,7 @@ function get_user_key($script, $userid, $instance=null, $iprestriction=null, $va
* @return bool Always returns true
*/
function update_user_login_times() {
- global $USER, $DB, $CFG;
-
- require_once($CFG->dirroot.'/user/lib.php');
+ global $USER, $DB;
if (isguestuser()) {
// Do not update guest access times/ips for performance.
@@ -3425,7 +3423,9 @@ function update_user_login_times() {
$USER->lastaccess = $user->lastaccess = $now;
$USER->lastip = $user->lastip = getremoteaddr();
- user_update_user($user, false);
+ // Note: do not call user_update_user() here because this is part of the login process,
+ // the login event means that these fields were updated.
+ $DB->update_record('user', $user);
return true;
}
@@ -2474,10 +2474,8 @@ public function test_complete_user_login() {
$events = $sink->get_events();
$sink->close();
- $this->assertCount(2, $events);
- $event = $events[0];
- $this->assertInstanceOf('\core\event\user_updated', $event);
- $event = $events[1];
+ $this->assertCount(1, $events);
+ $event = reset($events);
$this->assertInstanceOf('\core\event\user_loggedin', $event);
$this->assertEquals('user', $event->objecttable);
$this->assertEquals($user->id, $event->objectid);
@@ -2491,7 +2489,6 @@ public function test_complete_user_login() {
$this->assertTimeCurrent($USER->firstaccess);
$this->assertTimeCurrent($USER->lastaccess);
- $this->assertTimeCurrent($USER->timemodified);
$this->assertTimeCurrent($USER->currentlogin);
$this->assertSame(sesskey(), $USER->sesskey);
$this->assertTimeCurrent($USER->preference['_lastloaded']);

0 comments on commit 4d7f209

Please sign in to comment.