Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/src/EventSubscriber/UserRequestSubscriber.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\user\EventSubscriber; | 3 namespace Drupal\user\EventSubscriber; |
4 | 4 |
5 use Drupal\Core\Entity\EntityManagerInterface; | 5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; |
6 use Drupal\Core\Entity\EntityTypeManagerInterface; | |
6 use Drupal\Core\Session\AccountInterface; | 7 use Drupal\Core\Session\AccountInterface; |
7 use Drupal\Core\Site\Settings; | 8 use Drupal\Core\Site\Settings; |
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | 9 use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
9 use Symfony\Component\HttpKernel\Event\PostResponseEvent; | 10 use Symfony\Component\HttpKernel\Event\PostResponseEvent; |
10 use Symfony\Component\HttpKernel\KernelEvents; | 11 use Symfony\Component\HttpKernel\KernelEvents; |
11 | 12 |
12 /** | 13 /** |
13 * Updates the current user's last access time. | 14 * Updates the current user's last access time. |
14 */ | 15 */ |
15 class UserRequestSubscriber implements EventSubscriberInterface { | 16 class UserRequestSubscriber implements EventSubscriberInterface { |
17 use DeprecatedServicePropertyTrait; | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 protected $deprecatedProperties = ['entityManager' => 'entity.manager']; | |
16 | 23 |
17 /** | 24 /** |
18 * The current account. | 25 * The current account. |
19 * | 26 * |
20 * @var \Drupal\Core\Session\AccountInterface | 27 * @var \Drupal\Core\Session\AccountInterface |
21 */ | 28 */ |
22 protected $account; | 29 protected $account; |
23 | 30 |
24 /** | 31 /** |
25 * The entity manager. | 32 * The entity type manager service. |
26 * | 33 * |
27 * @var \Drupal\Core\Entity\EntityManagerInterface | 34 * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
28 */ | 35 */ |
29 protected $entityManager; | 36 protected $entityTypeManager; |
30 | 37 |
31 /** | 38 /** |
32 * Constructs a new UserRequestSubscriber. | 39 * Constructs a new UserRequestSubscriber. |
33 * | 40 * |
34 * @param \Drupal\Core\Session\AccountInterface $account | 41 * @param \Drupal\Core\Session\AccountInterface $account |
35 * The current user. | 42 * The current user. |
36 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | 43 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
37 * The entity manager. | 44 * The entity type manager service. |
38 */ | 45 */ |
39 public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager) { | 46 public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) { |
40 $this->account = $account; | 47 $this->account = $account; |
41 $this->entityManager = $entity_manager; | 48 $this->entityTypeManager = $entity_type_manager; |
42 } | 49 } |
43 | 50 |
44 /** | 51 /** |
45 * Updates the current user's last access time. | 52 * Updates the current user's last access time. |
46 * | 53 * |
49 */ | 56 */ |
50 public function onKernelTerminate(PostResponseEvent $event) { | 57 public function onKernelTerminate(PostResponseEvent $event) { |
51 if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { | 58 if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { |
52 // Do that no more than once per 180 seconds. | 59 // Do that no more than once per 180 seconds. |
53 /** @var \Drupal\user\UserStorageInterface $storage */ | 60 /** @var \Drupal\user\UserStorageInterface $storage */ |
54 $storage = $this->entityManager->getStorage('user'); | 61 $storage = $this->entityTypeManager->getStorage('user'); |
55 $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME); | 62 $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME); |
56 } | 63 } |
57 } | 64 } |
58 | 65 |
59 /** | 66 /** |