/**
* Sets the last logon time of the given user to right now.
*
* @param ElggUser $user User entity
* @return void
*/
public function setLastLogin(ElggUser $user)
{
$time = $this->getCurrentTime()->getTimestamp();
if ($user->last_login == $time) {
// no change required
return;
}
$query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET\n\t\t\t\tprev_last_login = last_login,\n\t\t\t\tlast_login = :last_login\n\t\t\tWHERE guid = :guid\n\t\t";
$params = [':last_login' => $time, ':guid' => (int) $user->guid];
$user->prev_last_login = $user->last_login;
$user->last_login = $time;
execute_delayed_write_query($query, null, $params);
$this->entity_cache->set($user);
// If we save the user to memcache during this request, then we'll end up with the
// old (incorrect) attributes cached. Hence we want to invalidate as late as possible.
// the user object gets saved
register_shutdown_function(function () use($user) {
$user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'));
});
}