1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
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
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @see \eZ\Publish\SPI\Persistence\Bookmark\Handler |
17
|
|
|
*/ |
18
|
|
|
class BookmarkHandler extends AbstractHandler implements BookmarkHandlerInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public function create(CreateStruct $createStruct): Bookmark |
24
|
|
|
{ |
25
|
|
|
$this->logger->logCall(__METHOD__, [ |
26
|
|
|
'createStruct' => $createStruct, |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
return $this->persistenceHandler->bookmarkHandler()->create($createStruct); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function delete(int $bookmarkId): void |
36
|
|
|
{ |
37
|
|
|
$this->logger->logCall(__METHOD__, [ |
38
|
|
|
'id' => $bookmarkId, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$this->persistenceHandler->bookmarkHandler()->delete($bookmarkId); |
42
|
|
|
|
43
|
|
|
$this->cache->invalidateTags(['bookmark-' . $bookmarkId]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function loadByUserIdAndLocationId(int $userId, array $locationIds): array |
50
|
|
|
{ |
51
|
|
|
return $this->getMultipleCacheItems( |
52
|
|
|
$locationIds, |
53
|
|
|
'ez-bookmark-' . $userId . '-', |
54
|
|
|
function (array $missingIds) use ($userId) { |
55
|
|
|
$this->logger->logCall(__METHOD__, [ |
56
|
|
|
'userId' => $userId, |
57
|
|
|
'locationIds' => $missingIds, |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
return $this->persistenceHandler->bookmarkHandler()->loadByUserIdAndLocationId($userId, $missingIds); |
61
|
|
|
}, |
62
|
|
|
function (Bookmark $bookmark) { |
63
|
|
|
return [ |
64
|
|
|
'bookmark-' . $bookmark->id, |
65
|
|
|
'location-' . $bookmark->locationId, |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array |
75
|
|
|
{ |
76
|
|
|
$this->logger->logCall(__METHOD__, [ |
77
|
|
|
'userId' => $userId, |
78
|
|
|
'offset' => $offset, |
79
|
|
|
'limit' => $limit, |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
return $this->persistenceHandler->bookmarkHandler()->loadUserBookmarks($userId, $offset, $limit); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function countUserBookmarks(int $userId): int |
89
|
|
|
{ |
90
|
|
|
$this->logger->logCall(__METHOD__, [ |
91
|
|
|
'userId' => $userId, |
92
|
|
|
]); |
93
|
|
|
|
94
|
|
|
return $this->persistenceHandler->bookmarkHandler()->countUserBookmarks($userId); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function locationSwapped(int $location1Id, int $location2Id): void |
101
|
|
|
{ |
102
|
|
|
$this->logger->logCall(__METHOD__, [ |
103
|
|
|
'location1Id' => $location1Id, |
104
|
|
|
'location2Id' => $location2Id, |
105
|
|
|
]); |
106
|
|
|
|
107
|
|
|
// Cache clearing is already done by locationHandler |
108
|
|
|
$this->persistenceHandler->bookmarkHandler()->locationSwapped($location1Id, $location2Id); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|