Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

NotificationHandler.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\Persistence\Cache;
10
11 use eZ\Publish\SPI\Persistence\Notification\CreateStruct;
12 use eZ\Publish\SPI\Persistence\Notification\Handler;
13 use eZ\Publish\SPI\Persistence\Notification\Notification;
14 use eZ\Publish\SPI\Persistence\Notification\UpdateStruct;
15 use eZ\Publish\API\Repository\Values\Notification\Notification as APINotification;
16
22 class NotificationHandler extends AbstractHandler implements Handler
23 {
24 private const NOTIFICATION_IDENTIFIER = 'notification';
25 private const NOTIFICATION_COUNT_IDENTIFIER = 'notification_count';
26 private const NOTIFICATION_PENDING_COUNT_IDENTIFIER = 'notification_pending_count';
27
31 public function createNotification(CreateStruct $createStruct): Notification
32 {
33 $this->logger->logCall(__METHOD__, [
34 'createStruct' => $createStruct,
35 ]);
36
37 $this->cache->deleteItems([
38 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_COUNT_IDENTIFIER, [$createStruct->ownerId], true),
39 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_PENDING_COUNT_IDENTIFIER, [$createStruct->ownerId], true),
40 ]);
41
42 return $this->persistenceHandler->notificationHandler()->createNotification($createStruct);
43 }
44
48 public function updateNotification(APINotification $notification, UpdateStruct $updateStruct): Notification
49 {
50 $this->logger->logCall(__METHOD__, [
51 'notificationId' => $notification->id,
52 ]);
53
54 $this->cache->deleteItems([
55 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_IDENTIFIER, [$notification->id], true),
56 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_PENDING_COUNT_IDENTIFIER, [$notification->ownerId], true),
57 ]);
58
59 return $this->persistenceHandler->notificationHandler()->updateNotification($notification, $updateStruct);
60 }
61
65 public function delete(APINotification $notification): void
66 {
67 $this->logger->logCall(__METHOD__, [
68 'notificationId' => $notification->id,
69 ]);
70
71 $this->cache->deleteItems([
72 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_IDENTIFIER, [$notification->id], true),
73 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_COUNT_IDENTIFIER, [$notification->ownerId], true),
74 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_PENDING_COUNT_IDENTIFIER, [$notification->ownerId], true),
75 ]);
76
77 $this->persistenceHandler->notificationHandler()->delete($notification);
78 }
79
83 public function countPendingNotifications(int $ownerId): int
84 {
85 $cacheItem = $this->cache->getItem(
86 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_PENDING_COUNT_IDENTIFIER, [$ownerId], true)
87 );
88
89 $count = $cacheItem->get();
90 if ($cacheItem->isHit()) {
91 return $count;
92 }
93
94 $this->logger->logCall(__METHOD__, [
95 'ownerId' => $ownerId,
96 ]);
97
98 $count = $this->persistenceHandler->notificationHandler()->countPendingNotifications($ownerId);
99
100 $cacheItem->set($count);
101 $this->cache->save($cacheItem);
102
103 return $count;
104 }
105
109 public function countNotifications(int $ownerId): int
110 {
111 $cacheItem = $this->cache->getItem(
112 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_COUNT_IDENTIFIER, [$ownerId], true)
113 );
114
115 $count = $cacheItem->get();
116 if ($cacheItem->isHit()) {
117 return $count;
118 }
119
120 $this->logger->logCall(__METHOD__, [
121 'ownerId' => $ownerId,
122 ]);
123
124 $count = $this->persistenceHandler->notificationHandler()->countNotifications($ownerId);
125
126 $cacheItem->set($count);
127 $this->cache->save($cacheItem);
128
129 return $count;
130 }
131
135 public function getNotificationById(int $notificationId): Notification
136 {
137 $cacheItem = $this->cache->getItem(
138 $this->cacheIdentifierGenerator->generateKey(self::NOTIFICATION_IDENTIFIER, [$notificationId], true)
139 );
140
141 $notification = $cacheItem->get();
142 if ($cacheItem->isHit()) {
143 return $notification;
144 }
145
146 $this->logger->logCall(__METHOD__, [
147 'notificationId' => $notificationId,
148 ]);
149
150 $notification = $this->persistenceHandler->notificationHandler()->getNotificationById($notificationId);
151
152 $cacheItem->set($notification);
153 $this->cache->save($cacheItem);
154
155 return $notification;
156 }
157
161 public function loadUserNotifications(int $userId, int $offset, int $limit): array
162 {
163 $this->logger->logCall(__METHOD__, [
164 'ownerId' => $userId,
165 'offset' => $offset,
166 'limit' => $limit,
167 ]);
168
169 return $this->persistenceHandler->notificationHandler()->loadUserNotifications($userId, $offset, $limit);
170 }
171 }
eZ\Publish\API\Repository\Values\Notification\Notification
Definition: API/Repository/Values/Notification/Notification.php:24
eZ\Publish\Core\Persistence\Cache\AbstractHandler
Class AbstractHandler.
Definition: AbstractHandler.php:21
eZ\Publish\Core\Persistence\Cache\Handler
Persistence Cache Handler class.
Definition: Core/Persistence/Cache/Handler.php:32
eZ\Publish\Core\Persistence\Cache\NotificationHandler
SPI cache for Notification Handler.
Definition: NotificationHandler.php:23
eZ\Publish\Core\Persistence\Cache\NotificationHandler\getNotificationById
getNotificationById(int $notificationId)
{}
Definition: NotificationHandler.php:135
eZ\Publish\Core\Persistence\Cache\NotificationHandler\countNotifications
countNotifications(int $ownerId)
{}
Definition: NotificationHandler.php:109
eZ\Publish\Core\Persistence\Cache\NotificationHandler\loadUserNotifications
loadUserNotifications(int $userId, int $offset, int $limit)
{}
Definition: NotificationHandler.php:161
eZ\Publish\Core\Persistence\Cache\NotificationHandler\countPendingNotifications
countPendingNotifications(int $ownerId)
{}
Definition: NotificationHandler.php:83
eZ\Publish\Core\Persistence\Cache\NotificationHandler\NOTIFICATION_PENDING_COUNT_IDENTIFIER
const NOTIFICATION_PENDING_COUNT_IDENTIFIER
Definition: NotificationHandler.php:26
eZ\Publish\Core\Persistence\Cache\NotificationHandler\NOTIFICATION_IDENTIFIER
const NOTIFICATION_IDENTIFIER
Definition: NotificationHandler.php:24
eZ\Publish\Core\Persistence\Cache\NotificationHandler\updateNotification
updateNotification(APINotification $notification, UpdateStruct $updateStruct)
{}
Definition: NotificationHandler.php:48
eZ\Publish\Core\Persistence\Cache\NotificationHandler\NOTIFICATION_COUNT_IDENTIFIER
const NOTIFICATION_COUNT_IDENTIFIER
Definition: NotificationHandler.php:25
eZ\Publish\Core\Persistence\Cache\NotificationHandler\createNotification
createNotification(CreateStruct $createStruct)
{}
Definition: NotificationHandler.php:31
eZ\Publish\SPI\Persistence\Bookmark\CreateStruct
Definition: SPI/Persistence/Bookmark/CreateStruct.php:14
eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct
Definition: Content/Location/UpdateStruct.php:12
eZ\Publish\SPI\Persistence\Notification\CreateStruct
Definition: SPI/Persistence/Notification/CreateStruct.php:14
eZ\Publish\SPI\Persistence\Notification\Notification
Definition: SPI/Persistence/Notification/Notification.php:14
eZ\Publish\SPI\Persistence\Notification\UpdateStruct
Definition: Notification/UpdateStruct.php:14
eZ\Publish\SPI\Persistence\Notification\Handler
Definition: SPI/Persistence/Notification/Handler.php:14
eZ\Publish\Core\Persistence\Cache
Definition: AbstractHandler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.