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 | * |
||
333 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
334 | * |
||
335 | * @param mixed $id |
||
336 | * @param array|null $languages A language priority, filters returned fields and is used as prioritized language code on |
||
337 | * returned value object. If not given all languages are returned. |
||
338 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
339 | * @param bool $isRemoteId |
||
340 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
341 | * |
||
342 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
343 | */ |
||
344 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
345 | { |
||
346 | try { |
||
347 | // Get Content ID if lookup by remote ID |
||
348 | if ($isRemoteId) { |
||
349 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
350 | $id = $spiContentInfo->id; |
||
351 | // Set $isRemoteId to false as the next loads will be for content id now that we have it (for exception use now) |
||
352 | $isRemoteId = false; |
||
353 | } |
||
354 | |||
355 | $loadLanguages = $languages; |
||
356 | $alwaysAvailableLanguageCode = null; |
||
357 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
358 | // @todo Move use always available logic to SPI load methods, like done in location handler in 7.x |
||
359 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
360 | if (!isset($spiContentInfo)) { |
||
361 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
362 | } |
||
363 | |||
364 | if ($spiContentInfo->alwaysAvailable) { |
||
365 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
366 | $loadLanguages = array_unique($loadLanguages); |
||
367 | } |
||
368 | } |
||
369 | |||
370 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
371 | $id, |
||
372 | $versionNo, |
||
373 | $loadLanguages |
||
374 | ); |
||
375 | } catch (APINotFoundException $e) { |
||
376 | throw new NotFoundException( |
||
377 | 'Content', |
||
378 | [ |
||
379 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
380 | 'languages' => $languages, |
||
381 | 'versionNo' => $versionNo, |
||
382 | ], |
||
383 | $e |
||
384 | ); |
||
385 | } |
||
386 | |||
387 | if ($languages === null) { |
||
388 | $languages = []; |
||
389 | } |
||
390 | |||
391 | return $this->domainMapper->buildContentDomainObject( |
||
392 | $spiContent, |
||
393 | $this->repository->getContentTypeService()->loadContentType( |
||
394 | $spiContent->versionInfo->contentInfo->contentTypeId, |
||
395 | $languages |
||
396 | ), |
||
397 | $languages, |
||
398 | $alwaysAvailableLanguageCode |
||
399 | ); |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Loads content in a version for the content object reference by the given remote id. |
||
404 | * |
||
405 | * If no version is given, the method returns the current version |
||
406 | * |
||
407 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
408 | * @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 |
||
409 | * |
||
410 | * @param string $remoteId |
||
411 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
412 | * @param int $versionNo the version number. If not given the current version is returned |
||
413 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
414 | * |
||
415 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
416 | */ |
||
417 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
418 | { |
||
419 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable); |
||
420 | |||
421 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
422 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
423 | } |
||
424 | |||
425 | if ( |
||
426 | !$content->getVersionInfo()->isPublished() |
||
427 | && !$this->repository->canUser('content', 'versionread', $content) |
||
428 | ) { |
||
429 | throw new UnauthorizedException('content', 'versionread', ['remoteId' => $remoteId, 'versionNo' => $versionNo]); |
||
430 | } |
||
431 | |||
432 | return $content; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
437 | * |
||
438 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
439 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
440 | * allowed to access every Content on the list. |
||
441 | * |
||
442 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
443 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
444 | * returned value object. If not given all languages are returned. |
||
445 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
446 | * unless all languages have been asked for. |
||
447 | * |
||
448 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
449 | */ |
||
450 | public function loadContentListByContentInfo( |
||
451 | array $contentInfoList, |
||
452 | array $languages = [], |
||
453 | $useAlwaysAvailable = true |
||
454 | ) { |
||
455 | $loadAllLanguages = $languages === Language::ALL; |
||
456 | $contentIds = []; |
||
457 | $contentTypeIds = []; |
||
458 | $translations = $languages; |
||
459 | foreach ($contentInfoList as $contentInfo) { |
||
460 | $contentIds[] = $contentInfo->id; |
||
461 | $contentTypeIds[] = $contentInfo->contentTypeId; |
||
462 | // Unless we are told to load all languages, we add main language to translations so they are loaded too |
||
463 | // Might in some case load more languages then intended, but prioritised handling will pick right one |
||
464 | if (!$loadAllLanguages && $useAlwaysAvailable && $contentInfo->alwaysAvailable) { |
||
465 | $translations[] = $contentInfo->mainLanguageCode; |
||
466 | } |
||
467 | } |
||
468 | |||
469 | $contentList = []; |
||
470 | $translations = array_unique($translations); |
||
471 | $spiContentList = $this->persistenceHandler->contentHandler()->loadContentList( |
||
472 | $contentIds, |
||
473 | $translations |
||
474 | ); |
||
475 | $contentTypeList = $this->repository->getContentTypeService()->loadContentTypeList( |
||
476 | array_unique($contentTypeIds), |
||
477 | $languages |
||
478 | ); |
||
479 | foreach ($spiContentList as $contentId => $spiContent) { |
||
480 | $contentInfo = $spiContent->versionInfo->contentInfo; |
||
481 | $contentList[$contentId] = $this->domainMapper->buildContentDomainObject( |
||
482 | $spiContent, |
||
483 | $contentTypeList[$contentInfo->contentTypeId], |
||
484 | $languages, |
||
485 | $contentInfo->alwaysAvailable ? $contentInfo->mainLanguageCode : null |
||
486 | ); |
||
487 | } |
||
488 | |||
489 | return $contentList; |
||
490 | } |
||
491 | |||
492 | /** |
||
493 | * Creates a new content draft assigned to the authenticated user. |
||
494 | * |
||
495 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
496 | * but this required special rights for the authenticated user |
||
497 | * (this is useful for content staging where the transfer process does not |
||
498 | * have to authenticate with the user which created the content object in the source server). |
||
499 | * The user has to publish the draft if it should be visible. |
||
500 | * In 4.x at least one location has to be provided in the location creation array. |
||
501 | * |
||
502 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
503 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
504 | * struct are missing or invalid, or if multiple locations are under the |
||
505 | * same parent. |
||
506 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
507 | * or if a required field is missing / set to an empty value. |
||
508 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
509 | * or value is set for non-translatable field in language |
||
510 | * other than main. |
||
511 | * |
||
512 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
513 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
514 | * |
||
515 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
516 | */ |
||
517 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = []) |
||
518 | { |
||
519 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
520 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
521 | } |
||
522 | |||
523 | if ($contentCreateStruct->contentType === null) { |
||
524 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
525 | } |
||
526 | |||
527 | $contentCreateStruct = clone $contentCreateStruct; |
||
528 | |||
529 | if ($contentCreateStruct->ownerId === null) { |
||
530 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
531 | } |
||
532 | |||
533 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
534 | $contentCreateStruct->alwaysAvailable = $contentCreateStruct->contentType->defaultAlwaysAvailable ?: false; |
||
535 | } |
||
536 | |||
537 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
538 | $contentCreateStruct->contentType->id |
||
539 | ); |
||
540 | |||
541 | if (empty($contentCreateStruct->sectionId)) { |
||
542 | if (isset($locationCreateStructs[0])) { |
||
543 | $location = $this->repository->getLocationService()->loadLocation( |
||
544 | $locationCreateStructs[0]->parentLocationId |
||
545 | ); |
||
546 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
547 | } else { |
||
548 | $contentCreateStruct->sectionId = 1; |
||
549 | } |
||
550 | } |
||
551 | |||
552 | if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
553 | throw new UnauthorizedException( |
||
554 | 'content', |
||
555 | 'create', |
||
556 | [ |
||
557 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
558 | $locationCreateStructs[0]->parentLocationId : |
||
559 | null, |
||
560 | 'sectionId' => $contentCreateStruct->sectionId, |
||
561 | ] |
||
562 | ); |
||
563 | } |
||
564 | |||
565 | if (!empty($contentCreateStruct->remoteId)) { |
||
566 | try { |
||
567 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
568 | |||
569 | throw new InvalidArgumentException( |
||
570 | '$contentCreateStruct', |
||
571 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
572 | ); |
||
573 | } catch (APINotFoundException $e) { |
||
574 | // Do nothing |
||
575 | } |
||
576 | } else { |
||
577 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
578 | } |
||
579 | |||
580 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
581 | |||
582 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
583 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
584 | |||
585 | $fieldValues = []; |
||
586 | $spiFields = []; |
||
587 | $allFieldErrors = []; |
||
588 | $inputRelations = []; |
||
589 | $locationIdToContentIdMapping = []; |
||
590 | |||
591 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
592 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
593 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
594 | $fieldDefinition->fieldTypeIdentifier |
||
595 | ); |
||
596 | |||
597 | foreach ($languageCodes as $languageCode) { |
||
598 | $isEmptyValue = false; |
||
599 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
600 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
601 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
602 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
603 | } else { |
||
604 | $fieldValue = $fieldDefinition->defaultValue; |
||
605 | } |
||
606 | |||
607 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
608 | |||
609 | if ($fieldType->isEmptyValue($fieldValue)) { |
||
610 | $isEmptyValue = true; |
||
611 | if ($fieldDefinition->isRequired) { |
||
612 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
613 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
614 | null, |
||
615 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
616 | 'empty' |
||
617 | ); |
||
618 | } |
||
619 | } else { |
||
620 | $fieldErrors = $fieldType->validate( |
||
621 | $fieldDefinition, |
||
622 | $fieldValue |
||
623 | ); |
||
624 | if (!empty($fieldErrors)) { |
||
625 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
626 | } |
||
627 | } |
||
628 | |||
629 | if (!empty($allFieldErrors)) { |
||
630 | continue; |
||
631 | } |
||
632 | |||
633 | $this->relationProcessor->appendFieldRelations( |
||
634 | $inputRelations, |
||
635 | $locationIdToContentIdMapping, |
||
636 | $fieldType, |
||
637 | $fieldValue, |
||
638 | $fieldDefinition->id |
||
639 | ); |
||
640 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
641 | |||
642 | // Only non-empty value for: translatable field or in main language |
||
643 | if ( |
||
644 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
645 | (!$isEmptyValue && $isLanguageMain) |
||
646 | ) { |
||
647 | $spiFields[] = new SPIField( |
||
648 | [ |
||
649 | 'id' => null, |
||
650 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
651 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
652 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
653 | 'languageCode' => $languageCode, |
||
654 | 'versionNo' => null, |
||
655 | ] |
||
656 | ); |
||
657 | } |
||
658 | } |
||
659 | } |
||
660 | |||
661 | if (!empty($allFieldErrors)) { |
||
662 | throw new ContentFieldValidationException($allFieldErrors); |
||
663 | } |
||
664 | |||
665 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
666 | [ |
||
667 | 'name' => $this->nameSchemaService->resolve( |
||
668 | $contentCreateStruct->contentType->nameSchema, |
||
669 | $contentCreateStruct->contentType, |
||
670 | $fieldValues, |
||
671 | $languageCodes |
||
672 | ), |
||
673 | 'typeId' => $contentCreateStruct->contentType->id, |
||
674 | 'sectionId' => $contentCreateStruct->sectionId, |
||
675 | 'ownerId' => $contentCreateStruct->ownerId, |
||
676 | 'locations' => $spiLocationCreateStructs, |
||
677 | 'fields' => $spiFields, |
||
678 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
679 | 'remoteId' => $contentCreateStruct->remoteId, |
||
680 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
681 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
682 | $contentCreateStruct->mainLanguageCode |
||
683 | )->id, |
||
684 | ] |
||
685 | ); |
||
686 | |||
687 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
688 | |||
689 | $this->repository->beginTransaction(); |
||
690 | try { |
||
691 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
692 | $this->relationProcessor->processFieldRelations( |
||
693 | $inputRelations, |
||
694 | $spiContent->versionInfo->contentInfo->id, |
||
695 | $spiContent->versionInfo->versionNo, |
||
696 | $contentCreateStruct->contentType |
||
697 | ); |
||
698 | |||
699 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
700 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
701 | $objectStateHandler->setContentState( |
||
702 | $spiContent->versionInfo->contentInfo->id, |
||
703 | $objectStateGroupId, |
||
704 | $objectState->id |
||
705 | ); |
||
706 | } |
||
707 | |||
708 | $this->repository->commit(); |
||
709 | } catch (Exception $e) { |
||
710 | $this->repository->rollback(); |
||
711 | throw $e; |
||
712 | } |
||
713 | |||
714 | return $this->domainMapper->buildContentDomainObject( |
||
715 | $spiContent, |
||
716 | $contentCreateStruct->contentType |
||
717 | ); |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * Returns an array of default content states with content state group id as key. |
||
722 | * |
||
723 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
724 | */ |
||
725 | protected function getDefaultObjectStates() |
||
740 | |||
741 | /** |
||
742 | * Returns all language codes used in given $fields. |
||
743 | * |
||
744 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
745 | * |
||
746 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
747 | * |
||
748 | * @return string[] |
||
749 | */ |
||
750 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
774 | |||
775 | /** |
||
776 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
777 | * |
||
778 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
779 | * or value is set for non-translatable field in language |
||
780 | * other than main |
||
781 | * |
||
782 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
783 | * |
||
784 | * @return array |
||
785 | */ |
||
786 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
787 | { |
||
788 | $fields = []; |
||
789 | |||
790 | foreach ($contentCreateStruct->fields as $field) { |
||
791 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier); |
||
792 | |||
793 | if ($fieldDefinition === null) { |
||
794 | throw new ContentValidationException( |
||
795 | "Field definition '%identifier%' does not exist in given ContentType", |
||
796 | ['%identifier%' => $field->fieldDefIdentifier] |
||
797 | ); |
||
798 | } |
||
799 | |||
800 | if ($field->languageCode === null) { |
||
801 | $field = $this->cloneField( |
||
802 | $field, |
||
803 | ['languageCode' => $contentCreateStruct->mainLanguageCode] |
||
804 | ); |
||
805 | } |
||
806 | |||
807 | if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { |
||
808 | throw new ContentValidationException( |
||
809 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'", |
||
810 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode] |
||
811 | ); |
||
812 | } |
||
813 | |||
814 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
815 | } |
||
816 | |||
817 | return $fields; |
||
818 | } |
||
819 | |||
820 | /** |
||
821 | * Clones $field with overriding specific properties from given $overrides array. |
||
822 | * |
||
823 | * @param Field $field |
||
824 | * @param array $overrides |
||
825 | * |
||
826 | * @return Field |
||
827 | */ |
||
828 | private function cloneField(Field $field, array $overrides = []) |
||
843 | |||
844 | /** |
||
845 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
846 | * |
||
847 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
848 | * |
||
849 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
850 | */ |
||
851 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
852 | { |
||
853 | $spiLocationCreateStructs = []; |
||
854 | $parentLocationIdSet = []; |
||
855 | $mainLocation = true; |
||
856 | |||
857 | foreach ($locationCreateStructs as $locationCreateStruct) { |
||
858 | if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) { |
||
859 | throw new InvalidArgumentException( |
||
860 | '$locationCreateStructs', |
||
861 | "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given" |
||
862 | ); |
||
863 | } |
||
864 | |||
865 | if (!array_key_exists($locationCreateStruct->sortField, Location::SORT_FIELD_MAP)) { |
||
866 | $locationCreateStruct->sortField = Location::SORT_FIELD_NAME; |
||
867 | } |
||
868 | |||
869 | if (!array_key_exists($locationCreateStruct->sortOrder, Location::SORT_ORDER_MAP)) { |
||
870 | $locationCreateStruct->sortOrder = Location::SORT_ORDER_ASC; |
||
871 | } |
||
872 | |||
873 | $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true; |
||
874 | $parentLocation = $this->repository->getLocationService()->loadLocation( |
||
875 | $locationCreateStruct->parentLocationId |
||
876 | ); |
||
877 | |||
878 | $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct( |
||
879 | $locationCreateStruct, |
||
880 | $parentLocation, |
||
881 | $mainLocation, |
||
882 | // For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation |
||
883 | null, |
||
884 | null |
||
885 | ); |
||
886 | |||
887 | // First Location in the list will be created as main Location |
||
888 | $mainLocation = false; |
||
889 | } |
||
890 | |||
891 | return $spiLocationCreateStructs; |
||
892 | } |
||
893 | |||
894 | /** |
||
895 | * Updates the metadata. |
||
896 | * |
||
897 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
898 | * |
||
899 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
900 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
901 | * |
||
902 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
903 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
904 | * |
||
905 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
906 | */ |
||
907 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
908 | { |
||
909 | $propertyCount = 0; |
||
910 | foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { |
||
911 | if (isset($contentMetadataUpdateStruct->$propertyName)) { |
||
912 | ++$propertyCount; |
||
913 | } |
||
914 | } |
||
915 | if ($propertyCount === 0) { |
||
916 | throw new InvalidArgumentException( |
||
917 | '$contentMetadataUpdateStruct', |
||
918 | 'At least one property must be set' |
||
919 | ); |
||
920 | } |
||
921 | |||
922 | $loadedContentInfo = $this->loadContentInfo($contentInfo->id); |
||
923 | |||
924 | if (!$this->repository->canUser('content', 'edit', $loadedContentInfo)) { |
||
925 | throw new UnauthorizedException('content', 'edit', ['contentId' => $loadedContentInfo->id]); |
||
926 | } |
||
927 | |||
928 | if (isset($contentMetadataUpdateStruct->remoteId)) { |
||
929 | try { |
||
930 | $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId); |
||
931 | |||
932 | if ($existingContentInfo->id !== $loadedContentInfo->id) { |
||
933 | throw new InvalidArgumentException( |
||
934 | '$contentMetadataUpdateStruct', |
||
935 | "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists" |
||
936 | ); |
||
937 | } |
||
938 | } catch (APINotFoundException $e) { |
||
939 | // Do nothing |
||
940 | } |
||
941 | } |
||
942 | |||
943 | $this->repository->beginTransaction(); |
||
944 | try { |
||
945 | if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) { |
||
946 | $this->persistenceHandler->contentHandler()->updateMetadata( |
||
947 | $loadedContentInfo->id, |
||
948 | new SPIMetadataUpdateStruct( |
||
949 | [ |
||
950 | 'ownerId' => $contentMetadataUpdateStruct->ownerId, |
||
951 | 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ? |
||
952 | $contentMetadataUpdateStruct->publishedDate->getTimestamp() : |
||
953 | null, |
||
954 | 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ? |
||
955 | $contentMetadataUpdateStruct->modificationDate->getTimestamp() : |
||
956 | null, |
||
957 | 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ? |
||
958 | $this->repository->getContentLanguageService()->loadLanguage( |
||
959 | $contentMetadataUpdateStruct->mainLanguageCode |
||
960 | )->id : |
||
961 | null, |
||
962 | 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable, |
||
963 | 'remoteId' => $contentMetadataUpdateStruct->remoteId, |
||
964 | 'name' => $contentMetadataUpdateStruct->name, |
||
965 | ] |
||
966 | ) |
||
967 | ); |
||
968 | } |
||
969 | |||
970 | // Change main location |
||
971 | if (isset($contentMetadataUpdateStruct->mainLocationId) |
||
972 | && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) { |
||
973 | $this->persistenceHandler->locationHandler()->changeMainLocation( |
||
974 | $loadedContentInfo->id, |
||
975 | $contentMetadataUpdateStruct->mainLocationId |
||
976 | ); |
||
977 | } |
||
978 | |||
979 | // Republish URL aliases to update always-available flag |
||
980 | if (isset($contentMetadataUpdateStruct->alwaysAvailable) |
||
981 | && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) { |
||
982 | $content = $this->loadContent($loadedContentInfo->id); |
||
983 | $this->publishUrlAliasesForContent($content, false); |
||
984 | } |
||
985 | |||
986 | $this->repository->commit(); |
||
987 | } catch (Exception $e) { |
||
988 | $this->repository->rollback(); |
||
989 | throw $e; |
||
990 | } |
||
991 | |||
992 | return isset($content) ? $content : $this->loadContent($loadedContentInfo->id); |
||
993 | } |
||
994 | |||
995 | /** |
||
996 | * Publishes URL aliases for all locations of a given content. |
||
997 | * |
||
998 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
999 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
1000 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
1001 | */ |
||
1002 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
1003 | { |
||
1004 | $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content); |
||
1005 | $locations = $this->repository->getLocationService()->loadLocations( |
||
1006 | $content->getVersionInfo()->getContentInfo() |
||
1007 | ); |
||
1008 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler(); |
||
1009 | foreach ($locations as $location) { |
||
1010 | foreach ($urlAliasNames as $languageCode => $name) { |
||
1011 | $urlAliasHandler->publishUrlAliasForLocation( |
||
1012 | $location->id, |
||
1013 | $location->parentLocationId, |
||
1014 | $name, |
||
1015 | $languageCode, |
||
1016 | $content->contentInfo->alwaysAvailable, |
||
1017 | $updatePathIdentificationString ? $languageCode === $content->contentInfo->mainLanguageCode : false |
||
1018 | ); |
||
1019 | } |
||
1020 | // archive URL aliases of Translations that got deleted |
||
1021 | $urlAliasHandler->archiveUrlAliasesForDeletedTranslations( |
||
1022 | $location->id, |
||
1023 | $location->parentLocationId, |
||
1024 | $content->versionInfo->languageCodes |
||
1025 | ); |
||
1026 | } |
||
1027 | } |
||
1028 | |||
1029 | /** |
||
1030 | * Deletes a content object including all its versions and locations including their subtrees. |
||
1031 | * |
||
1032 | * @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) |
||
1033 | * |
||
1034 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1035 | * |
||
1036 | * @return mixed[] Affected Location Id's |
||
1037 | */ |
||
1038 | public function deleteContent(ContentInfo $contentInfo) |
||
1039 | { |
||
1040 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id); |
||
1041 | |||
1042 | if (!$this->repository->canUser('content', 'remove', $contentInfo)) { |
||
1043 | throw new UnauthorizedException('content', 'remove', ['contentId' => $contentInfo->id]); |
||
1044 | } |
||
1045 | |||
1046 | $affectedLocations = []; |
||
1047 | $this->repository->beginTransaction(); |
||
1048 | try { |
||
1049 | // Load Locations first as deleting Content also deletes belonging Locations |
||
1050 | $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id); |
||
1051 | $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id); |
||
1052 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler(); |
||
1053 | foreach ($spiLocations as $spiLocation) { |
||
1054 | $urlAliasHandler->locationDeleted($spiLocation->id); |
||
1055 | $affectedLocations[] = $spiLocation->id; |
||
1056 | } |
||
1057 | $this->repository->commit(); |
||
1058 | } catch (Exception $e) { |
||
1059 | $this->repository->rollback(); |
||
1060 | throw $e; |
||
1061 | } |
||
1062 | |||
1063 | return $affectedLocations; |
||
1064 | } |
||
1065 | |||
1066 | /** |
||
1067 | * Creates a draft from a published or archived version. |
||
1068 | * |
||
1069 | * If no version is given, the current published version is used. |
||
1070 | * |
||
1071 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1072 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1073 | * @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 |
||
1074 | * @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. |
||
1075 | * |
||
1076 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
1077 | * |
||
1078 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
1079 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the current-user is not allowed to create the draft |
||
1080 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
1081 | */ |
||
1082 | public function createContentDraft( |
||
1083 | ContentInfo $contentInfo, |
||
1084 | APIVersionInfo $versionInfo = null, |
||
1085 | User $creator = null, |
||
1086 | ?Language $language = null |
||
1087 | ) { |
||
1088 | $contentInfo = $this->loadContentInfo($contentInfo->id); |
||
1089 | |||
1090 | if ($versionInfo !== null) { |
||
1091 | // Check that given $contentInfo and $versionInfo belong to the same content |
||
1092 | if ($versionInfo->getContentInfo()->id != $contentInfo->id) { |
||
1093 | throw new InvalidArgumentException( |
||
1094 | '$versionInfo', |
||
1095 | 'VersionInfo does not belong to the same content as given ContentInfo' |
||
1096 | ); |
||
1097 | } |
||
1098 | |||
1099 | $versionInfo = $this->loadVersionInfoById($contentInfo->id, $versionInfo->versionNo); |
||
1100 | |||
1101 | switch ($versionInfo->status) { |
||
1102 | case VersionInfo::STATUS_PUBLISHED: |
||
1103 | case VersionInfo::STATUS_ARCHIVED: |
||
1104 | break; |
||
1105 | |||
1106 | default: |
||
1107 | // @todo: throw an exception here, to be defined |
||
1108 | throw new BadStateException( |
||
1109 | '$versionInfo', |
||
1110 | 'Draft can not be created from a draft version' |
||
1111 | ); |
||
1112 | } |
||
1113 | |||
1114 | $versionNo = $versionInfo->versionNo; |
||
1115 | } elseif ($contentInfo->published) { |
||
1116 | $versionNo = $contentInfo->currentVersionNo; |
||
1117 | } else { |
||
1118 | // @todo: throw an exception here, to be defined |
||
1119 | throw new BadStateException( |
||
1120 | '$contentInfo', |
||
1121 | 'Content is not published, draft can be created only from published or archived version' |
||
1122 | ); |
||
1123 | } |
||
1124 | |||
1125 | if ($creator === null) { |
||
1126 | $creator = $this->repository->getCurrentUserReference(); |
||
1127 | } |
||
1128 | |||
1129 | $fallbackLanguageCode = $versionInfo->initialLanguageCode ?? $contentInfo->mainLanguageCode; |
||
1130 | $languageCode = $language->languageCode ?? $fallbackLanguageCode; |
||
1131 | |||
1132 | if (!$this->repository->getPermissionResolver()->canUser( |
||
1133 | 'content', |
||
1134 | 'edit', |
||
1135 | $contentInfo, |
||
1136 | [ |
||
1137 | (new Target\Builder\VersionBuilder()) |
||
1138 | ->changeStatusTo(APIVersionInfo::STATUS_DRAFT) |
||
1139 | ->build(), |
||
1140 | ] |
||
1141 | )) { |
||
1142 | throw new UnauthorizedException( |
||
1143 | 'content', |
||
1144 | 'edit', |
||
1145 | ['contentId' => $contentInfo->id] |
||
1146 | ); |
||
1147 | } |
||
1148 | |||
1149 | $this->repository->beginTransaction(); |
||
1150 | try { |
||
1151 | $spiContent = $this->persistenceHandler->contentHandler()->createDraftFromVersion( |
||
1152 | $contentInfo->id, |
||
1153 | $versionNo, |
||
1154 | $creator->getUserId(), |
||
1155 | $languageCode |
||
1156 | ); |
||
1157 | $this->repository->commit(); |
||
1158 | } catch (Exception $e) { |
||
1159 | $this->repository->rollback(); |
||
1160 | throw $e; |
||
1161 | } |
||
1162 | |||
1163 | return $this->domainMapper->buildContentDomainObject( |
||
1164 | $spiContent, |
||
1165 | $this->repository->getContentTypeService()->loadContentType( |
||
1166 | $spiContent->versionInfo->contentInfo->contentTypeId |
||
1167 | ) |
||
1168 | ); |
||
1169 | } |
||
1170 | |||
1171 | /** |
||
1172 | * {@inheritdoc} |
||
1173 | */ |
||
1174 | public function countContentDrafts(?User $user = null): int |
||
1175 | { |
||
1176 | if ($this->repository->hasAccess('content', 'versionread') === false) { |
||
1177 | return 0; |
||
1178 | } |
||
1179 | |||
1180 | return $this->persistenceHandler->contentHandler()->countDraftsForUser( |
||
1181 | $this->resolveUser($user)->getUserId() |
||
1182 | ); |
||
1183 | } |
||
1184 | |||
1185 | /** |
||
1186 | * Loads drafts for a user. |
||
1187 | * |
||
1188 | * If no user is given the drafts for the authenticated user are returned |
||
1189 | * |
||
1190 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
1191 | * |
||
1192 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Drafts owned by the given user |
||
1193 | * |
||
1194 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1195 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1196 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1197 | */ |
||
1198 | public function loadContentDrafts(User $user = null) |
||
1199 | { |
||
1200 | // throw early if user has absolutely no access to versionread |
||
1201 | if ($this->repository->hasAccess('content', 'versionread') === false) { |
||
1202 | throw new UnauthorizedException('content', 'versionread'); |
||
1203 | } |
||
1204 | |||
1205 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftsForUser( |
||
1206 | $this->resolveUser($user)->getUserId() |
||
1207 | ); |
||
1208 | $versionInfoList = []; |
||
1209 | foreach ($spiVersionInfoList as $spiVersionInfo) { |
||
1210 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
1211 | // @todo: Change this to filter returned drafts by permissions instead of throwing |
||
1212 | if (!$this->repository->canUser('content', 'versionread', $versionInfo)) { |
||
1213 | throw new UnauthorizedException('content', 'versionread', ['contentId' => $versionInfo->contentInfo->id]); |
||
1214 | } |
||
1215 | |||
1216 | $versionInfoList[] = $versionInfo; |
||
1217 | } |
||
1218 | |||
1219 | return $versionInfoList; |
||
1220 | } |
||
1221 | |||
1222 | /** |
||
1223 | * {@inheritdoc} |
||
1224 | */ |
||
1225 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList |
||
1226 | { |
||
1227 | $list = new ContentDraftList(); |
||
1228 | if ($this->repository->hasAccess('content', 'versionread') === false) { |
||
1229 | return $list; |
||
1230 | } |
||
1231 | |||
1232 | $list->totalCount = $this->persistenceHandler->contentHandler()->countDraftsForUser( |
||
1233 | $this->resolveUser($user)->getUserId() |
||
1234 | ); |
||
1235 | if ($list->totalCount > 0) { |
||
1236 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftListForUser( |
||
1237 | $this->resolveUser($user)->getUserId(), |
||
1238 | $offset, |
||
1239 | $limit |
||
1240 | ); |
||
1241 | foreach ($spiVersionInfoList as $spiVersionInfo) { |
||
1242 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
1243 | if ($this->repository->canUser('content', 'versionread', $versionInfo)) { |
||
1244 | $list->items[] = new ContentDraftListItem($versionInfo); |
||
1245 | } else { |
||
1246 | $list->items[] = new UnauthorizedContentDraftListItem( |
||
1247 | 'content', |
||
1248 | 'versionread', |
||
1249 | ['contentId' => $versionInfo->contentInfo->id] |
||
1250 | ); |
||
1251 | } |
||
1252 | } |
||
1253 | } |
||
1254 | |||
1255 | return $list; |
||
1256 | } |
||
1257 | |||
1258 | /** |
||
1259 | * Updates the fields of a draft. |
||
1260 | * |
||
1261 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1262 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1263 | * |
||
1264 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
1265 | * |
||
1266 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
1267 | * or if a required field is missing / set to an empty value. |
||
1268 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
1269 | * or value is set for non-translatable field in language |
||
1270 | * other than main. |
||
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 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1313 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
1314 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1315 | */ |
||
1316 | protected function internalUpdateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct): Content |
||
1487 | |||
1488 | /** |
||
1489 | * Returns only updated language codes. |
||
1490 | * |
||
1491 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1492 | * |
||
1493 | * @return array |
||
1494 | */ |
||
1495 | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
||
1511 | |||
1512 | /** |
||
1513 | * Returns all language codes used in given $fields. |
||
1514 | * |
||
1515 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
1516 | * |
||
1517 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1518 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
1519 | * |
||
1520 | * @return array |
||
1521 | */ |
||
1522 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
1534 | |||
1535 | /** |
||
1536 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
1537 | * |
||
1538 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
1539 | * or value is set for non-translatable field in language |
||
1540 | * other than main |
||
1541 | * |
||
1542 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1543 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
1544 | * @param string $mainLanguageCode |
||
1545 | * |
||
1546 | * @return array |
||
1547 | */ |
||
1548 | protected function mapFieldsForUpdate( |
||
1586 | |||
1587 | /** |
||
1588 | * Publishes a content version. |
||
1589 | * |
||
1590 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1591 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1592 | * |
||
1593 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1594 | * @param string[] $translations |
||
1595 | * |
||
1596 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1597 | * |
||
1598 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1599 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1600 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1601 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1602 | */ |
||
1603 | public function publishVersion(APIVersionInfo $versionInfo, array $translations = Language::ALL) |
||
1641 | |||
1642 | /** |
||
1643 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1644 | * @param array $translations |
||
1645 | * |
||
1646 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1647 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
1648 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
1649 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1650 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1651 | */ |
||
1652 | protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionInfo, array $translations = []): void |
||
1746 | |||
1747 | /** |
||
1748 | * Publishes a content version. |
||
1749 | * |
||
1750 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1751 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1752 | * |
||
1753 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1754 | * |
||
1755 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1756 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
1757 | * |
||
1758 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1759 | */ |
||
1760 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
1812 | |||
1813 | /** |
||
1814 | * @return int |
||
1815 | */ |
||
1816 | protected function getUnixTimestamp() |
||
1820 | |||
1821 | /** |
||
1822 | * Removes the given version. |
||
1823 | * |
||
1824 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
1825 | * published state or is a last version of Content in non draft state |
||
1826 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
1827 | * |
||
1828 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1829 | */ |
||
1830 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
1872 | |||
1873 | /** |
||
1874 | * Loads all versions for the given content. |
||
1875 | * |
||
1876 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
1877 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
1878 | * |
||
1879 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1880 | * @param int|null $status |
||
1881 | * |
||
1882 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
1883 | */ |
||
1884 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
1913 | |||
1914 | /** |
||
1915 | * Copies the content to a new location. If no version is given, |
||
1916 | * all versions are copied, otherwise only the given version. |
||
1917 | * |
||
1918 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
1919 | * |
||
1920 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1921 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
1922 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1923 | * |
||
1924 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1925 | */ |
||
1926 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
1981 | |||
1982 | /** |
||
1983 | * Loads all outgoing relations for the given version. |
||
1984 | * |
||
1985 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1986 | * |
||
1987 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1988 | * |
||
1989 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1990 | */ |
||
1991 | public function loadRelations(APIVersionInfo $versionInfo) |
||
2005 | |||
2006 | /** |
||
2007 | * Loads all outgoing relations for the given version without checking the permissions. |
||
2008 | * |
||
2009 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
2010 | * |
||
2011 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
2012 | */ |
||
2013 | protected function internalLoadRelations(APIVersionInfo $versionInfo): array |
||
2038 | |||
2039 | /** |
||
2040 | * {@inheritdoc} |
||
2041 | */ |
||
2042 | public function countReverseRelations(ContentInfo $contentInfo): int |
||
2052 | |||
2053 | /** |
||
2054 | * Loads all incoming relations for a content object. |
||
2055 | * |
||
2056 | * The relations come only from published versions of the source content objects |
||
2057 | * |
||
2058 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
2059 | * |
||
2060 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2061 | * |
||
2062 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
2063 | */ |
||
2064 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
2090 | |||
2091 | /** |
||
2092 | * {@inheritdoc} |
||
2093 | */ |
||
2094 | public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList |
||
2131 | |||
2132 | /** |
||
2133 | * Adds a relation of type common. |
||
2134 | * |
||
2135 | * The source of the relation is the content and version |
||
2136 | * referenced by $versionInfo. |
||
2137 | * |
||
2138 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
2139 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2140 | * |
||
2141 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2142 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
2143 | * |
||
2144 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
2145 | */ |
||
2146 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2187 | |||
2188 | /** |
||
2189 | * Removes a relation of type COMMON from a draft. |
||
2190 | * |
||
2191 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
2192 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2193 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
2194 | * |
||
2195 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2196 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
2197 | */ |
||
2198 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2248 | |||
2249 | /** |
||
2250 | * {@inheritdoc} |
||
2251 | */ |
||
2252 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
2260 | |||
2261 | /** |
||
2262 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
2263 | * |
||
2264 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
2265 | * |
||
2266 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2267 | * is the Main Translation of a Content Item. |
||
2268 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2269 | * to delete the content (in one of the locations of the given Content Item). |
||
2270 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2271 | * is invalid for the given content. |
||
2272 | * |
||
2273 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2274 | * @param string $languageCode |
||
2275 | * |
||
2276 | * @since 6.13 |
||
2277 | */ |
||
2278 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
2355 | |||
2356 | /** |
||
2357 | * Delete specified Translation from a Content Draft. |
||
2358 | * |
||
2359 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2360 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
2361 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2362 | * to edit the Content (in one of the locations of the given Content Object). |
||
2363 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2364 | * is invalid for the given Draft. |
||
2365 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
2366 | * |
||
2367 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
2368 | * @param string $languageCode Language code of the Translation to be removed |
||
2369 | * |
||
2370 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
2371 | * |
||
2372 | * @since 6.12 |
||
2373 | */ |
||
2374 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode) |
||
2440 | |||
2441 | /** |
||
2442 | * Hides Content by making all the Locations appear hidden. |
||
2443 | * It does not persist hidden state on Location object itself. |
||
2444 | * |
||
2445 | * Content hidden by this API can be revealed by revealContent API. |
||
2446 | * |
||
2447 | * @see revealContent |
||
2448 | * |
||
2449 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2450 | */ |
||
2451 | public function hideContent(ContentInfo $contentInfo): void |
||
2476 | |||
2477 | /** |
||
2478 | * Reveals Content hidden by hideContent API. |
||
2479 | * Locations which were hidden before hiding Content will remain hidden. |
||
2480 | * |
||
2481 | * @see hideContent |
||
2482 | * |
||
2483 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2484 | */ |
||
2485 | public function revealContent(ContentInfo $contentInfo): void |
||
2510 | |||
2511 | /** |
||
2512 | * Instantiates a new content create struct object. |
||
2513 | * |
||
2514 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
2515 | * |
||
2516 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
2517 | * @param string $mainLanguageCode |
||
2518 | * |
||
2519 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
2520 | */ |
||
2521 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
2531 | |||
2532 | /** |
||
2533 | * Instantiates a new content meta data update struct. |
||
2534 | * |
||
2535 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
2536 | */ |
||
2537 | public function newContentMetadataUpdateStruct() |
||
2541 | |||
2542 | /** |
||
2543 | * Instantiates a new content update struct. |
||
2544 | * |
||
2545 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
2546 | */ |
||
2547 | public function newContentUpdateStruct() |
||
2551 | |||
2552 | /** |
||
2553 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
2554 | * |
||
2555 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
2556 | */ |
||
2557 | private function resolveUser(?User $user): UserReference |
||
2565 | } |
||
2566 |
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.