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 |
||
| 52 | class ContentService implements ContentServiceInterface |
||
| 53 | { |
||
| 54 | /** |
||
| 55 | * @var \eZ\Publish\Core\Repository\Repository |
||
| 56 | */ |
||
| 57 | protected $repository; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 61 | */ |
||
| 62 | protected $persistenceHandler; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $settings; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 71 | */ |
||
| 72 | protected $domainMapper; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 76 | */ |
||
| 77 | protected $relationProcessor; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 81 | */ |
||
| 82 | protected $nameSchemaService; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 86 | */ |
||
| 87 | protected $fieldTypeRegistry; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 91 | * |
||
| 92 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 93 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
| 94 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
| 95 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 96 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
| 97 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|
|||
| 98 | * @param array $settings |
||
| 99 | */ |
||
| 100 | public function __construct( |
||
| 101 | RepositoryInterface $repository, |
||
| 102 | Handler $handler, |
||
| 103 | Helper\DomainMapper $domainMapper, |
||
| 104 | Helper\RelationProcessor $relationProcessor, |
||
| 105 | Helper\NameSchemaService $nameSchemaService, |
||
| 106 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
| 107 | array $settings = array() |
||
| 108 | ) { |
||
| 109 | $this->repository = $repository; |
||
| 110 | $this->persistenceHandler = $handler; |
||
| 111 | $this->domainMapper = $domainMapper; |
||
| 112 | $this->relationProcessor = $relationProcessor; |
||
| 113 | $this->nameSchemaService = $nameSchemaService; |
||
| 114 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
| 115 | // Union makes sure default settings are ignored if provided in argument |
||
| 116 | $this->settings = $settings + array( |
||
| 117 | // Version archive limit (0-50), only enforced on publish, not on un-publish. |
||
| 118 | 'default_version_archive_limit' => 5, |
||
| 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) |
|
| 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) |
||
| 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) |
|
| 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) |
||
| 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) |
||
| 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) |
||
| 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 the provided remoteId exists in the system, required properties on |
||
| 470 | * struct are missing or invalid, or if multiple locations are under the |
||
| 471 | * same parent. |
||
| 472 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 473 | * or if a required field is missing / set to an empty value. |
||
| 474 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 475 | * or value is set for non-translatable field in language |
||
| 476 | * other than main. |
||
| 477 | * |
||
| 478 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 479 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 480 | * |
||
| 481 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 482 | */ |
||
| 483 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Returns an array of default content states with content state group id as key. |
||
| 684 | * |
||
| 685 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 686 | */ |
||
| 687 | protected function getDefaultObjectStates() |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Returns all language codes used in given $fields. |
||
| 705 | * |
||
| 706 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 707 | * |
||
| 708 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 709 | * |
||
| 710 | * @return string[] |
||
| 711 | */ |
||
| 712 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 739 | * |
||
| 740 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 741 | * or value is set for non-translatable field in language |
||
| 742 | * other than main |
||
| 743 | * |
||
| 744 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 745 | * |
||
| 746 | * @return array |
||
| 747 | */ |
||
| 748 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 784 | * |
||
| 785 | * @param Field $field |
||
| 786 | * @param array $overrides |
||
| 787 | * |
||
| 788 | * @return Field |
||
| 789 | */ |
||
| 790 | private function cloneField(Field $field, array $overrides = array()) |
||
| 804 | |||
| 805 | /** |
||
| 806 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 807 | * |
||
| 808 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 809 | * |
||
| 810 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 811 | */ |
||
| 812 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Updates the metadata. |
||
| 849 | * |
||
| 850 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 851 | * |
||
| 852 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 853 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 854 | * |
||
| 855 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 856 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 857 | * |
||
| 858 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 859 | */ |
||
| 860 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 946 | |||
| 947 | /** |
||
| 948 | * Publishes URL aliases for all locations of a given content. |
||
| 949 | * |
||
| 950 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 951 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 952 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 953 | */ |
||
| 954 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 976 | * |
||
| 977 | * @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) |
||
| 978 | * |
||
| 979 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 980 | * |
||
| 981 | * @return mixed[] Affected Location Id's |
||
| 982 | */ |
||
| 983 | public function deleteContent(ContentInfo $contentInfo) |
||
| 1009 | |||
| 1010 | /** |
||
| 1011 | * Creates a draft from a published or archived version. |
||
| 1012 | * |
||
| 1013 | * If no version is given, the current published version is used. |
||
| 1014 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1015 | * It can be changed on updating the version. |
||
| 1016 | * |
||
| 1017 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1018 | * |
||
| 1019 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1020 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1021 | * @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 |
||
| 1022 | * |
||
| 1023 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1024 | */ |
||
| 1025 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Loads drafts for a user. |
||
| 1090 | * |
||
| 1091 | * If no user is given the drafts for the authenticated user a returned |
||
| 1092 | * |
||
| 1093 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1094 | * |
||
| 1095 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1096 | * |
||
| 1097 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1098 | */ |
||
| 1099 | public function loadContentDrafts(User $user = null) |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * Translate a version. |
||
| 1126 | * |
||
| 1127 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 1128 | * |
||
| 1129 | * @example Examples/translation_5x.php |
||
| 1130 | * |
||
| 1131 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
| 1132 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 1133 | * @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. |
||
| 1134 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1135 | * or value is set for non-translatable field in language |
||
| 1136 | * other than main. |
||
| 1137 | * |
||
| 1138 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1139 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 1140 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
| 1141 | * |
||
| 1142 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 1143 | * |
||
| 1144 | * @since 5.0 |
||
| 1145 | */ |
||
| 1146 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Updates the fields of a draft. |
||
| 1153 | * |
||
| 1154 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1155 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1156 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1157 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1158 | * or if a required field is missing / set to an empty value. |
||
| 1159 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1160 | * or value is set for non-translatable field in language |
||
| 1161 | * other than main. |
||
| 1162 | * |
||
| 1163 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1164 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1165 | * |
||
| 1166 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1167 | */ |
||
| 1168 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * Returns all language codes used in given $fields. |
||
| 1335 | * |
||
| 1336 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1337 | * |
||
| 1338 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1339 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1340 | * |
||
| 1341 | * @return array |
||
| 1342 | */ |
||
| 1343 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1372 | * |
||
| 1373 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1374 | * or value is set for non-translatable field in language |
||
| 1375 | * other than main |
||
| 1376 | * |
||
| 1377 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1378 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1379 | * @param string $mainLanguageCode |
||
| 1380 | * |
||
| 1381 | * @return array |
||
| 1382 | */ |
||
| 1383 | protected function mapFieldsForUpdate( |
||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * Publishes a content version. |
||
| 1424 | * |
||
| 1425 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1426 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1427 | * |
||
| 1428 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1429 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1430 | * |
||
| 1431 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1432 | * |
||
| 1433 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1434 | */ |
||
| 1435 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Publishes a content version. |
||
| 1465 | * |
||
| 1466 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1467 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1468 | * |
||
| 1469 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1470 | * |
||
| 1471 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1472 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1473 | * |
||
| 1474 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1475 | */ |
||
| 1476 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Removes the given version. |
||
| 1524 | * |
||
| 1525 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1526 | * published state or is the last version of the Content |
||
| 1527 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1528 | * |
||
| 1529 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1530 | */ |
||
| 1531 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1573 | |||
| 1574 | /** |
||
| 1575 | * Loads all versions for the given content. |
||
| 1576 | * |
||
| 1577 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1578 | * |
||
| 1579 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1580 | * |
||
| 1581 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1582 | */ |
||
| 1583 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Copies the content to a new location. If no version is given, |
||
| 1606 | * all versions are copied, otherwise only the given version. |
||
| 1607 | * |
||
| 1608 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1609 | * |
||
| 1610 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1611 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1612 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1613 | * |
||
| 1614 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1615 | */ |
||
| 1616 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * Loads all outgoing relations for the given version. |
||
| 1666 | * |
||
| 1667 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1668 | * |
||
| 1669 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1670 | * |
||
| 1671 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1672 | */ |
||
| 1673 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1708 | |||
| 1709 | /** |
||
| 1710 | * Loads all incoming relations for a content object. |
||
| 1711 | * |
||
| 1712 | * The relations come only from published versions of the source content objects |
||
| 1713 | * |
||
| 1714 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1715 | * |
||
| 1716 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1717 | * |
||
| 1718 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1719 | */ |
||
| 1720 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1746 | |||
| 1747 | /** |
||
| 1748 | * Adds a relation of type common. |
||
| 1749 | * |
||
| 1750 | * The source of the relation is the content and version |
||
| 1751 | * referenced by $versionInfo. |
||
| 1752 | * |
||
| 1753 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1754 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1755 | * |
||
| 1756 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1757 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1758 | * |
||
| 1759 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1760 | */ |
||
| 1761 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1802 | |||
| 1803 | /** |
||
| 1804 | * Removes a relation of type COMMON from a draft. |
||
| 1805 | * |
||
| 1806 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1807 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1808 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1809 | * |
||
| 1810 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1811 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1812 | */ |
||
| 1813 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1863 | |||
| 1864 | /** |
||
| 1865 | * Adds translation information to the content object. |
||
| 1866 | * |
||
| 1867 | * @example Examples/translation_5x.php |
||
| 1868 | * |
||
| 1869 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1870 | * |
||
| 1871 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1872 | * |
||
| 1873 | * @since 5.0 |
||
| 1874 | */ |
||
| 1875 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1879 | |||
| 1880 | /** |
||
| 1881 | * lists the translations done on this content object. |
||
| 1882 | * |
||
| 1883 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1884 | * |
||
| 1885 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1886 | * @param array $filter |
||
| 1887 | * |
||
| 1888 | * @todo TBD - filter by source version destination version and languages |
||
| 1889 | * |
||
| 1890 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1891 | * |
||
| 1892 | * @since 5.0 |
||
| 1893 | */ |
||
| 1894 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1898 | |||
| 1899 | /** |
||
| 1900 | * Instantiates a new content create struct object. |
||
| 1901 | * |
||
| 1902 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 1903 | * |
||
| 1904 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1905 | * @param string $mainLanguageCode |
||
| 1906 | * |
||
| 1907 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1908 | */ |
||
| 1909 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Instantiates a new content meta data update struct. |
||
| 1922 | * |
||
| 1923 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 1924 | */ |
||
| 1925 | public function newContentMetadataUpdateStruct() |
||
| 1929 | |||
| 1930 | /** |
||
| 1931 | * Instantiates a new content update struct. |
||
| 1932 | * |
||
| 1933 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 1934 | */ |
||
| 1935 | public function newContentUpdateStruct() |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Instantiates a new TranslationInfo object. |
||
| 1942 | * |
||
| 1943 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 1944 | */ |
||
| 1945 | public function newTranslationInfo() |
||
| 1949 | |||
| 1950 | /** |
||
| 1951 | * Instantiates a Translation object. |
||
| 1952 | * |
||
| 1953 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 1954 | */ |
||
| 1955 | public function newTranslationValues() |
||
| 1959 | } |
||
| 1960 |
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.