Chris@0: account = $account; Chris@0: $this->entityManager = $entity_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Updates the current user's last access time. Chris@0: * Chris@0: * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event Chris@0: * The event to process. Chris@0: */ Chris@0: public function onKernelTerminate(PostResponseEvent $event) { Chris@0: if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { Chris@0: // Do that no more than once per 180 seconds. Chris@0: /** @var \Drupal\user\UserStorageInterface $storage */ Chris@0: $storage = $this->entityManager->getStorage('user'); Chris@0: $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: // Should go before other subscribers start to write their caches. Notably Chris@0: // before \Drupal\Core\EventSubscriber\KernelDestructionSubscriber to Chris@0: // prevent instantiation of destructed services. Chris@0: $events[KernelEvents::TERMINATE][] = ['onKernelTerminate', 300]; Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }