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 |
||
55 | class ContentService implements ContentServiceInterface |
||
56 | { |
||
57 | /** @var \eZ\Publish\Core\Repository\Repository */ |
||
58 | protected $repository; |
||
59 | |||
60 | /** @var \eZ\Publish\SPI\Persistence\Handler */ |
||
61 | protected $persistenceHandler; |
||
62 | |||
63 | /** @var array */ |
||
64 | protected $settings; |
||
65 | |||
66 | /** @var \eZ\Publish\Core\Repository\Helper\DomainMapper */ |
||
67 | protected $domainMapper; |
||
68 | |||
69 | /** @var \eZ\Publish\Core\Repository\Helper\RelationProcessor */ |
||
70 | protected $relationProcessor; |
||
71 | |||
72 | /** @var \eZ\Publish\Core\Repository\Helper\NameSchemaService */ |
||
73 | protected $nameSchemaService; |
||
74 | |||
75 | /** @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry */ |
||
76 | protected $fieldTypeRegistry; |
||
77 | |||
78 | /** |
||
79 | * Setups service with reference to repository object that created it & corresponding handler. |
||
80 | * |
||
81 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
82 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
83 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
84 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
85 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
86 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|||
87 | * @param array $settings |
||
88 | */ |
||
89 | public function __construct( |
||
90 | RepositoryInterface $repository, |
||
91 | Handler $handler, |
||
92 | Helper\DomainMapper $domainMapper, |
||
93 | Helper\RelationProcessor $relationProcessor, |
||
94 | Helper\NameSchemaService $nameSchemaService, |
||
95 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
96 | array $settings = [] |
||
97 | ) { |
||
98 | $this->repository = $repository; |
||
99 | $this->persistenceHandler = $handler; |
||
100 | $this->domainMapper = $domainMapper; |
||
101 | $this->relationProcessor = $relationProcessor; |
||
102 | $this->nameSchemaService = $nameSchemaService; |
||
103 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
104 | // Union makes sure default settings are ignored if provided in argument |
||
105 | $this->settings = $settings + [ |
||
106 | // Version archive limit (0-50), only enforced on publish, not on un-publish. |
||
107 | 'default_version_archive_limit' => 5, |
||
108 | ]; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Loads a content info object. |
||
113 | * |
||
114 | * To load fields use loadContent |
||
115 | * |
||
116 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
117 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
118 | * |
||
119 | * @param int $contentId |
||
120 | * |
||
121 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
122 | */ |
||
123 | public function loadContentInfo($contentId) |
||
124 | { |
||
125 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
126 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
127 | throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); |
||
128 | } |
||
129 | |||
130 | return $contentInfo; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public function loadContentInfoList(array $contentIds): iterable |
||
137 | { |
||
138 | $contentInfoList = []; |
||
139 | $spiInfoList = $this->persistenceHandler->contentHandler()->loadContentInfoList($contentIds); |
||
140 | foreach ($spiInfoList as $id => $spiInfo) { |
||
141 | $contentInfo = $this->domainMapper->buildContentInfoDomainObject($spiInfo); |
||
142 | if ($this->repository->canUser('content', 'read', $contentInfo)) { |
||
143 | $contentInfoList[$id] = $contentInfo; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return $contentInfoList; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Loads a content info object. |
||
152 | * |
||
153 | * To load fields use loadContent |
||
154 | * |
||
155 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
156 | * |
||
157 | * @param mixed $id |
||
158 | * @param bool $isRemoteId |
||
159 | * |
||
160 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
161 | */ |
||
162 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
163 | { |
||
164 | try { |
||
165 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
166 | |||
167 | return $this->domainMapper->buildContentInfoDomainObject( |
||
168 | $this->persistenceHandler->contentHandler()->$method($id) |
||
169 | ); |
||
170 | } catch (APINotFoundException $e) { |
||
171 | throw new NotFoundException( |
||
172 | 'Content', |
||
173 | $id, |
||
174 | $e |
||
175 | ); |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Loads a content info object for the given remoteId. |
||
181 | * |
||
182 | * To load fields use loadContent |
||
183 | * |
||
184 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
185 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
186 | * |
||
187 | * @param string $remoteId |
||
188 | * |
||
189 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
190 | */ |
||
191 | public function loadContentInfoByRemoteId($remoteId) |
||
192 | { |
||
193 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
194 | |||
195 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
196 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
197 | } |
||
198 | |||
199 | return $contentInfo; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Loads a version info of the given content object. |
||
204 | * |
||
205 | * If no version number is given, the method returns the current version |
||
206 | * |
||
207 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
208 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
209 | * |
||
210 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
211 | * @param int $versionNo the version number. If not given the current version is returned. |
||
212 | * |
||
213 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
214 | */ |
||
215 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
216 | { |
||
217 | return $this->loadVersionInfoById($contentInfo->id, $versionNo); |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Loads a version info of the given content object id. |
||
222 | * |
||
223 | * If no version number is given, the method returns the current version |
||
224 | * |
||
225 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
226 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
227 | * |
||
228 | * @param mixed $contentId |
||
229 | * @param int $versionNo the version number. If not given the current version is returned. |
||
230 | * |
||
231 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
232 | */ |
||
233 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
234 | { |
||
235 | // @todo SPI should also support null to avoid concurrency issues |
||
236 | if ($versionNo === null) { |
||
237 | $versionNo = $this->loadContentInfo($contentId)->currentVersionNo; |
||
238 | } |
||
239 | |||
240 | try { |
||
241 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
242 | $contentId, |
||
243 | $versionNo |
||
244 | ); |
||
245 | } catch (APINotFoundException $e) { |
||
246 | throw new NotFoundException( |
||
247 | 'VersionInfo', |
||
248 | [ |
||
249 | 'contentId' => $contentId, |
||
250 | 'versionNo' => $versionNo, |
||
251 | ], |
||
252 | $e |
||
253 | ); |
||
254 | } |
||
255 | |||
256 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
257 | |||
258 | if ($versionInfo->isPublished()) { |
||
259 | $function = 'read'; |
||
260 | } else { |
||
261 | $function = 'versionread'; |
||
262 | } |
||
263 | |||
264 | if (!$this->repository->canUser('content', $function, $versionInfo)) { |
||
265 | throw new UnauthorizedException('content', $function, ['contentId' => $contentId]); |
||
266 | } |
||
267 | |||
268 | return $versionInfo; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * {@inheritdoc} |
||
273 | */ |
||
274 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
275 | { |
||
276 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
277 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
278 | $useAlwaysAvailable = false; |
||
279 | } |
||
280 | |||
281 | return $this->loadContent( |
||
282 | $contentInfo->id, |
||
283 | $languages, |
||
284 | $versionNo,// On purpose pass as-is and not use $contentInfo, to make sure to return actual current version on null |
||
285 | $useAlwaysAvailable |
||
286 | ); |
||
287 | } |
||
288 | |||
289 | /** |
||
290 | * {@inheritdoc} |
||
291 | */ |
||
292 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
306 | |||
307 | /** |
||
308 | * {@inheritdoc} |
||
309 | */ |
||
310 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
311 | { |
||
312 | $content = $this->internalLoadContent($contentId, $languages, $versionNo, false, $useAlwaysAvailable); |
||
313 | |||
314 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
326 | |||
327 | /** |
||
328 | * Loads content in a version of the given content object. |
||
329 | * |
||
330 | * If no version number is given, the method returns the current version |
||
331 | * |
||
332 | * @internal |
||
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) |
||
396 | |||
397 | /** |
||
398 | * Loads content in a version for the content object reference by the given remote id. |
||
399 | * |
||
400 | * If no version is given, the method returns the current version |
||
401 | * |
||
402 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
403 | * @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 |
||
404 | * |
||
405 | * @param string $remoteId |
||
406 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
407 | * @param int $versionNo the version number. If not given the current version is returned |
||
408 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
409 | * |
||
410 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
411 | */ |
||
412 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
429 | |||
430 | /** |
||
431 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
432 | * |
||
433 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
434 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
435 | * allowed to access every Content on the list. |
||
436 | * |
||
437 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
438 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
439 | * returned value object. If not given all languages are returned. |
||
440 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
441 | * unless all languages have been asked for. |
||
442 | * |
||
443 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
444 | */ |
||
445 | public function loadContentListByContentInfo( |
||
486 | |||
487 | /** |
||
488 | * Creates a new content draft assigned to the authenticated user. |
||
489 | * |
||
490 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
491 | * but this required special rights for the authenticated user |
||
492 | * (this is useful for content staging where the transfer process does not |
||
493 | * have to authenticate with the user which created the content object in the source server). |
||
494 | * The user has to publish the draft if it should be visible. |
||
495 | * In 4.x at least one location has to be provided in the location creation array. |
||
496 | * |
||
497 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
498 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
499 | * struct are missing or invalid, or if multiple locations are under the |
||
500 | * same parent. |
||
501 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
502 | * or if a required field is missing / set to an empty value. |
||
503 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
504 | * or value is set for non-translatable field in language |
||
505 | * other than main. |
||
506 | * |
||
507 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
508 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
509 | * |
||
510 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
511 | */ |
||
512 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = []) |
||
714 | |||
715 | /** |
||
716 | * Returns an array of default content states with content state group id as key. |
||
717 | * |
||
718 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
719 | */ |
||
720 | protected function getDefaultObjectStates() |
||
735 | |||
736 | /** |
||
737 | * Returns all language codes used in given $fields. |
||
738 | * |
||
739 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
740 | * |
||
741 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
742 | * |
||
743 | * @return string[] |
||
744 | */ |
||
745 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
769 | |||
770 | /** |
||
771 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
772 | * |
||
773 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
774 | * or value is set for non-translatable field in language |
||
775 | * other than main |
||
776 | * |
||
777 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
778 | * |
||
779 | * @return array |
||
780 | */ |
||
781 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
814 | |||
815 | /** |
||
816 | * Clones $field with overriding specific properties from given $overrides array. |
||
817 | * |
||
818 | * @param Field $field |
||
819 | * @param array $overrides |
||
820 | * |
||
821 | * @return Field |
||
822 | */ |
||
823 | private function cloneField(Field $field, array $overrides = []) |
||
838 | |||
839 | /** |
||
840 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
841 | * |
||
842 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
843 | * |
||
844 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
845 | */ |
||
846 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
888 | |||
889 | /** |
||
890 | * Updates the metadata. |
||
891 | * |
||
892 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
893 | * |
||
894 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
895 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
896 | * |
||
897 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
898 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
899 | * |
||
900 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
901 | */ |
||
902 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
989 | |||
990 | /** |
||
991 | * Publishes URL aliases for all locations of a given content. |
||
992 | * |
||
993 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
994 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
995 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
996 | */ |
||
997 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
1023 | |||
1024 | /** |
||
1025 | * Deletes a content object including all its versions and locations including their subtrees. |
||
1026 | * |
||
1027 | * @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) |
||
1028 | * |
||
1029 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1030 | * |
||
1031 | * @return mixed[] Affected Location Id's |
||
1032 | */ |
||
1033 | public function deleteContent(ContentInfo $contentInfo) |
||
1060 | |||
1061 | /** |
||
1062 | * Creates a draft from a published or archived version. |
||
1063 | * |
||
1064 | * If no version is given, the current published version is used. |
||
1065 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
1066 | * It can be changed on updating the version. |
||
1067 | * |
||
1068 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1069 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1070 | * @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 |
||
1071 | * |
||
1072 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
1073 | * |
||
1074 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
1075 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the current-user is not allowed to create the draft |
||
1076 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
1077 | */ |
||
1078 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
1158 | |||
1159 | /** |
||
1160 | * Counts drafts for a user. |
||
1161 | * |
||
1162 | * If no user is given the number of drafts for the authenticated user a returned |
||
1163 | * |
||
1164 | * @param \eZ\Publish\API\Repository\Values\User\User $user The user to load drafts from if defined, otherwise drafts for current-user |
||
1165 | * |
||
1166 | * @return int The number of drafts ({@link VersionInfo}) owned by the given user |
||
1167 | */ |
||
1168 | public function countContentDrafts(?User $user = null): int |
||
1174 | |||
1175 | /** |
||
1176 | * Loads drafts for a user. |
||
1177 | * |
||
1178 | * If no user is given the drafts for the authenticated user a returned |
||
1179 | * |
||
1180 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1181 | * |
||
1182 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Drafts owned by the given user |
||
1183 | * |
||
1184 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1185 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1186 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1187 | */ |
||
1188 | public function loadContentDrafts(User $user = null) |
||
1211 | |||
1212 | /** |
||
1213 | * {@inheritdoc} |
||
1214 | */ |
||
1215 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList |
||
1251 | |||
1252 | /** |
||
1253 | * Updates the fields of a draft. |
||
1254 | * |
||
1255 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1256 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1257 | * |
||
1258 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
1259 | * |
||
1260 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
1261 | * or if a required field is missing / set to an empty value. |
||
1262 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
1263 | * or value is set for non-translatable field in language |
||
1264 | * other than main. |
||
1265 | * |
||
1266 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
1267 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1268 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
1269 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1270 | */ |
||
1271 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
1458 | |||
1459 | /** |
||
1460 | * Returns only updated language codes. |
||
1461 | * |
||
1462 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1463 | * |
||
1464 | * @return array |
||
1465 | */ |
||
1466 | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
||
1482 | |||
1483 | /** |
||
1484 | * Returns all language codes used in given $fields. |
||
1485 | * |
||
1486 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
1487 | * |
||
1488 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1489 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
1490 | * |
||
1491 | * @return array |
||
1492 | */ |
||
1493 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
1505 | |||
1506 | /** |
||
1507 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
1508 | * |
||
1509 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
1510 | * or value is set for non-translatable field in language |
||
1511 | * other than main |
||
1512 | * |
||
1513 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
1514 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
1515 | * @param string $mainLanguageCode |
||
1516 | * |
||
1517 | * @return array |
||
1518 | */ |
||
1519 | protected function mapFieldsForUpdate( |
||
1557 | |||
1558 | /** |
||
1559 | * Publishes a content version. |
||
1560 | * |
||
1561 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1562 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1563 | * |
||
1564 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1565 | * @param string[] $translations |
||
1566 | * |
||
1567 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1568 | * |
||
1569 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1570 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1571 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1572 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1573 | */ |
||
1574 | public function publishVersion(APIVersionInfo $versionInfo, array $translations = Language::ALL) |
||
1617 | |||
1618 | /** |
||
1619 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1620 | * @param array $translations |
||
1621 | * |
||
1622 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
1623 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
1624 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
1625 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1626 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1627 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
1628 | */ |
||
1629 | protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionInfo, array $translations = []): void |
||
1678 | |||
1679 | /** |
||
1680 | * Publishes a content version. |
||
1681 | * |
||
1682 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
1683 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
1684 | * |
||
1685 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
1686 | * |
||
1687 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1688 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
1689 | * |
||
1690 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1691 | */ |
||
1692 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
1742 | |||
1743 | /** |
||
1744 | * @return int |
||
1745 | */ |
||
1746 | protected function getUnixTimestamp() |
||
1750 | |||
1751 | /** |
||
1752 | * Removes the given version. |
||
1753 | * |
||
1754 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
1755 | * published state or is a last version of Content in non draft state |
||
1756 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
1757 | * |
||
1758 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1759 | */ |
||
1760 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
1802 | |||
1803 | /** |
||
1804 | * Loads all versions for the given content. |
||
1805 | * |
||
1806 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
1807 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
1808 | * |
||
1809 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1810 | * @param int|null $status |
||
1811 | * |
||
1812 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
1813 | */ |
||
1814 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
1843 | |||
1844 | /** |
||
1845 | * Copies the content to a new location. If no version is given, |
||
1846 | * all versions are copied, otherwise only the given version. |
||
1847 | * |
||
1848 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
1849 | * |
||
1850 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1851 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
1852 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1853 | * |
||
1854 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
1855 | */ |
||
1856 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
1911 | |||
1912 | /** |
||
1913 | * Loads all outgoing relations for the given version. |
||
1914 | * |
||
1915 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1916 | * |
||
1917 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
1918 | * |
||
1919 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1920 | */ |
||
1921 | public function loadRelations(APIVersionInfo $versionInfo) |
||
1956 | |||
1957 | /** |
||
1958 | * Loads all incoming relations for a content object. |
||
1959 | * |
||
1960 | * The relations come only from published versions of the source content objects |
||
1961 | * |
||
1962 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
1963 | * |
||
1964 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1965 | * |
||
1966 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
1967 | */ |
||
1968 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
1994 | |||
1995 | /** |
||
1996 | * Adds a relation of type common. |
||
1997 | * |
||
1998 | * The source of the relation is the content and version |
||
1999 | * referenced by $versionInfo. |
||
2000 | * |
||
2001 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
2002 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2003 | * |
||
2004 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2005 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
2006 | * |
||
2007 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
2008 | */ |
||
2009 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2050 | |||
2051 | /** |
||
2052 | * Removes a relation of type COMMON from a draft. |
||
2053 | * |
||
2054 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
2055 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
2056 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
2057 | * |
||
2058 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
2059 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
2060 | */ |
||
2061 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
2111 | |||
2112 | /** |
||
2113 | * {@inheritdoc} |
||
2114 | */ |
||
2115 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
2123 | |||
2124 | /** |
||
2125 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
2126 | * |
||
2127 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
2128 | * |
||
2129 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2130 | * is the Main Translation of a Content Item. |
||
2131 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2132 | * to delete the content (in one of the locations of the given Content Item). |
||
2133 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2134 | * is invalid for the given content. |
||
2135 | * |
||
2136 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2137 | * @param string $languageCode |
||
2138 | * |
||
2139 | * @since 6.13 |
||
2140 | */ |
||
2141 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
2218 | |||
2219 | /** |
||
2220 | * Delete specified Translation from a Content Draft. |
||
2221 | * |
||
2222 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
2223 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
2224 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
2225 | * to edit the Content (in one of the locations of the given Content Object). |
||
2226 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
2227 | * is invalid for the given Draft. |
||
2228 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
2229 | * |
||
2230 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
2231 | * @param string $languageCode Language code of the Translation to be removed |
||
2232 | * |
||
2233 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
2234 | * |
||
2235 | * @since 6.12 |
||
2236 | */ |
||
2237 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode) |
||
2303 | |||
2304 | /** |
||
2305 | * Hides Content by making all the Locations appear hidden. |
||
2306 | * It does not persist hidden state on Location object itself. |
||
2307 | * |
||
2308 | * Content hidden by this API can be revealed by revealContent API. |
||
2309 | * |
||
2310 | * @see revealContent |
||
2311 | * |
||
2312 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2313 | */ |
||
2314 | public function hideContent(ContentInfo $contentInfo): void |
||
2339 | |||
2340 | /** |
||
2341 | * Reveals Content hidden by hideContent API. |
||
2342 | * Locations which were hidden before hiding Content will remain hidden. |
||
2343 | * |
||
2344 | * @see hideContent |
||
2345 | * |
||
2346 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
2347 | */ |
||
2348 | public function revealContent(ContentInfo $contentInfo): void |
||
2373 | |||
2374 | /** |
||
2375 | * Instantiates a new content create struct object. |
||
2376 | * |
||
2377 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
2378 | * |
||
2379 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
2380 | * @param string $mainLanguageCode |
||
2381 | * |
||
2382 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
2383 | */ |
||
2384 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
2394 | |||
2395 | /** |
||
2396 | * Instantiates a new content meta data update struct. |
||
2397 | * |
||
2398 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
2399 | */ |
||
2400 | public function newContentMetadataUpdateStruct() |
||
2404 | |||
2405 | /** |
||
2406 | * Instantiates a new content update struct. |
||
2407 | * |
||
2408 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
2409 | */ |
||
2410 | public function newContentUpdateStruct() |
||
2414 | |||
2415 | /** |
||
2416 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
2417 | * |
||
2418 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
2419 | */ |
||
2420 | private function resolveUser(?User $user): UserReference |
||
2428 | } |
||
2429 |
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.