Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
53 | class ContentService implements ContentServiceInterface |
||
54 | { |
||
55 | /** |
||
56 | * @var \eZ\Publish\Core\Repository\Repository |
||
57 | */ |
||
58 | protected $repository; |
||
59 | |||
60 | /** |
||
61 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
62 | */ |
||
63 | protected $persistenceHandler; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $settings; |
||
69 | |||
70 | /** |
||
71 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
72 | */ |
||
73 | protected $domainMapper; |
||
74 | |||
75 | /** |
||
76 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
77 | */ |
||
78 | protected $relationProcessor; |
||
79 | |||
80 | /** |
||
81 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
82 | */ |
||
83 | protected $nameSchemaService; |
||
84 | |||
85 | /** |
||
86 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
87 | */ |
||
88 | protected $fieldTypeRegistry; |
||
89 | |||
90 | /** |
||
91 | * Setups service with reference to repository object that created it & corresponding handler. |
||
92 | * |
||
93 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
94 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
95 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
96 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
97 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
98 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|||
99 | * @param array $settings |
||
100 | */ |
||
101 | View Code Duplication | public function __construct( |
|
102 | RepositoryInterface $repository, |
||
103 | Handler $handler, |
||
104 | Helper\DomainMapper $domainMapper, |
||
105 | Helper\RelationProcessor $relationProcessor, |
||
106 | Helper\NameSchemaService $nameSchemaService, |
||
107 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
108 | array $settings = array() |
||
109 | ) { |
||
110 | $this->repository = $repository; |
||
111 | $this->persistenceHandler = $handler; |
||
112 | $this->domainMapper = $domainMapper; |
||
113 | $this->relationProcessor = $relationProcessor; |
||
114 | $this->nameSchemaService = $nameSchemaService; |
||
115 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
116 | // Union makes sure default settings are ignored if provided in argument |
||
117 | $this->settings = $settings + array( |
||
118 | //'defaultSetting' => array(), |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Loads a content info object. |
||
124 | * |
||
125 | * To load fields use loadContent |
||
126 | * |
||
127 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
128 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
129 | * |
||
130 | * @param int $contentId |
||
131 | * |
||
132 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
133 | */ |
||
134 | View Code Duplication | public function loadContentInfo($contentId) |
|
135 | { |
||
136 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
137 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
138 | throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); |
||
139 | } |
||
140 | |||
141 | return $contentInfo; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Loads a content info object. |
||
146 | * |
||
147 | * To load fields use loadContent |
||
148 | * |
||
149 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
150 | * |
||
151 | * @param mixed $id |
||
152 | * @param bool $isRemoteId |
||
153 | * |
||
154 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
155 | */ |
||
156 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
157 | { |
||
158 | try { |
||
159 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
160 | |||
161 | return $this->domainMapper->buildContentInfoDomainObject( |
||
162 | $this->persistenceHandler->contentHandler()->$method($id) |
||
163 | ); |
||
164 | } catch (APINotFoundException $e) { |
||
165 | throw new NotFoundException( |
||
166 | 'Content', |
||
167 | $id, |
||
168 | $e |
||
169 | ); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Loads a content info object for the given remoteId. |
||
175 | * |
||
176 | * To load fields use loadContent |
||
177 | * |
||
178 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
179 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
180 | * |
||
181 | * @param string $remoteId |
||
182 | * |
||
183 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
184 | */ |
||
185 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
186 | { |
||
187 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
188 | |||
189 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
190 | throw new UnauthorizedException('content', 'read', array('remoteId' => $remoteId)); |
||
191 | } |
||
192 | |||
193 | return $contentInfo; |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * Loads a version info of the given content object. |
||
198 | * |
||
199 | * If no version number is given, the method returns the current version |
||
200 | * |
||
201 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
202 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
203 | * |
||
204 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
205 | * @param int $versionNo the version number. If not given the current version is returned. |
||
206 | * |
||
207 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
208 | */ |
||
209 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
213 | |||
214 | /** |
||
215 | * Loads a version info of the given content object id. |
||
216 | * |
||
217 | * If no version number is given, the method returns the current version |
||
218 | * |
||
219 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
220 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
221 | * |
||
222 | * @param mixed $contentId |
||
223 | * @param int $versionNo the version number. If not given the current version is returned. |
||
224 | * |
||
225 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
226 | */ |
||
227 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
228 | { |
||
229 | if ($versionNo === null) { |
||
230 | $versionNo = $this->loadContentInfo($contentId)->currentVersionNo; |
||
231 | } |
||
232 | |||
233 | try { |
||
234 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
235 | $contentId, |
||
236 | $versionNo |
||
237 | ); |
||
238 | } catch (APINotFoundException $e) { |
||
239 | throw new NotFoundException( |
||
240 | 'VersionInfo', |
||
241 | array( |
||
242 | 'contentId' => $contentId, |
||
243 | 'versionNo' => $versionNo, |
||
244 | ), |
||
245 | $e |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
250 | |||
251 | if ($versionInfo->status === APIVersionInfo::STATUS_PUBLISHED) { |
||
252 | $function = 'read'; |
||
253 | } else { |
||
254 | $function = 'versionread'; |
||
255 | } |
||
256 | |||
257 | if (!$this->repository->canUser('content', $function, $versionInfo)) { |
||
258 | throw new UnauthorizedException('content', $function, array('contentId' => $contentId)); |
||
259 | } |
||
260 | |||
261 | return $versionInfo; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * Loads content in a version for the given content info object. |
||
266 | * |
||
267 | * If no version number is given, the method returns the current version |
||
268 | * |
||
269 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
270 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
271 | * |
||
272 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
273 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
274 | * @param int $versionNo the version number. If not given the current version is returned |
||
275 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
276 | * |
||
277 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
278 | */ |
||
279 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
280 | { |
||
281 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
282 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
283 | $useAlwaysAvailable = false; |
||
284 | } |
||
285 | |||
286 | return $this->loadContent( |
||
287 | $contentInfo->id, |
||
288 | $languages, |
||
289 | $versionNo, |
||
290 | $useAlwaysAvailable |
||
291 | ); |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Loads content in the version given by version info. |
||
296 | * |
||
297 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
298 | * |
||
299 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
300 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
301 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
302 | * |
||
303 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
304 | */ |
||
305 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
306 | { |
||
307 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
308 | if ($useAlwaysAvailable && !$versionInfo->getContentInfo()->alwaysAvailable) { |
||
309 | $useAlwaysAvailable = false; |
||
310 | } |
||
311 | |||
312 | return $this->loadContent( |
||
313 | $versionInfo->getContentInfo()->id, |
||
314 | $languages, |
||
315 | $versionInfo->versionNo, |
||
316 | $useAlwaysAvailable |
||
317 | ); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Loads content in a version of the given content object. |
||
322 | * |
||
323 | * If no version number is given, the method returns the current version |
||
324 | * |
||
325 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
326 | * @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 |
||
327 | * |
||
328 | * @param int $contentId |
||
329 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
330 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
331 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
332 | * |
||
333 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
334 | */ |
||
335 | View Code Duplication | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
352 | |||
353 | /** |
||
354 | * Loads content in a version of the given content object. |
||
355 | * |
||
356 | * If no version number is given, the method returns the current version |
||
357 | * |
||
358 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
359 | * |
||
360 | * @param mixed $id |
||
361 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
362 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
363 | * @param bool $isRemoteId |
||
364 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
365 | * |
||
366 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
367 | */ |
||
368 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
369 | { |
||
370 | try { |
||
371 | // Get Content ID if lookup by remote ID |
||
372 | if ($isRemoteId) { |
||
373 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
374 | $id = $spiContentInfo->id; |
||
375 | } |
||
376 | |||
377 | // Get current version if $versionNo is not defined |
||
378 | if ($versionNo === null) { |
||
379 | if (!isset($spiContentInfo)) { |
||
380 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
381 | } |
||
382 | |||
383 | $versionNo = $spiContentInfo->currentVersionNo; |
||
384 | } |
||
385 | |||
386 | $loadLanguages = $languages; |
||
387 | $alwaysAvailableLanguageCode = null; |
||
388 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
389 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
390 | if (!isset($spiContentInfo)) { |
||
391 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
392 | } |
||
393 | |||
394 | if ($spiContentInfo->alwaysAvailable) { |
||
395 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
396 | $loadLanguages = array_unique($loadLanguages); |
||
397 | } |
||
398 | } |
||
399 | |||
400 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
401 | $id, |
||
402 | $versionNo, |
||
403 | $loadLanguages |
||
404 | ); |
||
405 | } catch (APINotFoundException $e) { |
||
406 | throw new NotFoundException( |
||
407 | 'Content', |
||
408 | array( |
||
409 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
410 | 'languages' => $languages, |
||
411 | 'versionNo' => $versionNo, |
||
412 | ), |
||
413 | $e |
||
414 | ); |
||
415 | } |
||
416 | |||
417 | return $this->domainMapper->buildContentDomainObject( |
||
418 | $spiContent, |
||
419 | null, |
||
420 | empty($languages) ? null : $languages, |
||
421 | $alwaysAvailableLanguageCode |
||
422 | ); |
||
423 | } |
||
424 | |||
425 | /** |
||
426 | * Loads content in a version for the content object reference by the given remote id. |
||
427 | * |
||
428 | * If no version is given, the method returns the current version |
||
429 | * |
||
430 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
431 | * @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 |
||
432 | * |
||
433 | * @param string $remoteId |
||
434 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
435 | * @param int $versionNo the version number. If not given the current version is returned |
||
436 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
437 | * |
||
438 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
439 | */ |
||
440 | View Code Duplication | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
457 | |||
458 | /** |
||
459 | * Creates a new content draft assigned to the authenticated user. |
||
460 | * |
||
461 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
462 | * but this required special rights for the authenticated user |
||
463 | * (this is useful for content staging where the transfer process does not |
||
464 | * have to authenticate with the user which created the content object in the source server). |
||
465 | * The user has to publish the draft if it should be visible. |
||
466 | * In 4.x at least one location has to be provided in the location creation array. |
||
467 | * |
||
468 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
469 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
470 | * or there is no location provided (4.x) or multiple locations |
||
471 | * are under the same parent or if the a field value is not accepted by the field type |
||
472 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
473 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value |
||
474 | * |
||
475 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
476 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
477 | * |
||
478 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
479 | */ |
||
480 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
676 | |||
677 | /** |
||
678 | * Returns an array of default content states with content state group id as key. |
||
679 | * |
||
680 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
681 | */ |
||
682 | protected function getDefaultObjectStates() |
||
683 | { |
||
684 | $defaultObjectStatesMap = array(); |
||
685 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
686 | |||
687 | foreach ($objectStateHandler->loadAllGroups() as $objectStateGroup) { |
||
688 | foreach ($objectStateHandler->loadObjectStates($objectStateGroup->id) as $objectState) { |
||
689 | // Only register the first object state which is the default one. |
||
690 | $defaultObjectStatesMap[$objectStateGroup->id] = $objectState; |
||
691 | break; |
||
692 | } |
||
693 | } |
||
694 | |||
695 | return $defaultObjectStatesMap; |
||
696 | } |
||
697 | |||
698 | /** |
||
699 | * Returns all language codes used in given $fields. |
||
700 | * |
||
701 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
702 | * |
||
703 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
704 | * |
||
705 | * @return string[] |
||
706 | */ |
||
707 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
708 | { |
||
709 | $languageCodes = array(); |
||
710 | |||
711 | View Code Duplication | foreach ($contentCreateStruct->fields as $field) { |
|
712 | if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { |
||
713 | continue; |
||
714 | } |
||
715 | |||
716 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
717 | $field->languageCode |
||
718 | ); |
||
719 | $languageCodes[$field->languageCode] = true; |
||
720 | } |
||
721 | |||
722 | if (!isset($languageCodes[$contentCreateStruct->mainLanguageCode])) { |
||
723 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
724 | $contentCreateStruct->mainLanguageCode |
||
725 | ); |
||
726 | $languageCodes[$contentCreateStruct->mainLanguageCode] = true; |
||
727 | } |
||
728 | |||
729 | return array_keys($languageCodes); |
||
730 | } |
||
731 | |||
732 | /** |
||
733 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
734 | * |
||
735 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
736 | * or value is set for non-translatable field in language |
||
737 | * other than main |
||
738 | * |
||
739 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
740 | * |
||
741 | * @return array |
||
742 | */ |
||
743 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
744 | { |
||
745 | $fields = array(); |
||
746 | |||
747 | foreach ($contentCreateStruct->fields as $field) { |
||
748 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier); |
||
749 | |||
750 | if ($fieldDefinition === null) { |
||
751 | throw new ContentValidationException( |
||
752 | "Field definition '%identifier%' does not exist in given ContentType", |
||
753 | ['%identifier%' => $field->fieldDefIdentifier] |
||
754 | ); |
||
755 | } |
||
756 | |||
757 | if ($field->languageCode === null) { |
||
758 | $field = $this->cloneField( |
||
759 | $field, |
||
760 | array('languageCode' => $contentCreateStruct->mainLanguageCode) |
||
761 | ); |
||
762 | } |
||
763 | |||
764 | View Code Duplication | if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { |
|
765 | throw new ContentValidationException( |
||
766 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'", |
||
767 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode] |
||
768 | ); |
||
769 | } |
||
770 | |||
771 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
772 | } |
||
773 | |||
774 | return $fields; |
||
775 | } |
||
776 | |||
777 | /** |
||
778 | * Clones $field with overriding specific properties from given $overrides array. |
||
779 | * |
||
780 | * @param Field $field |
||
781 | * @param array $overrides |
||
782 | * |
||
783 | * @return Field |
||
784 | */ |
||
785 | private function cloneField(Field $field, array $overrides = array()) |
||
786 | { |
||
787 | $fieldData = array_merge( |
||
788 | array( |
||
789 | 'id' => $field->id, |
||
790 | 'value' => $field->value, |
||
791 | 'languageCode' => $field->languageCode, |
||
792 | 'fieldDefIdentifier' => $field->fieldDefIdentifier, |
||
793 | ), |
||
794 | $overrides |
||
795 | ); |
||
796 | |||
797 | return new Field($fieldData); |
||
798 | } |
||
799 | |||
800 | /** |
||
801 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
802 | * |
||
803 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
804 | * |
||
805 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
806 | */ |
||
807 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
808 | { |
||
809 | $spiLocationCreateStructs = array(); |
||
810 | $parentLocationIdSet = array(); |
||
811 | $mainLocation = true; |
||
812 | |||
813 | foreach ($locationCreateStructs as $locationCreateStruct) { |
||
814 | if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) { |
||
815 | throw new InvalidArgumentException( |
||
816 | '$locationCreateStructs', |
||
817 | "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given" |
||
818 | ); |
||
819 | } |
||
820 | |||
821 | $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true; |
||
822 | $parentLocation = $this->repository->getLocationService()->loadLocation( |
||
823 | $locationCreateStruct->parentLocationId |
||
824 | ); |
||
825 | |||
826 | $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct( |
||
827 | $locationCreateStruct, |
||
828 | $parentLocation, |
||
829 | $mainLocation, |
||
830 | // For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation |
||
831 | null, |
||
832 | null |
||
833 | ); |
||
834 | |||
835 | // First Location in the list will be created as main Location |
||
836 | $mainLocation = false; |
||
837 | } |
||
838 | |||
839 | return $spiLocationCreateStructs; |
||
840 | } |
||
841 | |||
842 | /** |
||
843 | * Updates the metadata. |
||
844 | * |
||
845 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
846 | * |
||
847 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
848 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
849 | * |
||
850 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
851 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
852 | * |
||
853 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
854 | */ |
||
855 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
856 | { |
||
857 | $propertyCount = 0; |
||
858 | foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { |
||
859 | if (isset($contentMetadataUpdateStruct->$propertyName)) { |
||
860 | $propertyCount += 1; |
||
861 | } |
||
862 | } |
||
863 | if ($propertyCount === 0) { |
||
864 | throw new InvalidArgumentException( |
||
865 | '$contentMetadataUpdateStruct', |
||
866 | 'At least one property must be set' |
||
867 | ); |
||
868 | } |
||
869 | |||
870 | $loadedContentInfo = $this->loadContentInfo($contentInfo->id); |
||
871 | |||
872 | if (!$this->repository->canUser('content', 'edit', $loadedContentInfo)) { |
||
873 | throw new UnauthorizedException('content', 'edit', array('contentId' => $loadedContentInfo->id)); |
||
874 | } |
||
875 | |||
876 | if (isset($contentMetadataUpdateStruct->remoteId)) { |
||
877 | try { |
||
878 | $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId); |
||
879 | |||
880 | if ($existingContentInfo->id !== $loadedContentInfo->id) { |
||
881 | throw new InvalidArgumentException( |
||
882 | '$contentMetadataUpdateStruct', |
||
883 | "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists" |
||
884 | ); |
||
885 | } |
||
886 | } catch (APINotFoundException $e) { |
||
887 | // Do nothing |
||
888 | } |
||
889 | } |
||
890 | |||
891 | $this->repository->beginTransaction(); |
||
892 | try { |
||
893 | if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) { |
||
894 | $this->persistenceHandler->contentHandler()->updateMetadata( |
||
895 | $loadedContentInfo->id, |
||
896 | new SPIMetadataUpdateStruct( |
||
897 | array( |
||
898 | 'ownerId' => $contentMetadataUpdateStruct->ownerId, |
||
899 | 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ? |
||
900 | $contentMetadataUpdateStruct->publishedDate->getTimestamp() : |
||
901 | null, |
||
902 | 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ? |
||
903 | $contentMetadataUpdateStruct->modificationDate->getTimestamp() : |
||
904 | null, |
||
905 | 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ? |
||
906 | $this->repository->getContentLanguageService()->loadLanguage( |
||
907 | $contentMetadataUpdateStruct->mainLanguageCode |
||
908 | )->id : |
||
909 | null, |
||
910 | 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable, |
||
911 | 'remoteId' => $contentMetadataUpdateStruct->remoteId, |
||
912 | ) |
||
913 | ) |
||
914 | ); |
||
915 | } |
||
916 | |||
917 | // Change main location |
||
918 | if (isset($contentMetadataUpdateStruct->mainLocationId) |
||
919 | && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) { |
||
920 | $this->persistenceHandler->locationHandler()->changeMainLocation( |
||
921 | $loadedContentInfo->id, |
||
922 | $contentMetadataUpdateStruct->mainLocationId |
||
923 | ); |
||
924 | } |
||
925 | |||
926 | // Republish URL aliases to update always-available flag |
||
927 | if (isset($contentMetadataUpdateStruct->alwaysAvailable) |
||
928 | && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) { |
||
929 | $content = $this->loadContent($loadedContentInfo->id); |
||
930 | $this->publishUrlAliasesForContent($content, false); |
||
931 | } |
||
932 | |||
933 | $this->repository->commit(); |
||
934 | } catch (Exception $e) { |
||
935 | $this->repository->rollback(); |
||
936 | throw $e; |
||
937 | } |
||
938 | |||
939 | return isset($content) ? $content : $this->loadContent($loadedContentInfo->id); |
||
940 | } |
||
941 | |||
942 | /** |
||
943 | * Publishes URL aliases for all locations of a given content. |
||
944 | * |
||
945 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
946 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
947 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
948 | */ |
||
949 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
968 | |||
969 | /** |
||
970 | * Deletes a content object including all its versions and locations including their subtrees. |
||
971 | * |
||
972 | * @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) |
||
973 | * |
||
974 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
975 | */ |
||
976 | public function deleteContent(ContentInfo $contentInfo) |
||
977 | { |
||
978 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id); |
||
979 | |||
980 | if (!$this->repository->canUser('content', 'remove', $contentInfo)) { |
||
981 | throw new UnauthorizedException('content', 'remove', array('contentId' => $contentInfo->id)); |
||
982 | } |
||
983 | |||
984 | $this->repository->beginTransaction(); |
||
985 | try { |
||
986 | // Load Locations first as deleting Content also deletes belonging Locations |
||
987 | $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id); |
||
988 | $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id); |
||
989 | foreach ($spiLocations as $spiLocation) { |
||
990 | $this->persistenceHandler->urlAliasHandler()->locationDeleted($spiLocation->id); |
||
991 | } |
||
992 | $this->repository->commit(); |
||
993 | } catch (Exception $e) { |
||
994 | $this->repository->rollback(); |
||
995 | throw $e; |
||
996 | } |
||
997 | } |
||
998 | |||
999 | /** |
||
1000 | * Creates a draft from a published or archived version. |
||
1001 | * |
||
1002 | * If no version is given, the current published version is used. |
||
1003 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
1004 | * It can be changed on updating the version. |
||
1005 | * |
||
1006 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
1007 | * |
||
1008 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1009 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1010 | * @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 |
||
1011 | * |
||
1012 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
1013 | */ |
||
1014 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
1015 | { |
||
1016 | $contentInfo = $this->loadContentInfo($contentInfo->id); |
||
1017 | |||
1018 | if ($versionInfo !== null) { |
||
1019 | // Check that given $contentInfo and $versionInfo belong to the same content |
||
1020 | if ($versionInfo->getContentInfo()->id != $contentInfo->id) { |
||
1021 | throw new InvalidArgumentException( |
||
1022 | '$versionInfo', |
||
1023 | 'VersionInfo does not belong to the same content as given ContentInfo' |
||
1024 | ); |
||
1025 | } |
||
1026 | |||
1027 | $versionInfo = $this->loadVersionInfoById($contentInfo->id, $versionInfo->versionNo); |
||
1028 | |||
1029 | switch ($versionInfo->status) { |
||
1030 | case VersionInfo::STATUS_PUBLISHED: |
||
1031 | case VersionInfo::STATUS_ARCHIVED: |
||
1032 | break; |
||
1033 | |||
1034 | default: |
||
1035 | // @todo: throw an exception here, to be defined |
||
1036 | throw new BadStateException( |
||
1037 | '$versionInfo', |
||
1038 | 'Draft can not be created from a draft version' |
||
1039 | ); |
||
1040 | } |
||
1041 | |||
1042 | $versionNo = $versionInfo->versionNo; |
||
1043 | } elseif ($contentInfo->published) { |
||
1044 | $versionNo = $contentInfo->currentVersionNo; |
||
1045 | } else { |
||
1046 | // @todo: throw an exception here, to be defined |
||
1047 | throw new BadStateException( |
||
1048 | '$contentInfo', |
||
1049 | 'Content is not published, draft can be created only from published or archived version' |
||
1050 | ); |
||
1051 | } |
||
1052 | |||
1053 | if ($creator === null) { |
||
1054 | $creator = $this->repository->getCurrentUserReference(); |
||
1055 | } |
||
1056 | |||
1057 | if (!$this->repository->canUser('content', 'edit', $contentInfo)) { |
||
1058 | throw new UnauthorizedException('content', 'edit', array('contentId' => $contentInfo->id)); |
||
1059 | } |
||
1060 | |||
1061 | $this->repository->beginTransaction(); |
||
1062 | try { |
||
1063 | $spiContent = $this->persistenceHandler->contentHandler()->createDraftFromVersion( |
||
1064 | $contentInfo->id, |
||
1065 | $versionNo, |
||
1066 | $creator->getUserId() |
||
1067 | ); |
||
1068 | $this->repository->commit(); |
||
1069 | } catch (Exception $e) { |
||
1070 | $this->repository->rollback(); |
||
1071 | throw $e; |
||
1072 | } |
||
1073 | |||
1074 | return $this->domainMapper->buildContentDomainObject($spiContent); |
||
1075 | } |
||
1076 | |||
1077 | /** |
||
1078 | * Loads drafts for a user. |
||
1079 | * |
||
1080 | * If no user is given the drafts for the authenticated user a returned |
||
1081 | * |
||
1082 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
1083 | * |
||
1084 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
1085 | * |
||
1086 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
1087 | */ |
||
1088 | public function loadContentDrafts(User $user = null) |
||
1089 | { |
||
1090 | if ($user === null) { |
||
1091 | $user = $this->repository->getCurrentUserReference(); |
||
1092 | } |
||
1093 | |||
1094 | // throw early if user has absolutely no access to versionread |
||
1095 | if ($this->repository->hasAccess('content', 'versionread') === false) { |
||
1096 | throw new UnauthorizedException('content', 'versionread'); |
||
1097 | } |
||
1098 | |||
1099 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftsForUser($user->getUserId()); |
||
1100 | $versionInfoList = array(); |
||
1101 | View Code Duplication | foreach ($spiVersionInfoList as $spiVersionInfo) { |
|
1102 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
1103 | if (!$this->repository->canUser('content', 'versionread', $versionInfo)) { |
||
1104 | throw new UnauthorizedException('content', 'versionread', array('contentId' => $versionInfo->contentInfo->id)); |
||
1105 | } |
||
1106 | |||
1107 | $versionInfoList[] = $versionInfo; |
||
1108 | } |
||
1109 | |||
1110 | return $versionInfoList; |
||
1111 | } |
||
1112 | |||
1113 | /** |
||
1114 | * Translate a version. |
||
1115 | * |
||
1116 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
1117 | * |
||
1118 | * @example Examples/translation_5x.php |
||
1119 | * |
||
1120 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
1121 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
1122 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
1123 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid |
||
1124 | * |
||
1125 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
1126 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
1127 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
1128 | * |
||
1129 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
1130 | * |
||
1131 | * @since 5.0 |
||
1132 | */ |
||
1133 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
1137 | |||
1138 | /** |
||
1139 | * Updates the fields of a draft. |
||
1140 | * |
||
1141 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
1142 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1143 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
1144 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
1145 | * |
||
1146 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1147 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1148 | * |
||
1149 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
1150 | */ |
||
1151 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
1152 | { |
||
1153 | $contentUpdateStruct = clone $contentUpdateStruct; |
||
1154 | |||
1313 | |||
1314 | /** |
||
1315 | * Returns all language codes used in given $fields. |
||
1316 | * |
||
1317 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
1318 | * |
||
1319 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1320 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
1321 | * |
||
1322 | * @return array |
||
1323 | */ |
||
1324 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
1350 | |||
1351 | /** |
||
1352 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
1353 | * |
||
1354 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
1355 | * or value is set for non-translatable field in language |
||
1356 | * other than main |
||
1357 | * |
||
1358 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1359 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
1360 | * @param string $mainLanguageCode |
||
1361 | * |
||
1362 | * @return array |
||
1363 | */ |
||
1364 | protected function mapFieldsForUpdate( |
||
1402 | |||
1403 | /** |
||
1404 | * Publishes a content version. |
||
1405 | * |
||
1406 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
1407 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1408 | * |
||
1409 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1410 | * |
||
1411 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1412 | */ |
||
1413 | public function publishVersion(APIVersionInfo $versionInfo) |
||
1440 | |||
1441 | /** |
||
1442 | * Publishes a content version. |
||
1443 | * |
||
1444 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1445 | * |
||
1446 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1447 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
1448 | * |
||
1449 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1450 | */ |
||
1451 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
1476 | |||
1477 | /** |
||
1478 | * Removes the given version. |
||
1479 | * |
||
1480 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
1481 | * published state or is the last version of the Content |
||
1482 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
1483 | * |
||
1484 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1485 | */ |
||
1486 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
1526 | |||
1527 | /** |
||
1528 | * Loads all versions for the given content. |
||
1529 | * |
||
1530 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
1531 | * |
||
1532 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1533 | * |
||
1534 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
1535 | */ |
||
1536 | public function loadVersions(ContentInfo $contentInfo) |
||
1567 | |||
1568 | /** |
||
1569 | * Copies the content to a new location. If no version is given, |
||
1570 | * all versions are copied, otherwise only the given version. |
||
1571 | * |
||
1572 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
1573 | * |
||
1574 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1575 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
1576 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1577 | * |
||
1578 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1579 | */ |
||
1580 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
1581 | { |
||
1582 | View Code Duplication | if (!$this->repository->canUser('content', 'create', $contentInfo, $destinationLocationCreateStruct)) { |
|
1583 | throw new UnauthorizedException( |
||
1584 | 'content', |
||
1585 | 'create', |
||
1586 | array( |
||
1587 | 'parentLocationId' => $destinationLocationCreateStruct->parentLocationId, |
||
1588 | 'sectionId' => $contentInfo->sectionId, |
||
1589 | ) |
||
1590 | ); |
||
1591 | } |
||
1592 | |||
1593 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
1594 | |||
1595 | $this->repository->beginTransaction(); |
||
1596 | try { |
||
1597 | $spiContent = $this->persistenceHandler->contentHandler()->copy( |
||
1598 | $contentInfo->id, |
||
1599 | $versionInfo ? $versionInfo->versionNo : null |
||
1600 | ); |
||
1601 | |||
1602 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
1603 | $this->persistenceHandler->objectStateHandler()->setContentState( |
||
1604 | $spiContent->versionInfo->contentInfo->id, |
||
1605 | $objectStateGroupId, |
||
1606 | $objectState->id |
||
1607 | ); |
||
1608 | } |
||
1609 | |||
1610 | $content = $this->internalPublishVersion( |
||
1611 | $this->domainMapper->buildVersionInfoDomainObject($spiContent->versionInfo), |
||
1612 | $spiContent->versionInfo->creationDate |
||
1613 | ); |
||
1614 | |||
1615 | $this->repository->getLocationService()->createLocation( |
||
1616 | $content->getVersionInfo()->getContentInfo(), |
||
1617 | $destinationLocationCreateStruct |
||
1618 | ); |
||
1619 | $this->repository->commit(); |
||
1620 | } catch (Exception $e) { |
||
1621 | $this->repository->rollback(); |
||
1622 | throw $e; |
||
1623 | } |
||
1624 | |||
1625 | return $this->internalLoadContent($content->id); |
||
1626 | } |
||
1627 | |||
1628 | /** |
||
1629 | * Loads all outgoing relations for the given version. |
||
1630 | * |
||
1631 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1632 | * |
||
1633 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1634 | * |
||
1635 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1636 | */ |
||
1637 | public function loadRelations(APIVersionInfo $versionInfo) |
||
1672 | |||
1673 | /** |
||
1674 | * Loads all incoming relations for a content object. |
||
1675 | * |
||
1676 | * The relations come only from published versions of the source content objects |
||
1677 | * |
||
1678 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1679 | * |
||
1680 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1681 | * |
||
1682 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1683 | */ |
||
1684 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
1710 | |||
1711 | /** |
||
1712 | * Adds a relation of type common. |
||
1713 | * |
||
1714 | * The source of the relation is the content and version |
||
1715 | * referenced by $versionInfo. |
||
1716 | * |
||
1717 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
1718 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1719 | * |
||
1720 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
1721 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
1722 | * |
||
1723 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
1724 | */ |
||
1725 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
1766 | |||
1767 | /** |
||
1768 | * Removes a relation of type COMMON from a draft. |
||
1769 | * |
||
1770 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
1771 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1772 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
1773 | * |
||
1774 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
1775 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
1776 | */ |
||
1777 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
1827 | |||
1828 | /** |
||
1829 | * Adds translation information to the content object. |
||
1830 | * |
||
1831 | * @example Examples/translation_5x.php |
||
1832 | * |
||
1833 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
1834 | * |
||
1835 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
1836 | * |
||
1837 | * @since 5.0 |
||
1838 | */ |
||
1839 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
1843 | |||
1844 | /** |
||
1845 | * lists the translations done on this content object. |
||
1846 | * |
||
1847 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
1848 | * |
||
1849 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1850 | * @param array $filter |
||
1851 | * |
||
1852 | * @todo TBD - filter by source version destination version and languages |
||
1853 | * |
||
1854 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
1855 | * |
||
1856 | * @since 5.0 |
||
1857 | */ |
||
1858 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
1862 | |||
1863 | /** |
||
1864 | * Instantiates a new content create struct object. |
||
1865 | * |
||
1866 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
1867 | * @param string $mainLanguageCode |
||
1868 | * |
||
1869 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
1870 | */ |
||
1871 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
1880 | |||
1881 | /** |
||
1882 | * Instantiates a new content meta data update struct. |
||
1883 | * |
||
1884 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
1885 | */ |
||
1886 | public function newContentMetadataUpdateStruct() |
||
1890 | |||
1891 | /** |
||
1892 | * Instantiates a new content update struct. |
||
1893 | * |
||
1894 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
1895 | */ |
||
1896 | public function newContentUpdateStruct() |
||
1900 | |||
1901 | /** |
||
1902 | * Instantiates a new TranslationInfo object. |
||
1903 | * |
||
1904 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
1905 | */ |
||
1906 | public function newTranslationInfo() |
||
1910 | |||
1911 | /** |
||
1912 | * Instantiates a Translation object. |
||
1913 | * |
||
1914 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
1915 | */ |
||
1916 | public function newTranslationValues() |
||
1920 | } |
||
1921 |
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.