1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ContentHandler 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\API\Repository\Values\Content\Relation as APIRelation; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\Handler as ContentHandlerInterface; |
13
|
|
|
use eZ\Publish\SPI\Persistence\Content; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\CreateStruct; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\UpdateStruct; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @see eZ\Publish\SPI\Persistence\Content\Handler |
22
|
|
|
*/ |
23
|
|
|
class ContentHandler extends AbstractHandler implements ContentHandlerInterface |
24
|
|
|
{ |
25
|
|
|
const ALL_TRANSLATIONS_KEY = '0'; |
26
|
|
|
const PUBLISHED_VERSION = 0; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::create |
30
|
|
|
*/ |
31
|
|
|
public function create(CreateStruct $struct) |
32
|
|
|
{ |
33
|
|
|
// Cached on demand when published or loaded |
34
|
|
|
$this->logger->logCall(__METHOD__, array('struct' => $struct)); |
35
|
|
|
|
36
|
|
|
return $this->persistenceHandler->contentHandler()->create($struct); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::createDraftFromVersion |
41
|
|
|
*/ |
42
|
|
|
public function createDraftFromVersion($contentId, $srcVersion, $userId) |
43
|
|
|
{ |
44
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $srcVersion, 'user' => $userId)); |
45
|
|
|
|
46
|
|
|
return $this->persistenceHandler->contentHandler()->createDraftFromVersion($contentId, $srcVersion, $userId); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::copy |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function copy($contentId, $versionNo = null, $newOwnerId = null) |
53
|
|
|
{ |
54
|
|
|
$this->logger->logCall(__METHOD__, array( |
55
|
|
|
'content' => $contentId, |
56
|
|
|
'version' => $versionNo, |
57
|
|
|
'newOwner' => $newOwnerId, |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
return $this->persistenceHandler->contentHandler()->copy($contentId, $versionNo, $newOwnerId); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::load |
65
|
|
|
*/ |
66
|
|
|
public function load($contentId, $version = null, array $translations = null) |
67
|
|
|
{ |
68
|
|
|
$translationsKey = empty($translations) ? self::ALL_TRANSLATIONS_KEY : implode('|', $translations); |
69
|
|
|
$cache = $this->cache->getItem('content', $contentId, $version ?: self::PUBLISHED_VERSION, $translationsKey); |
70
|
|
|
$content = $cache->get(); |
71
|
|
|
if ($cache->isMiss()) { |
72
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $version, 'translations' => $translations)); |
73
|
|
|
$content = $this->persistenceHandler->contentHandler()->load($contentId, $version, $translations); |
|
|
|
|
74
|
|
|
$cache->set($content)->save(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $content; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function loadContentList(array $contentIds, array $translations = null) |
81
|
|
|
{ |
82
|
|
|
// Intentionally not caching until we can handle caching multiple items (see 7.x) |
83
|
|
|
return $this->persistenceHandler->contentHandler()->loadContentList($contentIds, $translations); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadContentInfo |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function loadContentInfo($contentId) |
90
|
|
|
{ |
91
|
|
|
$cache = $this->cache->getItem('content', 'info', $contentId); |
92
|
|
|
$contentInfo = $cache->get(); |
93
|
|
|
if ($cache->isMiss()) { |
94
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId)); |
95
|
|
|
$cache->set($contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($contentId))->save(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $contentInfo; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function loadContentInfoList(array $contentIds) |
102
|
|
|
{ |
103
|
|
|
// Intentionally not caching until we can handle caching multiple items (see 7.x) |
104
|
|
|
return $this->persistenceHandler->contentHandler()->loadContentInfoList($contentIds); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadContentInfoByRemoteId |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
public function loadContentInfoByRemoteId($remoteId) |
111
|
|
|
{ |
112
|
|
|
$cache = $this->cache->getItem('content', 'info', 'remoteId', $remoteId); |
113
|
|
|
$contentInfo = $cache->get(); |
114
|
|
|
if ($cache->isMiss()) { |
115
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $remoteId)); |
116
|
|
|
$cache->set($contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($remoteId))->save(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $contentInfo; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadVersionInfo |
124
|
|
|
*/ |
125
|
|
View Code Duplication |
public function loadVersionInfo($contentId, $versionNo) |
126
|
|
|
{ |
127
|
|
|
$cache = $this->cache->getItem('content', 'info', $contentId, 'versioninfo', $versionNo); |
128
|
|
|
$versionInfo = $cache->get(); |
129
|
|
|
if ($cache->isMiss()) { |
130
|
|
|
$this->logger->logCall(__METHOD__, ['content' => $contentId, 'version' => $versionNo]); |
131
|
|
|
$cache->set($versionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo($contentId, $versionNo))->save(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $versionInfo; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadDraftsForUser |
139
|
|
|
*/ |
140
|
|
|
public function loadDraftsForUser($userId) |
141
|
|
|
{ |
142
|
|
|
$this->logger->logCall(__METHOD__, array('user' => $userId)); |
143
|
|
|
|
144
|
|
|
return $this->persistenceHandler->contentHandler()->loadDraftsForUser($userId); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::setStatus |
149
|
|
|
*/ |
150
|
|
|
public function setStatus($contentId, $status, $version) |
151
|
|
|
{ |
152
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'status' => $status, 'version' => $version)); |
153
|
|
|
$return = $this->persistenceHandler->contentHandler()->setStatus($contentId, $status, $version); |
154
|
|
|
|
155
|
|
|
$this->cache->clear('content', $contentId, $version); |
156
|
|
|
$this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); |
157
|
|
|
if ($status === VersionInfo::STATUS_PUBLISHED) { |
158
|
|
|
$this->cache->clear('content', 'info', $contentId); |
159
|
|
|
$this->cache->clear('content', 'info', 'remoteId'); |
160
|
|
|
} else { |
161
|
|
|
$this->cache->clear('content', 'info', $contentId, 'versioninfo', $version); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $return; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::updateMetadata |
169
|
|
|
*/ |
170
|
|
|
public function updateMetadata($contentId, MetadataUpdateStruct $struct) |
171
|
|
|
{ |
172
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'struct' => $struct)); |
173
|
|
|
|
174
|
|
|
$contentInfo = $this->persistenceHandler->contentHandler()->updateMetadata($contentId, $struct); |
175
|
|
|
|
176
|
|
|
$this->cache->clear('content', $contentId, $contentInfo->currentVersionNo); |
177
|
|
|
$this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); |
178
|
|
|
$this->cache->clear('content', 'info', $contentId); |
179
|
|
|
|
180
|
|
|
if ($struct->remoteId) { |
181
|
|
|
// remote id changed |
182
|
|
|
$this->cache->clear('content', 'info', 'remoteId'); |
183
|
|
|
} else { |
184
|
|
|
$this->cache->clear('content', 'info', 'remoteId', $contentInfo->remoteId); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return $contentInfo; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::updateContent |
192
|
|
|
*/ |
193
|
|
|
public function updateContent($contentId, $versionNo, UpdateStruct $struct) |
194
|
|
|
{ |
195
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo, 'struct' => $struct)); |
196
|
|
|
$content = $this->persistenceHandler->contentHandler()->updateContent($contentId, $versionNo, $struct); |
197
|
|
|
$this->cache->clear('content', $contentId, $versionNo); |
198
|
|
|
$this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); |
199
|
|
|
$this->cache->clear('content', 'info', $contentId, 'versioninfo', $versionNo); |
200
|
|
|
|
201
|
|
|
return $content; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::deleteContent |
206
|
|
|
*/ |
207
|
|
|
public function deleteContent($contentId) |
208
|
|
|
{ |
209
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId)); |
210
|
|
|
|
211
|
|
|
// Load locations and reverse field relations first |
212
|
|
|
$locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentId); |
213
|
|
|
$reverseRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations( |
214
|
|
|
$contentId, |
215
|
|
|
APIRelation::FIELD |
216
|
|
|
); |
217
|
|
|
|
218
|
|
|
$return = $this->persistenceHandler->contentHandler()->deleteContent($contentId); |
219
|
|
|
|
220
|
|
|
// Clear cache of the reversely related Content after main action has executed |
221
|
|
|
foreach ($reverseRelations as $relation) { |
222
|
|
|
$this->cache->clear('content', $relation->sourceContentId); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$this->cache->clear('content', $contentId); |
226
|
|
|
$this->cache->clear('content', 'info', $contentId); |
227
|
|
|
$this->cache->clear('content', 'info', 'remoteId'); |
228
|
|
|
$this->cache->clear('location', 'subtree'); |
229
|
|
|
|
230
|
|
|
foreach ($locations as $location) { |
231
|
|
|
$this->cache->clear('location', $location->id); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return $return; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::deleteVersion |
239
|
|
|
*/ |
240
|
|
|
public function deleteVersion($contentId, $versionNo) |
241
|
|
|
{ |
242
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo)); |
243
|
|
|
$return = $this->persistenceHandler->contentHandler()->deleteVersion($contentId, $versionNo); |
244
|
|
|
|
245
|
|
|
$this->cache->clear('content', $contentId, $versionNo); |
246
|
|
|
$this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); |
247
|
|
|
$this->cache->clear('content', 'info', $contentId); |
248
|
|
|
$this->cache->clear('content', 'info', 'remoteId'); |
249
|
|
|
$this->cache->clear('location', 'subtree'); |
250
|
|
|
|
251
|
|
|
return $return; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::listVersions |
256
|
|
|
*/ |
257
|
|
|
public function listVersions($contentId, $status = null, $limit = -1) |
258
|
|
|
{ |
259
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'status' => $status)); |
260
|
|
|
|
261
|
|
|
return $this->persistenceHandler->contentHandler()->listVersions($contentId, $status, $limit); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::addRelation |
266
|
|
|
*/ |
267
|
|
|
public function addRelation(RelationCreateStruct $relation) |
268
|
|
|
{ |
269
|
|
|
$this->logger->logCall(__METHOD__, array('struct' => $relation)); |
270
|
|
|
|
271
|
|
|
return $this->persistenceHandler->contentHandler()->addRelation($relation); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::removeRelation |
276
|
|
|
*/ |
277
|
|
|
public function removeRelation($relationId, $type) |
278
|
|
|
{ |
279
|
|
|
$this->logger->logCall(__METHOD__, array('relation' => $relationId, 'type' => $type)); |
280
|
|
|
$this->persistenceHandler->contentHandler()->removeRelation($relationId, $type); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadRelations |
285
|
|
|
*/ |
286
|
|
View Code Duplication |
public function loadRelations($sourceContentId, $sourceContentVersionNo = null, $type = null) |
287
|
|
|
{ |
288
|
|
|
$this->logger->logCall( |
289
|
|
|
__METHOD__, |
290
|
|
|
array( |
291
|
|
|
'content' => $sourceContentId, |
292
|
|
|
'version' => $sourceContentVersionNo, |
293
|
|
|
'type' => $type, |
294
|
|
|
) |
295
|
|
|
); |
296
|
|
|
|
297
|
|
|
return $this->persistenceHandler->contentHandler()->loadRelations($sourceContentId, $sourceContentVersionNo, $type); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::loadReverseRelations |
302
|
|
|
*/ |
303
|
|
|
public function loadReverseRelations($destinationContentId, $type = null) |
304
|
|
|
{ |
305
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $destinationContentId, 'type' => $type)); |
306
|
|
|
|
307
|
|
|
return $this->persistenceHandler->contentHandler()->loadReverseRelations($destinationContentId, $type); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Handler::publish |
312
|
|
|
*/ |
313
|
|
|
public function publish($contentId, $versionNo, MetadataUpdateStruct $struct) |
314
|
|
|
{ |
315
|
|
|
$this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo, 'struct' => $struct)); |
316
|
|
|
$content = $this->persistenceHandler->contentHandler()->publish($contentId, $versionNo, $struct); |
317
|
|
|
|
318
|
|
|
$this->cache->clear('content', $contentId); |
319
|
|
|
$this->cache->clear('content', 'info', $contentId); |
320
|
|
|
$this->cache->clear('content', 'info', 'remoteId'); |
321
|
|
|
$this->cache->clear('location', 'subtree'); |
322
|
|
|
|
323
|
|
|
// warm up cache |
324
|
|
|
$contentInfo = $content->versionInfo->contentInfo; |
325
|
|
|
$this->cache |
326
|
|
|
->getItem('content', $contentInfo->id, $content->versionInfo->versionNo, self::ALL_TRANSLATIONS_KEY) |
327
|
|
|
->set($content) |
328
|
|
|
->save(); |
329
|
|
|
$this->cache->getItem('content', 'info', $contentInfo->id)->set($contentInfo)->save(); |
330
|
|
|
|
331
|
|
|
return $content; |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.