Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
59 | class ContentService implements ContentServiceInterface |
||
60 | { |
||
61 | /** @var \eZ\Publish\Core\Repository\Repository */ |
||
62 | protected $repository; |
||
63 | |||
64 | /** @var \eZ\Publish\SPI\Persistence\Handler */ |
||
65 | protected $persistenceHandler; |
||
66 | |||
67 | /** @var array */ |
||
68 | protected $settings; |
||
69 | |||
70 | /** @var \eZ\Publish\Core\Repository\Helper\DomainMapper */ |
||
71 | protected $domainMapper; |
||
72 | |||
73 | /** @var \eZ\Publish\Core\Repository\Helper\RelationProcessor */ |
||
74 | protected $relationProcessor; |
||
75 | |||
76 | /** @var \eZ\Publish\Core\Repository\Helper\NameSchemaService */ |
||
77 | protected $nameSchemaService; |
||
78 | |||
79 | /** @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry */ |
||
80 | protected $fieldTypeRegistry; |
||
81 | |||
82 | /** |
||
83 | * Setups service with reference to repository object that created it & corresponding handler. |
||
84 | * |
||
85 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
86 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
87 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
88 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
89 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
90 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|||
91 | * @param array $settings |
||
92 | */ |
||
93 | public function __construct( |
||
94 | RepositoryInterface $repository, |
||
95 | Handler $handler, |
||
96 | Helper\DomainMapper $domainMapper, |
||
97 | Helper\RelationProcessor $relationProcessor, |
||
98 | Helper\NameSchemaService $nameSchemaService, |
||
99 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
100 | array $settings = [] |
||
101 | ) { |
||
102 | $this->repository = $repository; |
||
103 | $this->persistenceHandler = $handler; |
||
104 | $this->domainMapper = $domainMapper; |
||
105 | $this->relationProcessor = $relationProcessor; |
||
106 | $this->nameSchemaService = $nameSchemaService; |
||
107 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
108 | // Union makes sure default settings are ignored if provided in argument |
||
109 | $this->settings = $settings + [ |
||
110 | // Version archive limit (0-50), only enforced on publish, not on un-publish. |
||
111 | 'default_version_archive_limit' => 5, |
||
112 | ]; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Loads a content info object. |
||
117 | * |
||
118 | * To load fields use loadContent |
||
119 | * |
||
120 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
121 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
122 | * |
||
123 | * @param int $contentId |
||
124 | * |
||
125 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
126 | */ |
||
127 | public function loadContentInfo($contentId) |
||
128 | { |
||
129 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
130 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
131 | throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); |
||
132 | } |
||
133 | |||
134 | return $contentInfo; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function loadContentInfoList(array $contentIds): iterable |
||
141 | { |
||
142 | $contentInfoList = []; |
||
143 | $spiInfoList = $this->persistenceHandler->contentHandler()->loadContentInfoList($contentIds); |
||
144 | foreach ($spiInfoList as $id => $spiInfo) { |
||
145 | $contentInfo = $this->domainMapper->buildContentInfoDomainObject($spiInfo); |
||
146 | if ($this->repository->canUser('content', 'read', $contentInfo)) { |
||
147 | $contentInfoList[$id] = $contentInfo; |
||
148 | } |
||
149 | } |
||
150 | |||
151 | return $contentInfoList; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Loads a content info object. |
||
156 | * |
||
157 | * To load fields use loadContent |
||
158 | * |
||
159 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
160 | * |
||
161 | * @param mixed $id |
||
162 | * @param bool $isRemoteId |
||
163 | * |
||
164 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
165 | */ |
||
166 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
167 | { |
||
168 | try { |
||
169 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
170 | |||
171 | return $this->domainMapper->buildContentInfoDomainObject( |
||
172 | $this->persistenceHandler->contentHandler()->$method($id) |
||
173 | ); |
||
174 | } catch (APINotFoundException $e) { |
||
175 | throw new NotFoundException( |
||
176 | 'Content', |
||
177 | $id, |
||
178 | $e |
||
179 | ); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Loads a content info object for the given remoteId. |
||
185 | * |
||
186 | * To load fields use loadContent |
||
187 | * |
||
188 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
189 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
190 | * |
||
191 | * @param string $remoteId |
||
192 | * |
||
193 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
194 | */ |
||
195 | public function loadContentInfoByRemoteId($remoteId) |
||
196 | { |
||
197 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
198 | |||
199 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
200 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
201 | } |
||
202 | |||
203 | return $contentInfo; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Loads a version info of the given content object. |
||
208 | * |
||
209 | * If no version number is given, the method returns the current version |
||
210 | * |
||
211 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
212 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
213 | * |
||
214 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
215 | * @param int $versionNo the version number. If not given the current version is returned. |
||
216 | * |
||
217 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
218 | */ |
||
219 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
220 | { |
||
221 | return $this->loadVersionInfoById($contentInfo->id, $versionNo); |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * Loads a version info of the given content object id. |
||
226 | * |
||
227 | * If no version number is given, the method returns the current version |
||
228 | * |
||
229 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
230 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
231 | * |
||
232 | * @param mixed $contentId |
||
233 | * @param int $versionNo the version number. If not given the current version is returned. |
||
234 | * |
||
235 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
236 | */ |
||
237 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
238 | { |
||
239 | try { |
||
240 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
241 | $contentId, |
||
242 | $versionNo |
||
243 | ); |
||
244 | } catch (APINotFoundException $e) { |
||
245 | throw new NotFoundException( |
||
246 | 'VersionInfo', |
||
247 | [ |
||
248 | 'contentId' => $contentId, |
||
249 | 'versionNo' => $versionNo, |
||
250 | ], |
||
251 | $e |
||
252 | ); |
||
253 | } |
||
254 | |||
255 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
256 | |||
257 | if ($versionInfo->isPublished()) { |
||
258 | $function = 'read'; |
||
259 | } else { |
||
260 | $function = 'versionread'; |
||
261 | } |
||
262 | |||
263 | if (!$this->repository->canUser('content', $function, $versionInfo)) { |
||
264 | throw new UnauthorizedException('content', $function, ['contentId' => $contentId]); |
||
265 | } |
||
266 | |||
267 | return $versionInfo; |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * {@inheritdoc} |
||
272 | */ |
||
273 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
274 | { |
||
275 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
276 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
277 | $useAlwaysAvailable = false; |
||
278 | } |
||
279 | |||
280 | return $this->loadContent( |
||
281 | $contentInfo->id, |
||
282 | $languages, |
||
283 | $versionNo,// On purpose pass as-is and not use $contentInfo, to make sure to return actual current version on null |
||
284 | $useAlwaysAvailable |
||
285 | ); |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
305 | |||
306 | /** |
||
307 | * {@inheritdoc} |
||
308 | */ |
||
309 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
310 | { |
||
311 | $content = $this->internalLoadContent($contentId, $languages, $versionNo, false, $useAlwaysAvailable); |
||
312 | |||
313 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
314 | throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); |
||
315 | } |
||
316 | if ( |
||
317 | !$content->getVersionInfo()->isPublished() |
||
318 | && !$this->repository->canUser('content', 'versionread', $content) |
||
319 | ) { |
||
320 | throw new UnauthorizedException('content', 'versionread', ['contentId' => $contentId, 'versionNo' => $versionNo]); |
||
321 | } |
||
322 | |||
323 | return $content; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Loads content in a version of the given content object. |
||
328 | * |
||
329 | * If no version number is given, the method returns the current version |
||
330 | * |
||
331 | * @internal |
||
332 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
333 | * |
||
334 | * @param mixed $id |
||
335 | * @param array|null $languages A language priority, filters returned fields and is used as prioritized language code on |
||
336 | * returned value object. If not given all languages are returned. |
||
337 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
338 | * @param bool $isRemoteId |
||
339 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
340 | * |
||
341 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
342 | */ |
||
343 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
344 | { |
||
345 | try { |
||
346 | // Get Content ID if lookup by remote ID |
||
347 | if ($isRemoteId) { |
||
348 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
349 | $id = $spiContentInfo->id; |
||
350 | // Set $isRemoteId to false as the next loads will be for content id now that we have it (for exception use now) |
||
351 | $isRemoteId = false; |
||
352 | } |
||
353 | |||
354 | $loadLanguages = $languages; |
||
355 | $alwaysAvailableLanguageCode = null; |
||
356 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
357 | // @todo Move use always available logic to SPI load methods, like done in location handler in 7.x |
||
358 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
359 | if (!isset($spiContentInfo)) { |
||
360 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
361 | } |
||
362 | |||
363 | if ($spiContentInfo->alwaysAvailable) { |
||
364 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
365 | $loadLanguages = array_unique($loadLanguages); |
||
366 | } |
||
367 | } |
||
368 | |||
369 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
370 | $id, |
||
371 | $versionNo, |
||
372 | $loadLanguages |
||
373 | ); |
||
374 | } catch (APINotFoundException $e) { |
||
375 | throw new NotFoundException( |
||
376 | 'Content', |
||
377 | [ |
||
378 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
379 | 'languages' => $languages, |
||
380 | 'versionNo' => $versionNo, |
||
381 | ], |
||
382 | $e |
||
383 | ); |
||
384 | } |
||
385 | |||
386 | if ($languages === null) { |
||
387 | $languages = []; |
||
388 | } |
||
389 | |||
390 | return $this->domainMapper->buildContentDomainObject( |
||
391 | $spiContent, |
||
392 | $this->repository->getContentTypeService()->loadContentType( |
||
393 | $spiContent->versionInfo->contentInfo->contentTypeId, |
||
394 | $languages |
||
395 | ), |
||
396 | $languages, |
||
397 | $alwaysAvailableLanguageCode |
||
398 | ); |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * Loads content in a version for the content object reference by the given remote id. |
||
403 | * |
||
404 | * If no version is given, the method returns the current version |
||
405 | * |
||
406 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
407 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
408 | * |
||
409 | * @param string $remoteId |
||
410 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
411 | * @param int $versionNo the version number. If not given the current version is returned |
||
412 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
413 | * |
||
414 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
415 | */ |
||
416 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
417 | { |
||
418 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable); |
||
419 | |||
420 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
421 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
422 | } |
||
423 | |||
424 | if ( |
||
425 | !$content->getVersionInfo()->isPublished() |
||
426 | && !$this->repository->canUser('content', 'versionread', $content) |
||
427 | ) { |
||
428 | throw new UnauthorizedException('content', 'versionread', ['remoteId' => $remoteId, 'versionNo' => $versionNo]); |
||
429 | } |
||
430 | |||
431 | return $content; |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
436 | * |
||
437 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
438 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
439 | * allowed to access every Content on the list. |
||
440 | * |
||
441 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
442 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
443 | * returned value object. If not given all languages are returned. |
||
444 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
445 | * unless all languages have been asked for. |
||
446 | * |
||
447 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
448 | */ |
||
449 | public function loadContentListByContentInfo( |
||
450 | array $contentInfoList, |
||
451 | array $languages = [], |
||
452 | $useAlwaysAvailable = true |
||
453 | ) { |
||
454 | $loadAllLanguages = $languages === Language::ALL; |
||
455 | $contentIds = []; |
||
456 | $contentTypeIds = []; |
||
457 | $translations = $languages; |
||
458 | foreach ($contentInfoList as $contentInfo) { |
||
459 | $contentIds[] = $contentInfo->id; |
||
460 | $contentTypeIds[] = $contentInfo->contentTypeId; |
||
461 | // Unless we are told to load all languages, we add main language to translations so they are loaded too |
||
462 | // Might in some case load more languages then intended, but prioritised handling will pick right one |
||
463 | if (!$loadAllLanguages && $useAlwaysAvailable && $contentInfo->alwaysAvailable) { |
||
464 | $translations[] = $contentInfo->mainLanguageCode; |
||
465 | } |
||
466 | } |
||
467 | |||
468 | $contentList = []; |
||
469 | $translations = array_unique($translations); |
||
470 | $spiContentList = $this->persistenceHandler->contentHandler()->loadContentList( |
||
471 | $contentIds, |
||
472 | $translations |
||
473 | ); |
||
474 | $contentTypeList = $this->repository->getContentTypeService()->loadContentTypeList( |
||
475 | array_unique($contentTypeIds), |
||
476 | $languages |
||
477 | ); |
||
478 | foreach ($spiContentList as $contentId => $spiContent) { |
||
479 | $contentInfo = $spiContent->versionInfo->contentInfo; |
||
480 | $contentList[$contentId] = $this->domainMapper->buildContentDomainObject( |
||
481 | $spiContent, |
||
482 | $contentTypeList[$contentInfo->contentTypeId], |
||
483 | $languages, |
||
484 | $contentInfo->alwaysAvailable ? $contentInfo->mainLanguageCode : null |
||
485 | ); |
||
486 | } |
||
487 | |||
488 | return $contentList; |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * Creates a new content draft assigned to the authenticated user. |
||
493 | * |
||
494 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
495 | * but this required special rights for the authenticated user |
||
496 | * (this is useful for content staging where the transfer process does not |
||
497 | * have to authenticate with the user which created the content object in the source server). |
||
498 | * The user has to publish the draft if it should be visible. |
||
499 | * In 4.x at least one location has to be provided in the location creation array. |
||
500 | * |
||
501 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
502 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
503 | * struct are missing or invalid, or if multiple locations are under the |
||
504 | * same parent. |
||
505 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
506 | * or if a required field is missing / set to an empty value. |
||
507 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
508 | * or value is set for non-translatable field in language |
||
509 | * other than main. |
||
510 | * |
||
511 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
512 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
513 | * |
||
514 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
515 | */ |
||
516 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = []) |
||
517 | { |
||
518 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
519 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
520 | } |
||
521 | |||
522 | if ($contentCreateStruct->contentType === null) { |
||
523 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
524 | } |
||
525 | |||
526 | $contentCreateStruct = clone $contentCreateStruct; |
||
527 | |||
528 | if ($contentCreateStruct->ownerId === null) { |
||
529 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
530 | } |
||
531 | |||
532 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
533 | $contentCreateStruct->alwaysAvailable = $contentCreateStruct->contentType->defaultAlwaysAvailable ?: false; |
||
534 | } |
||
535 | |||
536 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
537 | $contentCreateStruct->contentType->id |
||
538 | ); |
||
539 | |||
540 | if (empty($contentCreateStruct->sectionId)) { |
||
541 | if (isset($locationCreateStructs[0])) { |
||
542 | $location = $this->repository->getLocationService()->loadLocation( |
||
543 | $locationCreateStructs[0]->parentLocationId |
||
544 | ); |
||
545 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
546 | } else { |
||
547 | $contentCreateStruct->sectionId = 1; |
||
548 | } |
||
549 | } |
||
550 | |||
551 | if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
552 | throw new UnauthorizedException( |
||
553 | 'content', |
||
554 | 'create', |
||
555 | [ |
||
556 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
557 | $locationCreateStructs[0]->parentLocationId : |
||
558 | null, |
||
559 | 'sectionId' => $contentCreateStruct->sectionId, |
||
560 | ] |
||
561 | ); |
||
562 | } |
||
563 | |||
564 | if (!empty($contentCreateStruct->remoteId)) { |
||
565 | try { |
||
566 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
567 | |||
568 | throw new InvalidArgumentException( |
||
569 | '$contentCreateStruct', |
||
570 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
571 | ); |
||
572 | } catch (APINotFoundException $e) { |
||
573 | // Do nothing |
||
574 | } |
||
575 | } else { |
||
576 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
577 | } |
||
578 | |||
579 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
580 | |||
581 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
582 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
583 | |||
584 | $fieldValues = []; |
||
585 | $spiFields = []; |
||
586 | $allFieldErrors = []; |
||
587 | $inputRelations = []; |
||
588 | $locationIdToContentIdMapping = []; |
||
589 | |||
590 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
591 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
592 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
593 | $fieldDefinition->fieldTypeIdentifier |
||
594 | ); |
||
595 | |||
596 | foreach ($languageCodes as $languageCode) { |
||
597 | $isEmptyValue = false; |
||
598 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
599 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
600 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
601 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
602 | } else { |
||
603 | $fieldValue = $fieldDefinition->defaultValue; |
||
604 | } |
||
605 | |||
606 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
607 | |||
608 | if ($fieldType->isEmptyValue($fieldValue)) { |
||
609 | $isEmptyValue = true; |
||
610 | if ($fieldDefinition->isRequired) { |
||
611 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
612 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
613 | null, |
||
614 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
615 | 'empty' |
||
616 | ); |
||
617 | } |
||
618 | } else { |
||
619 | $fieldErrors = $fieldType->validate( |
||
620 | $fieldDefinition, |
||
621 | $fieldValue |
||
622 | ); |
||
623 | if (!empty($fieldErrors)) { |
||
624 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
625 | } |
||
626 | } |
||
627 | |||
628 | if (!empty($allFieldErrors)) { |
||
629 | continue; |
||
630 | } |
||
631 | |||
632 | $this->relationProcessor->appendFieldRelations( |
||
633 | $inputRelations, |
||
634 | $locationIdToContentIdMapping, |
||
635 | $fieldType, |
||
636 | $fieldValue, |
||
637 | $fieldDefinition->id |
||
638 | ); |
||
639 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
640 | |||
641 | // Only non-empty value for: translatable field or in main language |
||
642 | if ( |
||
643 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
644 | (!$isEmptyValue && $isLanguageMain) |
||
645 | ) { |
||
646 | $spiFields[] = new SPIField( |
||
647 | [ |
||
648 | 'id' => null, |
||
649 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
650 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
651 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
652 | 'languageCode' => $languageCode, |
||
653 | 'versionNo' => null, |
||
654 | ] |
||
655 | ); |
||
656 | } |
||
657 | } |
||
658 | } |
||
659 | |||
660 | if (!empty($allFieldErrors)) { |
||
661 | throw new ContentFieldValidationException($allFieldErrors); |
||
662 | } |
||
663 | |||
664 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
665 | [ |
||
666 | 'name' => $this->nameSchemaService->resolve( |
||
667 | $contentCreateStruct->contentType->nameSchema, |
||
668 | $contentCreateStruct->contentType, |
||
669 | $fieldValues, |
||
670 | $languageCodes |
||
671 | ), |
||
672 | 'typeId' => $contentCreateStruct->contentType->id, |
||
673 | 'sectionId' => $contentCreateStruct->sectionId, |
||
674 | 'ownerId' => $contentCreateStruct->ownerId, |
||
675 | 'locations' => $spiLocationCreateStructs, |
||
676 | 'fields' => $spiFields, |
||
677 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
678 | 'remoteId' => $contentCreateStruct->remoteId, |
||
679 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
680 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
681 | $contentCreateStruct->mainLanguageCode |
||
682 | )->id, |
||
683 | ] |
||
684 | ); |
||
685 | |||
686 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
687 | |||
688 | $this->repository->beginTransaction(); |
||
689 | try { |
||
690 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
691 | $this->relationProcessor->processFieldRelations( |
||
692 | $inputRelations, |
||
693 | $spiContent->versionInfo->contentInfo->id, |
||
694 | $spiContent->versionInfo->versionNo, |
||
695 | $contentCreateStruct->contentType |
||
696 | ); |
||
697 | |||
698 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
699 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
700 | $objectStateHandler->setContentState( |
||
701 | $spiContent->versionInfo->contentInfo->id, |
||
702 | $objectStateGroupId, |
||
703 | $objectState->id |
||
704 | ); |
||
705 | } |
||
706 | |||
707 | $this->repository->commit(); |
||
708 | } catch (Exception $e) { |
||
709 | $this->repository->rollback(); |
||
710 | throw $e; |
||
711 | } |
||
712 | |||
713 | return $this->domainMapper->buildContentDomainObject( |
||
714 | $spiContent, |
||
715 | $contentCreateStruct->contentType |
||
716 | ); |
||
717 | } |
||
718 | |||
719 | /** |
||
720 | * Returns an array of default content states with content state group id as key. |
||
721 | * |
||
722 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
723 | */ |
||
724 | protected function getDefaultObjectStates() |
||
739 | |||
740 | /** |
||
741 | * Returns all language codes used in given $fields. |
||
742 | * |
||
743 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
744 | * |
||
745 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
746 | * |
||
747 | * @return string[] |
||
748 | */ |
||
749 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
773 | |||
774 | /** |
||
775 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
776 | * |
||
777 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
778 | * or value is set for non-translatable field in language |
||
779 | * other than main |
||
780 | * |
||
781 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
782 | * |
||
783 | * @return array |
||
784 | */ |
||
785 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
786 | { |
||
787 | $fields = []; |
||
788 | |||
789 | foreach ($contentCreateStruct->fields as $field) { |
||
790 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier); |
||
791 | |||
792 | if ($fieldDefinition === null) { |
||
793 | throw new ContentValidationException( |
||
794 | "Field definition '%identifier%' does not exist in given ContentType", |
||
795 | ['%identifier%' => $field->fieldDefIdentifier] |
||
796 | ); |
||
797 | } |
||
798 | |||
799 | if ($field->languageCode === null) { |
||
800 | $field = $this->cloneField( |
||
801 | $field, |
||
802 | ['languageCode' => $contentCreateStruct->mainLanguageCode] |
||
803 | ); |
||
804 | } |
||
805 | |||
806 | if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { |
||
807 | throw new ContentValidationException( |
||
808 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'", |
||
809 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode] |
||
810 | ); |
||
811 | } |
||
812 | |||
813 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
814 | } |
||
815 | |||
816 | return $fields; |
||
817 | } |
||
818 | |||
819 | /** |
||
820 | * Clones $field with overriding specific properties from given $overrides array. |
||
821 | * |
||
822 | * @param Field $field |
||
823 | * @param array $overrides |
||
824 | * |
||
825 | * @return Field |
||
826 | */ |
||
827 | private function cloneField(Field $field, array $overrides = []) |
||
842 | |||
843 | /** |
||
844 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
845 | * |
||
846 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
847 | * |
||
848 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
849 | */ |
||
850 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
892 | |||
893 | /** |
||
894 | * Updates the metadata. |
||
895 | * |
||
896 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
897 | * |
||
898 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
899 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
900 | * |
||
901 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
902 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
903 | * |
||
904 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
905 | */ |
||
906 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
993 | |||
994 | /** |
||
995 | * Publishes URL aliases for all locations of a given content. |
||
996 | * |
||
997 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
998 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
999 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
1000 | */ |
||
1001 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
1027 | |||
1028 | /** |
||
1029 | * Deletes a content object including all its versions and locations including their subtrees. |
||
1030 | * |
||
1031 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) |
||
1032 | * |
||
1033 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1034 | * |
||
1035 | * @return mixed[] Affected Location Id's |
||
1036 | */ |
||
1037 | public function deleteContent(ContentInfo $contentInfo) |
||
1064 | |||
1065 | /** |
||
1066 | * Creates a draft from a published or archived version. |
||
1067 | * |
||
1068 | * If no version is given, the current published version is used. |
||
1069 | * |
||
1070 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1071 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1072 | * @param \eZ\Publish\API\Repository\Values\User\User $creator if set given user is used to create the draft - otherwise the current-user is used |
||
1073 | * @param \eZ\Publish\API\Repository\Values\Content\Language|null if not set the draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
1074 | * |
||
1075 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
1076 | * |
||
1077 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
1078 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the current-user is not allowed to create the draft |
||
1079 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
1080 | */ |
||
1081 | public function createContentDraft( |
||
1169 | |||
1170 | /** |
||
1171 | * {@inheritdoc} |
||
1172 | */ |
||
1173 | public function countContentDrafts(?User $user = null): int |
||
1183 | |||
1184 | /** |
||
1185 | * Loads drafts for a user. |
||
1186 | * |
||
1187 | * If no user is given the drafts for the authenticated user are returned |
||
1188 | * |
||
1189 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
1190 | * |
||
1191 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Drafts owned by the given user |
||
1192 | * |
||
1193 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1194 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1195 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1196 | */ |
||
1197 | public function loadContentDrafts(User $user = null) |
||
1220 | |||
1221 | /** |
||
1222 | * {@inheritdoc} |
||
1223 | */ |
||
1224 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList |
||
1256 | |||
1257 | /** |
||
1258 | * Updates the fields of a draft. |
||
1259 | * |
||
1260 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1261 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1262 | * |
||
1263 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
1264 | * |
||
1265 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
1266 | * or if a required field is missing / set to an empty value. |
||
1267 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
1268 | * or value is set for non-translatable field in language |
||
1269 | * other than main. |
||
1270 | * |
||
1271 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
1272 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1273 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
1274 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1275 | */ |
||
1276 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
1303 | |||
1304 | /** |
||
1305 | * Updates the fields of a draft without checking the permissions. |
||
1306 | * |
||
1307 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
1308 | * or if a required field is missing / set to an empty value. |
||
1309 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
1310 | * or value is set for non-translatable field in language |
||
1311 | * other than main. |
||
1312 | * |
||
1313 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1314 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
1315 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1316 | */ |
||
1317 | protected function internalUpdateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct): Content |
||
1488 | |||
1489 | /** |
||
1490 | * Returns only updated language codes. |
||
1491 | * |
||
1492 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1493 | * |
||
1494 | * @return array |
||
1495 | */ |
||
1496 | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
||
1512 | |||
1513 | /** |
||
1514 | * Returns all language codes used in given $fields. |
||
1515 | * |
||
1516 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
1517 | * |
||
1518 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1519 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
1520 | * |
||
1521 | * @return array |
||
1522 | */ |
||
1523 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
1535 | |||
1536 | /** |
||
1537 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
1538 | * |
||
1539 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
1540 | * or value is set for non-translatable field in language |
||
1541 | * other than main |
||
1542 | * |
||
1543 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1544 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
1545 | * @param string $mainLanguageCode |
||
1546 | * |
||
1547 | * @return array |
||
1548 | */ |
||
1549 | protected function mapFieldsForUpdate( |
||
1587 | |||
1588 | /** |
||
1589 | * Publishes a content version. |
||
1590 | * |
||
1591 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1592 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1593 | * |
||
1594 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1595 | * @param string[] $translations |
||
1596 | * |
||
1597 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1598 | * |
||
1599 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1600 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1601 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1602 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1603 | */ |
||
1604 | public function publishVersion(APIVersionInfo $versionInfo, array $translations = Language::ALL) |
||
1642 | |||
1643 | /** |
||
1644 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1645 | * @param array $translations |
||
1646 | * |
||
1647 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1648 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
1649 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
1650 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1651 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1652 | */ |
||
1653 | protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionInfo, array $translations = []): void |
||
1747 | |||
1748 | /** |
||
1749 | * Publishes a content version. |
||
1750 | * |
||
1751 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1752 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1753 | * |
||
1754 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1755 | * |
||
1756 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1757 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
1758 | * |
||
1759 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1760 | */ |
||
1761 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
1813 | |||
1814 | /** |
||
1815 | * @return int |
||
1816 | */ |
||
1817 | protected function getUnixTimestamp() |
||
1821 | |||
1822 | /** |
||
1823 | * Removes the given version. |
||
1824 | * |
||
1825 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
1826 | * published state or is a last version of Content in non draft state |
||
1827 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
1828 | * |
||
1829 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1830 | */ |
||
1831 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
1873 | |||
1874 | /** |
||
1875 | * Loads all versions for the given content. |
||
1876 | * |
||
1877 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
1878 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
1879 | * |
||
1880 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1881 | * @param int|null $status |
||
1882 | * |
||
1883 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
1884 | */ |
||
1885 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
1914 | |||
1915 | /** |
||
1916 | * Copies the content to a new location. If no version is given, |
||
1917 | * all versions are copied, otherwise only the given version. |
||
1918 | * |
||
1919 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
1920 | * |
||
1921 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1922 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
1923 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1924 | * |
||
1925 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1926 | */ |
||
1927 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
1982 | |||
1983 | /** |
||
1984 | * Loads all outgoing relations for the given version. |
||
1985 | * |
||
1986 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1987 | * |
||
1988 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1989 | * |
||
1990 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1991 | */ |
||
1992 | public function loadRelations(APIVersionInfo $versionInfo) |
||
2006 | |||
2007 | /** |
||
2008 | * Loads all outgoing relations for the given version without checking the permissions. |
||
2009 | * |
||
2010 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
2011 | * |
||
2012 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
2013 | */ |
||
2014 | protected function internalLoadRelations(APIVersionInfo $versionInfo): array |
||
2039 | |||
2040 | /** |
||
2041 | * {@inheritdoc} |
||
2042 | */ |
||
2043 | public function countReverseRelations(ContentInfo $contentInfo): int |
||
2053 | |||
2054 | /** |
||
2055 | * Loads all incoming relations for a content object. |
||
2056 | * |
||
2057 | * The relations come only from published versions of the source content objects |
||
2058 | * |
||
2059 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
2060 | * |
||
2061 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2062 | * |
||
2063 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
2064 | */ |
||
2065 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
2091 | |||
2092 | /** |
||
2093 | * {@inheritdoc} |
||
2094 | */ |
||
2095 | public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList |
||
2132 | |||
2133 | /** |
||
2134 | * Adds a relation of type common. |
||
2135 | * |
||
2136 | * The source of the relation is the content and version |
||
2137 | * referenced by $versionInfo. |
||
2138 | * |
||
2139 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
2140 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2141 | * |
||
2142 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2143 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
2144 | * |
||
2145 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
2146 | */ |
||
2147 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2188 | |||
2189 | /** |
||
2190 | * Removes a relation of type COMMON from a draft. |
||
2191 | * |
||
2192 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
2193 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2194 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
2195 | * |
||
2196 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2197 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
2198 | */ |
||
2199 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2249 | |||
2250 | /** |
||
2251 | * {@inheritdoc} |
||
2252 | */ |
||
2253 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
2261 | |||
2262 | /** |
||
2263 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
2264 | * |
||
2265 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
2266 | * |
||
2267 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2268 | * is the Main Translation of a Content Item. |
||
2269 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2270 | * to delete the content (in one of the locations of the given Content Item). |
||
2271 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2272 | * is invalid for the given content. |
||
2273 | * |
||
2274 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2275 | * @param string $languageCode |
||
2276 | * |
||
2277 | * @since 6.13 |
||
2278 | */ |
||
2279 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
2356 | |||
2357 | /** |
||
2358 | * Delete specified Translation from a Content Draft. |
||
2359 | * |
||
2360 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2361 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
2362 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2363 | * to edit the Content (in one of the locations of the given Content Object). |
||
2364 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2365 | * is invalid for the given Draft. |
||
2366 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
2367 | * |
||
2368 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
2369 | * @param string $languageCode Language code of the Translation to be removed |
||
2370 | * |
||
2371 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
2372 | * |
||
2373 | * @since 6.12 |
||
2374 | */ |
||
2375 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode) |
||
2441 | |||
2442 | /** |
||
2443 | * Hides Content by making all the Locations appear hidden. |
||
2444 | * It does not persist hidden state on Location object itself. |
||
2445 | * |
||
2446 | * Content hidden by this API can be revealed by revealContent API. |
||
2447 | * |
||
2448 | * @see revealContent |
||
2449 | * |
||
2450 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2451 | */ |
||
2452 | public function hideContent(ContentInfo $contentInfo): void |
||
2477 | |||
2478 | /** |
||
2479 | * Reveals Content hidden by hideContent API. |
||
2480 | * Locations which were hidden before hiding Content will remain hidden. |
||
2481 | * |
||
2482 | * @see hideContent |
||
2483 | * |
||
2484 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2485 | */ |
||
2486 | public function revealContent(ContentInfo $contentInfo): void |
||
2511 | |||
2512 | /** |
||
2513 | * Instantiates a new content create struct object. |
||
2514 | * |
||
2515 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
2516 | * |
||
2517 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
2518 | * @param string $mainLanguageCode |
||
2519 | * |
||
2520 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
2521 | */ |
||
2522 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
2532 | |||
2533 | /** |
||
2534 | * Instantiates a new content meta data update struct. |
||
2535 | * |
||
2536 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
2537 | */ |
||
2538 | public function newContentMetadataUpdateStruct() |
||
2542 | |||
2543 | /** |
||
2544 | * Instantiates a new content update struct. |
||
2545 | * |
||
2546 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
2547 | */ |
||
2548 | public function newContentUpdateStruct() |
||
2552 | |||
2553 | /** |
||
2554 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
2555 | * |
||
2556 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
2557 | */ |
||
2558 | private function resolveUser(?User $user): UserReference |
||
2566 | } |
||
2567 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.