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 | public function __construct( |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Loads a content info object. |
||
| 125 | * |
||
| 126 | * To load fields use loadContent |
||
| 127 | * |
||
| 128 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 129 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 130 | * |
||
| 131 | * @param int $contentId |
||
| 132 | * |
||
| 133 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function loadContentInfo($contentId) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Loads a content info object. |
||
| 147 | * |
||
| 148 | * To load fields use loadContent |
||
| 149 | * |
||
| 150 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 151 | * |
||
| 152 | * @param mixed $id |
||
| 153 | * @param bool $isRemoteId |
||
| 154 | * |
||
| 155 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 156 | */ |
||
| 157 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Loads a content info object for the given remoteId. |
||
| 176 | * |
||
| 177 | * To load fields use loadContent |
||
| 178 | * |
||
| 179 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 180 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 181 | * |
||
| 182 | * @param string $remoteId |
||
| 183 | * |
||
| 184 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 185 | */ |
||
| 186 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Loads a version info of the given content object. |
||
| 199 | * |
||
| 200 | * If no version number is given, the method returns the current version |
||
| 201 | * |
||
| 202 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 203 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 204 | * |
||
| 205 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 206 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 207 | * |
||
| 208 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 209 | */ |
||
| 210 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Loads a version info of the given content object id. |
||
| 217 | * |
||
| 218 | * If no version number is given, the method returns the current version |
||
| 219 | * |
||
| 220 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 221 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 222 | * |
||
| 223 | * @param mixed $contentId |
||
| 224 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 225 | * |
||
| 226 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 227 | */ |
||
| 228 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Loads content in a version for the given content info object. |
||
| 267 | * |
||
| 268 | * If no version number is given, the method returns the current version |
||
| 269 | * |
||
| 270 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 271 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 272 | * |
||
| 273 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 274 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 275 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 276 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 277 | * |
||
| 278 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 279 | */ |
||
| 280 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Loads content in the version given by version info. |
||
| 297 | * |
||
| 298 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 299 | * |
||
| 300 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 301 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 302 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 303 | * |
||
| 304 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 305 | */ |
||
| 306 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Loads content in a version of the given content object. |
||
| 323 | * |
||
| 324 | * If no version number is given, the method returns the current version |
||
| 325 | * |
||
| 326 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 327 | * @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 |
||
| 328 | * |
||
| 329 | * @param int $contentId |
||
| 330 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 331 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 332 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 333 | * |
||
| 334 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 335 | */ |
||
| 336 | View Code Duplication | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Loads content in a version of the given content object. |
||
| 356 | * |
||
| 357 | * If no version number is given, the method returns the current version |
||
| 358 | * |
||
| 359 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 360 | * |
||
| 361 | * @param mixed $id |
||
| 362 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 363 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 364 | * @param bool $isRemoteId |
||
| 365 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 366 | * |
||
| 367 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 368 | */ |
||
| 369 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Loads content in a version for the content object reference by the given remote id. |
||
| 428 | * |
||
| 429 | * If no version is given, the method returns the current version |
||
| 430 | * |
||
| 431 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 432 | * @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 |
||
| 433 | * |
||
| 434 | * @param string $remoteId |
||
| 435 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 436 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 437 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 438 | * |
||
| 439 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 440 | */ |
||
| 441 | View Code Duplication | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 458 | |||
| 459 | /** |
||
| 460 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
| 461 | * |
||
| 462 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
| 463 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
| 464 | * allowed to access every Content on the list. |
||
| 465 | * |
||
| 466 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
| 467 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 468 | * returned value object. If not given all languages are returned. |
||
| 469 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
| 470 | * unless all languages have been asked for. |
||
| 471 | * |
||
| 472 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
| 473 | */ |
||
| 474 | public function loadContentListByContentInfo( |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Creates a new content draft assigned to the authenticated user. |
||
| 512 | * |
||
| 513 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 514 | * but this required special rights for the authenticated user |
||
| 515 | * (this is useful for content staging where the transfer process does not |
||
| 516 | * have to authenticate with the user which created the content object in the source server). |
||
| 517 | * The user has to publish the draft if it should be visible. |
||
| 518 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 519 | * |
||
| 520 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 521 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
| 522 | * struct are missing or invalid, or if multiple locations are under the |
||
| 523 | * same parent. |
||
| 524 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 525 | * or if a required field is missing / set to an empty value. |
||
| 526 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 527 | * or value is set for non-translatable field in language |
||
| 528 | * other than main. |
||
| 529 | * |
||
| 530 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 531 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 532 | * |
||
| 533 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 534 | */ |
||
| 535 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Returns an array of default content states with content state group id as key. |
||
| 736 | * |
||
| 737 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 738 | */ |
||
| 739 | protected function getDefaultObjectStates() |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Returns all language codes used in given $fields. |
||
| 757 | * |
||
| 758 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 759 | * |
||
| 760 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 761 | * |
||
| 762 | * @return string[] |
||
| 763 | */ |
||
| 764 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 791 | * |
||
| 792 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 793 | * or value is set for non-translatable field in language |
||
| 794 | * other than main |
||
| 795 | * |
||
| 796 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 797 | * |
||
| 798 | * @return array |
||
| 799 | */ |
||
| 800 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 836 | * |
||
| 837 | * @param Field $field |
||
| 838 | * @param array $overrides |
||
| 839 | * |
||
| 840 | * @return Field |
||
| 841 | */ |
||
| 842 | private function cloneField(Field $field, array $overrides = array()) |
||
| 856 | |||
| 857 | /** |
||
| 858 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 859 | * |
||
| 860 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 861 | * |
||
| 862 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 863 | */ |
||
| 864 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Updates the metadata. |
||
| 901 | * |
||
| 902 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 903 | * |
||
| 904 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 905 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 906 | * |
||
| 907 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 908 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 909 | * |
||
| 910 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 911 | */ |
||
| 912 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Publishes URL aliases for all locations of a given content. |
||
| 1001 | * |
||
| 1002 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1003 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 1004 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 1005 | */ |
||
| 1006 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 1028 | * |
||
| 1029 | * @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) |
||
| 1030 | * |
||
| 1031 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1032 | * |
||
| 1033 | * @return mixed[] Affected Location Id's |
||
| 1034 | */ |
||
| 1035 | public function deleteContent(ContentInfo $contentInfo) |
||
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Creates a draft from a published or archived version. |
||
| 1064 | * |
||
| 1065 | * If no version is given, the current published version is used. |
||
| 1066 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1067 | * It can be changed on updating the version. |
||
| 1068 | * |
||
| 1069 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1070 | * |
||
| 1071 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1072 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1073 | * @param \eZ\Publish\API\Repository\Values\User\User $creator if set given user is used to create the draft - otherwise the current-user is used |
||
| 1074 | * |
||
| 1075 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1076 | */ |
||
| 1077 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Loads drafts for a user. |
||
| 1142 | * |
||
| 1143 | * If no user is given the drafts for the authenticated user a returned |
||
| 1144 | * |
||
| 1145 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1146 | * |
||
| 1147 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1148 | * |
||
| 1149 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1150 | */ |
||
| 1151 | public function loadContentDrafts(User $user = null) |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Translate a version. |
||
| 1179 | * |
||
| 1180 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 1181 | * |
||
| 1182 | * @example Examples/translation_5x.php |
||
| 1183 | * |
||
| 1184 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
| 1185 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 1186 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid, or if a required field is missing or is set to an empty value. |
||
| 1187 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1188 | * or value is set for non-translatable field in language |
||
| 1189 | * other than main. |
||
| 1190 | * |
||
| 1191 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1192 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 1193 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
| 1194 | * |
||
| 1195 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 1196 | * |
||
| 1197 | * @since 5.0 |
||
| 1198 | */ |
||
| 1199 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Updates the fields of a draft. |
||
| 1206 | * |
||
| 1207 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1208 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1209 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1210 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1211 | * or if a required field is missing / set to an empty value. |
||
| 1212 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1213 | * or value is set for non-translatable field in language |
||
| 1214 | * other than main. |
||
| 1215 | * |
||
| 1216 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1217 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1218 | * |
||
| 1219 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1220 | */ |
||
| 1221 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Returns only updated language codes. |
||
| 1398 | * |
||
| 1399 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1400 | * |
||
| 1401 | * @return array |
||
| 1402 | */ |
||
| 1403 | View Code Duplication | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
|
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Returns all language codes used in given $fields. |
||
| 1422 | * |
||
| 1423 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1424 | * |
||
| 1425 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1426 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1427 | * |
||
| 1428 | * @return array |
||
| 1429 | */ |
||
| 1430 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1442 | |||
| 1443 | /** |
||
| 1444 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1445 | * |
||
| 1446 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1447 | * or value is set for non-translatable field in language |
||
| 1448 | * other than main |
||
| 1449 | * |
||
| 1450 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1451 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1452 | * @param string $mainLanguageCode |
||
| 1453 | * |
||
| 1454 | * @return array |
||
| 1455 | */ |
||
| 1456 | protected function mapFieldsForUpdate( |
||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * Publishes a content version. |
||
| 1497 | * |
||
| 1498 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1499 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1500 | * |
||
| 1501 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1502 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1503 | * |
||
| 1504 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1505 | * |
||
| 1506 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1507 | */ |
||
| 1508 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1535 | |||
| 1536 | /** |
||
| 1537 | * Publishes a content version. |
||
| 1538 | * |
||
| 1539 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1540 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1541 | * |
||
| 1542 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1543 | * |
||
| 1544 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1545 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1546 | * |
||
| 1547 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1548 | */ |
||
| 1549 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Removes the given version. |
||
| 1597 | * |
||
| 1598 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1599 | * published state or is the last version of the Content |
||
| 1600 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1601 | * |
||
| 1602 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1603 | */ |
||
| 1604 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Loads all versions for the given content. |
||
| 1649 | * |
||
| 1650 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1651 | * |
||
| 1652 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1653 | * |
||
| 1654 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1655 | */ |
||
| 1656 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Copies the content to a new location. If no version is given, |
||
| 1679 | * all versions are copied, otherwise only the given version. |
||
| 1680 | * |
||
| 1681 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1682 | * |
||
| 1683 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1684 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1685 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1686 | * |
||
| 1687 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1688 | */ |
||
| 1689 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1739 | |||
| 1740 | /** |
||
| 1741 | * Loads all outgoing relations for the given version. |
||
| 1742 | * |
||
| 1743 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1744 | * |
||
| 1745 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1746 | * |
||
| 1747 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1748 | */ |
||
| 1749 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1784 | |||
| 1785 | /** |
||
| 1786 | * Loads all incoming relations for a content object. |
||
| 1787 | * |
||
| 1788 | * The relations come only from published versions of the source content objects |
||
| 1789 | * |
||
| 1790 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1791 | * |
||
| 1792 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1793 | * |
||
| 1794 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1795 | */ |
||
| 1796 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1822 | |||
| 1823 | /** |
||
| 1824 | * Adds a relation of type common. |
||
| 1825 | * |
||
| 1826 | * The source of the relation is the content and version |
||
| 1827 | * referenced by $versionInfo. |
||
| 1828 | * |
||
| 1829 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1830 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1831 | * |
||
| 1832 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1833 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1834 | * |
||
| 1835 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1836 | */ |
||
| 1837 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1878 | |||
| 1879 | /** |
||
| 1880 | * Removes a relation of type COMMON from a draft. |
||
| 1881 | * |
||
| 1882 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1883 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1884 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1885 | * |
||
| 1886 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1887 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1888 | */ |
||
| 1889 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Adds translation information to the content object. |
||
| 1942 | * |
||
| 1943 | * @example Examples/translation_5x.php |
||
| 1944 | * |
||
| 1945 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1946 | * |
||
| 1947 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1948 | * |
||
| 1949 | * @since 5.0 |
||
| 1950 | */ |
||
| 1951 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1955 | |||
| 1956 | /** |
||
| 1957 | * lists the translations done on this content object. |
||
| 1958 | * |
||
| 1959 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1960 | * |
||
| 1961 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1962 | * @param array $filter |
||
| 1963 | * |
||
| 1964 | * @todo TBD - filter by source version destination version and languages |
||
| 1965 | * |
||
| 1966 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1967 | * |
||
| 1968 | * @since 5.0 |
||
| 1969 | */ |
||
| 1970 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Instantiates a new content create struct object. |
||
| 1977 | * |
||
| 1978 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 1979 | * |
||
| 1980 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1981 | * @param string $mainLanguageCode |
||
| 1982 | * |
||
| 1983 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1984 | */ |
||
| 1985 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1995 | |||
| 1996 | /** |
||
| 1997 | * Instantiates a new content meta data update struct. |
||
| 1998 | * |
||
| 1999 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 2000 | */ |
||
| 2001 | public function newContentMetadataUpdateStruct() |
||
| 2005 | |||
| 2006 | /** |
||
| 2007 | * Instantiates a new content update struct. |
||
| 2008 | * |
||
| 2009 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 2010 | */ |
||
| 2011 | public function newContentUpdateStruct() |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * Instantiates a new TranslationInfo object. |
||
| 2018 | * |
||
| 2019 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 2020 | */ |
||
| 2021 | public function newTranslationInfo() |
||
| 2025 | |||
| 2026 | /** |
||
| 2027 | * Instantiates a Translation object. |
||
| 2028 | * |
||
| 2029 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 2030 | */ |
||
| 2031 | public function newTranslationValues() |
||
| 2035 | } |
||
| 2036 |
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.