Elgg\Database\UsersTable::setLastAction PHP Method

setLastAction() public method

Sets the last action time of the given user to right now.
See also: _elgg_session_boot The session boot calls this at the beginning of every request
public setLastAction ( ElggUse\ElggUser $user ) : void
$user ElggUse\ElggUser User entity
return void
    public function setLastAction(ElggUser $user)
    {
        $time = $this->getCurrentTime()->getTimestamp();
        if ($user->last_action == $time) {
            // no change required
            return;
        }
        $query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET\n\t\t\t\tprev_last_action = last_action,\n\t\t\t\tlast_action = :last_action\n\t\t\tWHERE guid = :guid\n\t\t";
        $params = [':last_action' => $time, ':guid' => (int) $user->guid];
        $user->prev_last_action = $user->last_action;
        $user->last_action = $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 (notice the above query is delayed). So it's
        // simplest to just resave the user after all plugin code runs.
        register_shutdown_function(function () use($user, $time) {
            $this->entities->updateLastAction($user, $time);
            // keep entity table in sync
            $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'), $time);
        });
    }