function UserRequestSubscriber::onKernelTerminate

Same name in other branches
  1. 8.9.x core/modules/user/src/EventSubscriber/UserRequestSubscriber.php \Drupal\user\EventSubscriber\UserRequestSubscriber::onKernelTerminate()
  2. 10 core/modules/user/src/EventSubscriber/UserRequestSubscriber.php \Drupal\user\EventSubscriber\UserRequestSubscriber::onKernelTerminate()
  3. 11.x core/modules/user/src/EventSubscriber/UserRequestSubscriber.php \Drupal\user\EventSubscriber\UserRequestSubscriber::onKernelTerminate()

Updates the current user's last access time.

Parameters

\Symfony\Component\HttpKernel\Event\TerminateEvent $event: The event to process.

File

core/modules/user/src/EventSubscriber/UserRequestSubscriber.php, line 50

Class

UserRequestSubscriber
Updates the current user's last access time.

Namespace

Drupal\user\EventSubscriber

Code

public function onKernelTerminate(TerminateEvent $event) {
    if ($this->account
        ->isAuthenticated() && REQUEST_TIME - $this->account
        ->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
        // Do that no more than once per 180 seconds.
        
        /** @var \Drupal\user\UserStorageInterface $storage */
        $storage = $this->entityTypeManager
            ->getStorage('user');
        $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.