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) |
||
| 713 | { |
||
| 714 | $languageCodes = array(); |
||
| 715 | |||
| 716 | foreach ($contentCreateStruct->fields as $field) { |
||
| 717 | if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { |
||
| 718 | continue; |
||
| 719 | } |
||
| 720 | |||
| 721 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 722 | $field->languageCode |
||
| 723 | ); |
||
| 724 | $languageCodes[$field->languageCode] = true; |
||
| 725 | } |
||
| 726 | |||
| 727 | if (!isset($languageCodes[$contentCreateStruct->mainLanguageCode])) { |
||
| 728 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 729 | $contentCreateStruct->mainLanguageCode |
||
| 730 | ); |
||
| 731 | $languageCodes[$contentCreateStruct->mainLanguageCode] = true; |
||
| 732 | } |
||
| 733 | |||
| 734 | return array_keys($languageCodes); |
||
| 735 | } |
||
| 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) |
||
| 1342 | |||
| 1343 | /** |
||
| 1344 | * Returns only updated language codes. |
||
| 1345 | * |
||
| 1346 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1347 | * |
||
| 1348 | * @return array |
||
| 1349 | */ |
||
| 1350 | View Code Duplication | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
|
| 1366 | |||
| 1367 | /** |
||
| 1368 | * Returns all language codes used in given $fields. |
||
| 1369 | * |
||
| 1370 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1371 | * |
||
| 1372 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1373 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1374 | * |
||
| 1375 | * @return array |
||
| 1376 | */ |
||
| 1377 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1392 | * |
||
| 1393 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1394 | * or value is set for non-translatable field in language |
||
| 1395 | * other than main |
||
| 1396 | * |
||
| 1397 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1398 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1399 | * @param string $mainLanguageCode |
||
| 1400 | * |
||
| 1401 | * @return array |
||
| 1402 | */ |
||
| 1403 | protected function mapFieldsForUpdate( |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Publishes a content version. |
||
| 1444 | * |
||
| 1445 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1446 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1447 | * |
||
| 1448 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1449 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1450 | * |
||
| 1451 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1452 | * |
||
| 1453 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1454 | */ |
||
| 1455 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1482 | |||
| 1483 | /** |
||
| 1484 | * Publishes a content version. |
||
| 1485 | * |
||
| 1486 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1487 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1488 | * |
||
| 1489 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1490 | * |
||
| 1491 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1492 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1493 | * |
||
| 1494 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1495 | */ |
||
| 1496 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Removes the given version. |
||
| 1544 | * |
||
| 1545 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1546 | * published state or is the last version of the Content |
||
| 1547 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1548 | * |
||
| 1549 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1550 | */ |
||
| 1551 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1593 | |||
| 1594 | /** |
||
| 1595 | * Loads all versions for the given content. |
||
| 1596 | * |
||
| 1597 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1598 | * |
||
| 1599 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1600 | * |
||
| 1601 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1602 | */ |
||
| 1603 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1623 | |||
| 1624 | /** |
||
| 1625 | * Copies the content to a new location. If no version is given, |
||
| 1626 | * all versions are copied, otherwise only the given version. |
||
| 1627 | * |
||
| 1628 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1629 | * |
||
| 1630 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1631 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1632 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1633 | * |
||
| 1634 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1635 | */ |
||
| 1636 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1686 | |||
| 1687 | /** |
||
| 1688 | * Loads all outgoing relations for the given version. |
||
| 1689 | * |
||
| 1690 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1691 | * |
||
| 1692 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1693 | * |
||
| 1694 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1695 | */ |
||
| 1696 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * Loads all incoming relations for a content object. |
||
| 1734 | * |
||
| 1735 | * The relations come only from published versions of the source content objects |
||
| 1736 | * |
||
| 1737 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1738 | * |
||
| 1739 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1740 | * |
||
| 1741 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1742 | */ |
||
| 1743 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1769 | |||
| 1770 | /** |
||
| 1771 | * Adds a relation of type common. |
||
| 1772 | * |
||
| 1773 | * The source of the relation is the content and version |
||
| 1774 | * referenced by $versionInfo. |
||
| 1775 | * |
||
| 1776 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1777 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1778 | * |
||
| 1779 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1780 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1781 | * |
||
| 1782 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1783 | */ |
||
| 1784 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1825 | |||
| 1826 | /** |
||
| 1827 | * Removes a relation of type COMMON from a draft. |
||
| 1828 | * |
||
| 1829 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1830 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1831 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1832 | * |
||
| 1833 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1834 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1835 | */ |
||
| 1836 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1886 | |||
| 1887 | /** |
||
| 1888 | * Adds translation information to the content object. |
||
| 1889 | * |
||
| 1890 | * @example Examples/translation_5x.php |
||
| 1891 | * |
||
| 1892 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1893 | * |
||
| 1894 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1895 | * |
||
| 1896 | * @since 5.0 |
||
| 1897 | */ |
||
| 1898 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1902 | |||
| 1903 | /** |
||
| 1904 | * lists the translations done on this content object. |
||
| 1905 | * |
||
| 1906 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1907 | * |
||
| 1908 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1909 | * @param array $filter |
||
| 1910 | * |
||
| 1911 | * @todo TBD - filter by source version destination version and languages |
||
| 1912 | * |
||
| 1913 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1914 | * |
||
| 1915 | * @since 5.0 |
||
| 1916 | */ |
||
| 1917 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1921 | |||
| 1922 | /** |
||
| 1923 | * Instantiates a new content create struct object. |
||
| 1924 | * |
||
| 1925 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 1926 | * |
||
| 1927 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1928 | * @param string $mainLanguageCode |
||
| 1929 | * |
||
| 1930 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1931 | */ |
||
| 1932 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Instantiates a new content meta data update struct. |
||
| 1945 | * |
||
| 1946 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 1947 | */ |
||
| 1948 | public function newContentMetadataUpdateStruct() |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Instantiates a new content update struct. |
||
| 1955 | * |
||
| 1956 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 1957 | */ |
||
| 1958 | public function newContentUpdateStruct() |
||
| 1962 | |||
| 1963 | /** |
||
| 1964 | * Instantiates a new TranslationInfo object. |
||
| 1965 | * |
||
| 1966 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 1967 | */ |
||
| 1968 | public function newTranslationInfo() |
||
| 1972 | |||
| 1973 | /** |
||
| 1974 | * Instantiates a Translation object. |
||
| 1975 | * |
||
| 1976 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 1977 | */ |
||
| 1978 | public function newTranslationValues() |
||
| 1982 | } |
||
| 1983 |
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.