1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ObjectStateHandler implementation. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Cache; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\Handler as ObjectStateHandlerInterface; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\InputStruct; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler |
16
|
|
|
*/ |
17
|
|
|
class ObjectStateHandler extends AbstractHandler implements ObjectStateHandlerInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function createGroup(InputStruct $input) |
23
|
|
|
{ |
24
|
|
|
$this->logger->logCall(__METHOD__, array('struct' => $input)); |
25
|
|
|
$group = $this->persistenceHandler->objectStateHandler()->createGroup($input); |
26
|
|
|
|
27
|
|
|
$this->cache->deleteItem('ez-state-group-all'); |
28
|
|
|
|
29
|
|
|
return $group; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function loadGroup($groupId) |
36
|
|
|
{ |
37
|
|
|
$cacheItem = $this->cache->getItem('ez-state-group-' . $groupId); |
38
|
|
|
if ($cacheItem->isHit()) { |
39
|
|
|
return $cacheItem->get(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $groupId)); |
43
|
|
|
$group = $this->persistenceHandler->objectStateHandler()->loadGroup($groupId); |
44
|
|
|
|
45
|
|
|
$cacheItem->set($group); |
46
|
|
|
$cacheItem->tag(['state-group-' . $group->id]); |
47
|
|
|
$this->cache->save($cacheItem); |
48
|
|
|
|
49
|
|
|
return $group; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function loadGroupByIdentifier($identifier) |
56
|
|
|
{ |
57
|
|
|
$cacheItem = $this->cache->getItem('ez-state-group-' . $identifier . '-by-identifier'); |
58
|
|
|
if ($cacheItem->isHit()) { |
59
|
|
|
return $cacheItem->get(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $identifier)); |
63
|
|
|
$group = $this->persistenceHandler->objectStateHandler()->loadGroupByIdentifier($identifier); |
64
|
|
|
|
65
|
|
|
$cacheItem->set($group); |
66
|
|
|
$cacheItem->tag(['state-group-' . $group->id]); |
67
|
|
|
$this->cache->save($cacheItem); |
68
|
|
|
|
69
|
|
|
return $group; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function loadAllGroups($offset = 0, $limit = -1) |
76
|
|
|
{ |
77
|
|
|
$cacheItem = $this->cache->getItem('ez-state-group-all'); |
78
|
|
|
if ($cacheItem->isHit()) { |
79
|
|
|
return array_slice($cacheItem->get(), $offset, $limit > -1 ? $limit : null); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->logger->logCall(__METHOD__, array('offset' => $offset, 'limit' => $limit)); |
83
|
|
|
$stateGroups = $this->persistenceHandler->objectStateHandler()->loadAllGroups(0, -1); |
84
|
|
|
|
85
|
|
|
$cacheItem->set($stateGroups); |
86
|
|
|
$cacheTags = []; |
87
|
|
|
foreach ($stateGroups as $group) { |
88
|
|
|
$cacheTags[] = 'state-group-' . $group->id; |
89
|
|
|
} |
90
|
|
|
$cacheItem->tag($cacheTags); |
91
|
|
|
$this->cache->save($cacheItem); |
92
|
|
|
|
93
|
|
|
return array_slice($stateGroups, $offset, $limit > -1 ? $limit : null); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
|
public function loadObjectStates($groupId) |
100
|
|
|
{ |
101
|
|
|
$cacheItem = $this->cache->getItem('ez-state-list-by-group-' . $groupId); |
102
|
|
|
if ($cacheItem->isHit()) { |
103
|
|
|
return $cacheItem->get(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $groupId)); |
107
|
|
|
$objectStates = $this->persistenceHandler->objectStateHandler()->loadObjectStates($groupId); |
108
|
|
|
|
109
|
|
|
$cacheItem->set($objectStates); |
110
|
|
|
$cacheTags = ['state-group-' . $groupId]; |
111
|
|
|
foreach ($objectStates as $state) { |
112
|
|
|
$cacheTags[] = 'state-' . $state->id; |
113
|
|
|
} |
114
|
|
|
$cacheItem->tag($cacheTags); |
115
|
|
|
$this->cache->save($cacheItem); |
116
|
|
|
|
117
|
|
|
return $objectStates; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function updateGroup($groupId, InputStruct $input) |
124
|
|
|
{ |
125
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $groupId, 'struct' => $input)); |
126
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->updateGroup($groupId, $input); |
127
|
|
|
|
128
|
|
|
$this->cache->invalidateTags(['state-group-' . $groupId]); |
129
|
|
|
|
130
|
|
|
return $return; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
|
|
public function deleteGroup($groupId) |
137
|
|
|
{ |
138
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $groupId)); |
139
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->deleteGroup($groupId); |
140
|
|
|
|
141
|
|
|
$this->cache->invalidateTags(['state-group-' . $groupId]); |
142
|
|
|
|
143
|
|
|
return $return; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
*/ |
149
|
|
|
public function create($groupId, InputStruct $input) |
150
|
|
|
{ |
151
|
|
|
$this->logger->logCall(__METHOD__, array('groupId' => $groupId, 'struct' => $input)); |
152
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->create($groupId, $input); |
153
|
|
|
|
154
|
|
|
$this->cache->deleteItem('ez-state-list-by-group-' . $groupId); |
155
|
|
|
|
156
|
|
|
return $return; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
View Code Duplication |
public function load($stateId) |
163
|
|
|
{ |
164
|
|
|
$cacheItem = $this->cache->getItem('ez-state-' . $stateId); |
165
|
|
|
if ($cacheItem->isHit()) { |
166
|
|
|
return $cacheItem->get(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
$this->logger->logCall(__METHOD__, array('stateId' => $stateId)); |
170
|
|
|
$objectState = $this->persistenceHandler->objectStateHandler()->load($stateId); |
171
|
|
|
|
172
|
|
|
$cacheItem->set($objectState); |
173
|
|
|
$cacheItem->tag(['state-' . $objectState->id, 'state-group-' . $objectState->groupId]); |
174
|
|
|
$this->cache->save($cacheItem); |
175
|
|
|
|
176
|
|
|
return $objectState; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* {@inheritdoc} |
181
|
|
|
*/ |
182
|
|
View Code Duplication |
public function loadByIdentifier($identifier, $groupId) |
183
|
|
|
{ |
184
|
|
|
$cacheItem = $this->cache->getItem('ez-state-identifier-' . $identifier . '-by-group-' . $groupId); |
185
|
|
|
if ($cacheItem->isHit()) { |
186
|
|
|
return $cacheItem->get(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$this->logger->logCall(__METHOD__, array('identifier' => $identifier, 'groupId' => $groupId)); |
190
|
|
|
$objectState = $this->persistenceHandler->objectStateHandler()->loadByIdentifier($identifier, $groupId); |
191
|
|
|
|
192
|
|
|
$cacheItem->set($objectState); |
193
|
|
|
$cacheItem->tag(['state-' . $objectState->id, 'state-group-' . $objectState->groupId]); |
194
|
|
|
$this->cache->save($cacheItem); |
195
|
|
|
|
196
|
|
|
return $objectState; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritdoc} |
201
|
|
|
*/ |
202
|
|
|
public function update($stateId, InputStruct $input) |
203
|
|
|
{ |
204
|
|
|
$this->logger->logCall(__METHOD__, array('stateId' => $stateId, 'struct' => $input)); |
205
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->update($stateId, $input); |
206
|
|
|
|
207
|
|
|
$this->cache->invalidateTags(['state-' . $stateId]); |
208
|
|
|
|
209
|
|
|
return $return; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* {@inheritdoc} |
214
|
|
|
*/ |
215
|
|
|
public function setPriority($stateId, $priority) |
216
|
|
|
{ |
217
|
|
|
$this->logger->logCall(__METHOD__, array('stateId' => $stateId, 'priority' => $priority)); |
218
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->setPriority($stateId, $priority); |
219
|
|
|
|
220
|
|
|
$this->cache->invalidateTags(['state-' . $stateId]); |
221
|
|
|
|
222
|
|
|
return $return; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* {@inheritdoc} |
227
|
|
|
*/ |
228
|
|
|
public function delete($stateId) |
229
|
|
|
{ |
230
|
|
|
$this->logger->logCall(__METHOD__, array('stateId' => $stateId)); |
231
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->delete($stateId); |
232
|
|
|
|
233
|
|
|
$this->cache->invalidateTags(['state-' . $stateId]); |
234
|
|
|
|
235
|
|
|
return $return; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* {@inheritdoc} |
240
|
|
|
*/ |
241
|
|
|
public function setContentState($contentId, $groupId, $stateId) |
242
|
|
|
{ |
243
|
|
|
$this->logger->logCall(__METHOD__, array('contentId' => $contentId, 'groupId' => $groupId, 'stateId' => $stateId)); |
244
|
|
|
$return = $this->persistenceHandler->objectStateHandler()->setContentState($contentId, $groupId, $stateId); |
245
|
|
|
|
246
|
|
|
$this->cache->deleteItem('ez-state-by-group-' . $groupId . '-on-content-' . $contentId); |
247
|
|
|
|
248
|
|
|
return $return; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* {@inheritdoc} |
253
|
|
|
*/ |
254
|
|
View Code Duplication |
public function getContentState($contentId, $stateGroupId) |
255
|
|
|
{ |
256
|
|
|
$cacheItem = $this->cache->getItem('ez-state-by-group-' . $stateGroupId . '-on-content-' . $contentId); |
257
|
|
|
if ($cacheItem->isHit()) { |
258
|
|
|
return $cacheItem->get(); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
$this->logger->logCall(__METHOD__, array('contentId' => $contentId, 'stateGroupId' => $stateGroupId)); |
262
|
|
|
$contentState = $this->persistenceHandler->objectStateHandler()->getContentState($contentId, $stateGroupId); |
263
|
|
|
|
264
|
|
|
$cacheItem->set($contentState); |
265
|
|
|
$cacheItem->tag(['state-' . $contentState->id, 'content-' . $contentId]); |
266
|
|
|
$this->cache->save($cacheItem); |
267
|
|
|
|
268
|
|
|
return $contentState; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* {@inheritdoc} |
273
|
|
|
*/ |
274
|
|
|
public function getContentCount($stateId) |
275
|
|
|
{ |
276
|
|
|
$this->logger->logCall(__METHOD__, array('stateId' => $stateId)); |
277
|
|
|
|
278
|
|
|
return $this->persistenceHandler->objectStateHandler()->getContentCount($stateId); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|