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.
This commit is contained in:
Petr Škoda 2014-01-24 09:59:40 +08:00
parent 8cf30a371a
commit 54b1e0409c
3 changed files with 8 additions and 13 deletions

View File

@ -268,10 +268,8 @@ class auth_ldap_plugin_testcase extends advanced_testcase {
$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 File

@ -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;
}

View File

@ -2452,10 +2452,8 @@ class core_moodlelib_testcase extends advanced_testcase {
$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);
@ -2470,7 +2468,6 @@ class core_moodlelib_testcase extends advanced_testcase {
$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']);