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

BookmarkHandler.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\Bookmark\Bookmark;
12 use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct;
13 use eZ\Publish\SPI\Persistence\Bookmark\Handler as BookmarkHandlerInterface;
14
18 class BookmarkHandler extends AbstractHandler implements BookmarkHandlerInterface
19 {
20 private const BOOKMARK_IDENTIFIER = 'bookmark';
21 private const LOCATION_IDENTIFIER = 'location';
22 private const USER_IDENTIFIER = 'user';
23 private const LOCATION_PATH_IDENTIFIER = 'location_path';
24
28 public function create(CreateStruct $createStruct): Bookmark
29 {
30 $this->logger->logCall(__METHOD__, [
31 'createStruct' => $createStruct,
32 ]);
33
34 return $this->persistenceHandler->bookmarkHandler()->create($createStruct);
35 }
36
40 public function delete(int $bookmarkId): void
41 {
42 $this->logger->logCall(__METHOD__, [
43 'id' => $bookmarkId,
44 ]);
45
46 $this->persistenceHandler->bookmarkHandler()->delete($bookmarkId);
47
48 $this->cache->invalidateTags([
49 $this->cacheIdentifierGenerator->generateTag(self::BOOKMARK_IDENTIFIER, [$bookmarkId]),
50 ]);
51 }
52
56 public function loadByUserIdAndLocationId(int $userId, array $locationIds): array
57 {
58 return $this->getMultipleCacheItems(
59 $locationIds,
60 $this->cacheIdentifierGenerator->generateKey(self::BOOKMARK_IDENTIFIER, [$userId], true) . '-',
61 function (array $missingIds) use ($userId) {
62 $this->logger->logCall(__CLASS__ . '::loadByUserIdAndLocationId', [
63 'userId' => $userId,
64 'locationIds' => $missingIds,
65 ]);
66
67 return $this->persistenceHandler->bookmarkHandler()->loadByUserIdAndLocationId($userId, $missingIds);
68 },
69 function (Bookmark $bookmark) {
70 $tags = [
71 $this->cacheIdentifierGenerator->generateTag(self::BOOKMARK_IDENTIFIER, [$bookmark->id]),
72 $this->cacheIdentifierGenerator->generateTag(self::LOCATION_IDENTIFIER, [$bookmark->locationId]),
73 $this->cacheIdentifierGenerator->generateTag(self::USER_IDENTIFIER, [$bookmark->userId]),
74 ];
75
76 $location = $this->persistenceHandler->locationHandler()->load($bookmark->locationId);
77 $pathIds = $this->locationPathConverter->convertToPathIds($location->pathString);
78 foreach ($pathIds as $pathId) {
79 $tags[] = $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$pathId]);
80 }
81
82 return $tags;
83 }
84 );
85 }
86
90 public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array
91 {
92 $this->logger->logCall(__METHOD__, [
93 'userId' => $userId,
94 'offset' => $offset,
95 'limit' => $limit,
96 ]);
97
98 return $this->persistenceHandler->bookmarkHandler()->loadUserBookmarks($userId, $offset, $limit);
99 }
100
104 public function countUserBookmarks(int $userId): int
105 {
106 $this->logger->logCall(__METHOD__, [
107 'userId' => $userId,
108 ]);
109
110 return $this->persistenceHandler->bookmarkHandler()->countUserBookmarks($userId);
111 }
112
116 public function locationSwapped(int $location1Id, int $location2Id): void
117 {
118 $this->logger->logCall(__METHOD__, [
119 'location1Id' => $location1Id,
120 'location2Id' => $location2Id,
121 ]);
122
123 // Cache clearing is already done by locationHandler
124 $this->persistenceHandler->bookmarkHandler()->locationSwapped($location1Id, $location2Id);
125 }
126 }
eZ\Publish\Core\Persistence\Cache\AbstractHandler
Class AbstractHandler.
Definition: AbstractHandler.php:21
eZ\Publish\Core\Persistence\Cache\AbstractHandler\getMultipleCacheItems
getMultipleCacheItems(array $ids, string $keyPrefix, callable $missingLoader, callable $loadedTagger, array $keySuffixes=[])
Helper for getting multiple cache items in one call and do the id extraction for you.
Definition: AbstractHandler.php:84
eZ\Publish\Core\Persistence\Cache\BookmarkHandler
Definition: BookmarkHandler.php:19
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\loadUserBookmarks
loadUserBookmarks(int $userId, int $offset=0, int $limit=-1)
{Loads bookmarks owned by user.the start offset for paging the number of bookmarked locations returne...
Definition: BookmarkHandler.php:90
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\BOOKMARK_IDENTIFIER
const BOOKMARK_IDENTIFIER
Definition: BookmarkHandler.php:20
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\USER_IDENTIFIER
const USER_IDENTIFIER
Definition: BookmarkHandler.php:22
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\locationSwapped
locationSwapped(int $location1Id, int $location2Id)
{Notifies the underlying engine that a location was swapped.This method triggers the change of the bo...
Definition: BookmarkHandler.php:116
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\LOCATION_IDENTIFIER
const LOCATION_IDENTIFIER
Definition: BookmarkHandler.php:21
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\countUserBookmarks
countUserBookmarks(int $userId)
{Count bookmarks owned by user.int}
Definition: BookmarkHandler.php:104
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\create
create(CreateStruct $createStruct)
{Create a new bookmark.\eZ\Publish\SPI\Persistence\Bookmark\Bookmark}
Definition: BookmarkHandler.php:28
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\LOCATION_PATH_IDENTIFIER
const LOCATION_PATH_IDENTIFIER
Definition: BookmarkHandler.php:23
eZ\Publish\Core\Persistence\Cache\BookmarkHandler\loadByUserIdAndLocationId
loadByUserIdAndLocationId(int $userId, array $locationIds)
{Get bookmark by user id and location id.\eZ\Publish\SPI\Persistence\Bookmark\Bookmark[]}
Definition: BookmarkHandler.php:56
eZ\Publish\SPI\Persistence\Bookmark\Bookmark
Definition: SPI/Persistence/Bookmark/Bookmark.php:14
eZ\Publish\SPI\Persistence\Bookmark\CreateStruct
Definition: SPI/Persistence/Bookmark/CreateStruct.php:14
eZ\Publish\SPI\Persistence\Bookmark\Handler
Definition: SPI/Persistence/Bookmark/Handler.php:12
eZ\Publish\Core\Persistence\Cache
Definition: AbstractHandler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.