Chris@0: 'entity.manager']; Chris@0: Chris@0: /** Chris@0: * The current account. Chris@0: * Chris@0: * @var \Drupal\Core\Session\AccountInterface Chris@0: */ Chris@0: protected $account; Chris@0: Chris@0: /** Chris@18: * The entity type manager service. Chris@0: * Chris@18: * @var \Drupal\Core\Entity\EntityTypeManagerInterface Chris@0: */ Chris@18: protected $entityTypeManager; Chris@0: Chris@0: /** Chris@0: * Constructs a new UserRequestSubscriber. Chris@0: * Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The current user. Chris@18: * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager Chris@18: * The entity type manager service. Chris@0: */ Chris@18: public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) { Chris@0: $this->account = $account; Chris@18: $this->entityTypeManager = $entity_type_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@18: $storage = $this->entityTypeManager->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: }