diff --git a/auth/ldap/tests/plugin_test.php b/auth/ldap/tests/plugin_test.php index 955b81e8c8da9..13cdcc083b92b 100644 --- a/auth/ldap/tests/plugin_test.php +++ b/auth/ldap/tests/plugin_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); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 2fb79dfd2dc88..66d34f1289a11 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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; } diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index 5894dada6fdd1..fe3325c2bd1db 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -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']);