Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 53 | class ContentService implements ContentServiceInterface |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * @var \eZ\Publish\Core\Repository\Repository |
||
| 57 | */ |
||
| 58 | protected $repository; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 62 | */ |
||
| 63 | protected $persistenceHandler; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected $settings; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 72 | */ |
||
| 73 | protected $domainMapper; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 77 | */ |
||
| 78 | protected $relationProcessor; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 82 | */ |
||
| 83 | protected $nameSchemaService; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 87 | */ |
||
| 88 | protected $fieldTypeRegistry; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 92 | * |
||
| 93 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 94 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
| 95 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
| 96 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 97 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
| 98 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|
|||
| 99 | * @param array $settings |
||
| 100 | */ |
||
| 101 | View Code Duplication | public function __construct( |
|
| 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 there is a provided remoteId which exists in the system |
||
| 470 | * or there is no location provided (4.x) or multiple locations |
||
| 471 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 472 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 473 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value |
||
| 474 | * |
||
| 475 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 476 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 477 | * |
||
| 478 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 479 | */ |
||
| 480 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Returns an array of default content states with content state group id as key. |
||
| 679 | * |
||
| 680 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 681 | */ |
||
| 682 | protected function getDefaultObjectStates() |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Returns all language codes used in given $fields. |
||
| 700 | * |
||
| 701 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 702 | * |
||
| 703 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 704 | * |
||
| 705 | * @return string[] |
||
| 706 | */ |
||
| 707 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 734 | * |
||
| 735 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 736 | * or value is set for non-translatable field in language |
||
| 737 | * other than main |
||
| 738 | * |
||
| 739 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 740 | * |
||
| 741 | * @return array |
||
| 742 | */ |
||
| 743 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 776 | |||
| 777 | /** |
||
| 778 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 779 | * |
||
| 780 | * @param Field $field |
||
| 781 | * @param array $overrides |
||
| 782 | * |
||
| 783 | * @return Field |
||
| 784 | */ |
||
| 785 | private function cloneField(Field $field, array $overrides = array()) |
||
| 799 | |||
| 800 | /** |
||
| 801 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 802 | * |
||
| 803 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 804 | * |
||
| 805 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 806 | */ |
||
| 807 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Updates the metadata. |
||
| 844 | * |
||
| 845 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 846 | * |
||
| 847 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 848 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 849 | * |
||
| 850 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 851 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 852 | * |
||
| 853 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 854 | */ |
||
| 855 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 941 | |||
| 942 | /** |
||
| 943 | * Publishes URL aliases for all locations of a given content. |
||
| 944 | * |
||
| 945 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 946 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 947 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 948 | */ |
||
| 949 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 968 | |||
| 969 | /** |
||
| 970 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 971 | * |
||
| 972 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) |
||
| 973 | * |
||
| 974 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 975 | */ |
||
| 976 | public function deleteContent(ContentInfo $contentInfo) |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Creates a draft from a published or archived version. |
||
| 1001 | * |
||
| 1002 | * If no version is given, the current published version is used. |
||
| 1003 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1004 | * It can be changed on updating the version. |
||
| 1005 | * |
||
| 1006 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1007 | * |
||
| 1008 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1009 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1010 | * @param \eZ\Publish\API\Repository\Values\User\User $creator if set given user is used to create the draft - otherwise the current-user is used |
||
| 1011 | * |
||
| 1012 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1013 | */ |
||
| 1014 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * Loads drafts for a user. |
||
| 1079 | * |
||
| 1080 | * If no user is given the drafts for the authenticated user a returned |
||
| 1081 | * |
||
| 1082 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1083 | * |
||
| 1084 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1085 | * |
||
| 1086 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1087 | */ |
||
| 1088 | public function loadContentDrafts(User $user = null) |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Translate a version. |
||
| 1115 | * |
||
| 1116 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 1117 | * |
||
| 1118 | * @example Examples/translation_5x.php |
||
| 1119 | * |
||
| 1120 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
| 1121 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 1122 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 1123 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid |
||
| 1124 | * |
||
| 1125 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1126 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 1127 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
| 1128 | * |
||
| 1129 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 1130 | * |
||
| 1131 | * @since 5.0 |
||
| 1132 | */ |
||
| 1133 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Updates the fields of a draft. |
||
| 1140 | * |
||
| 1141 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1142 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1143 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 1144 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 1145 | * |
||
| 1146 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1147 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1148 | * |
||
| 1149 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1150 | */ |
||
| 1151 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Returns all language codes used in given $fields. |
||
| 1316 | * |
||
| 1317 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1318 | * |
||
| 1319 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1320 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1321 | * |
||
| 1322 | * @return array |
||
| 1323 | */ |
||
| 1324 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1353 | * |
||
| 1354 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1355 | * or value is set for non-translatable field in language |
||
| 1356 | * other than main |
||
| 1357 | * |
||
| 1358 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1359 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1360 | * @param string $mainLanguageCode |
||
| 1361 | * |
||
| 1362 | * @return array |
||
| 1363 | */ |
||
| 1364 | protected function mapFieldsForUpdate( |
||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * Publishes a content version. |
||
| 1405 | * |
||
| 1406 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1407 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1408 | * |
||
| 1409 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1410 | * |
||
| 1411 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1412 | */ |
||
| 1413 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * Publishes a content version. |
||
| 1443 | * |
||
| 1444 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1445 | * |
||
| 1446 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1447 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1448 | * |
||
| 1449 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1450 | */ |
||
| 1451 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1452 | { |
||
| 1453 | if ($versionInfo->status !== APIVersionInfo::STATUS_DRAFT) { |
||
| 1454 | throw new BadStateException('$versionInfo', 'Only versions in draft status can be published.'); |
||
| 1455 | } |
||
| 1456 | |||
| 1457 | $currentTime = time(); |
||
| 1458 | if ($publicationDate === null && $versionInfo->versionNo === 1) { |
||
| 1459 | $publicationDate = $currentTime; |
||
| 1460 | } |
||
| 1461 | |||
| 1462 | $metadataUpdateStruct = new SPIMetadataUpdateStruct(); |
||
| 1463 | $metadataUpdateStruct->publicationDate = $publicationDate; |
||
| 1464 | $metadataUpdateStruct->modificationDate = $currentTime; |
||
| 1465 | |||
| 1466 | $spiContent = $this->persistenceHandler->contentHandler()->publish( |
||
| 1467 | $versionInfo->getContentInfo()->id, |
||
| 1468 | $versionInfo->versionNo, |
||
| 1469 | $metadataUpdateStruct |
||
| 1470 | ); |
||
| 1471 | $content = $this->domainMapper->buildContentDomainObject($spiContent); |
||
| 1472 | |||
| 1473 | $this->publishUrlAliasesForContent($content); |
||
| 1474 | |||
| 1475 | return $content; |
||
| 1476 | } |
||
| 1477 | |||
| 1478 | /** |
||
| 1479 | * Removes the given version. |
||
| 1480 | * |
||
| 1481 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1482 | * published state or is the last version of the Content |
||
| 1483 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1484 | * |
||
| 1485 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1486 | */ |
||
| 1487 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1527 | |||
| 1528 | /** |
||
| 1529 | * Loads all versions for the given content. |
||
| 1530 | * |
||
| 1531 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1532 | * |
||
| 1533 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1534 | * |
||
| 1535 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1536 | */ |
||
| 1537 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1568 | |||
| 1569 | /** |
||
| 1570 | * Copies the content to a new location. If no version is given, |
||
| 1571 | * all versions are copied, otherwise only the given version. |
||
| 1572 | * |
||
| 1573 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1574 | * |
||
| 1575 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1576 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1577 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1578 | * |
||
| 1579 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1580 | */ |
||
| 1581 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Loads all outgoing relations for the given version. |
||
| 1631 | * |
||
| 1632 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1633 | * |
||
| 1634 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1635 | * |
||
| 1636 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1637 | */ |
||
| 1638 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Loads all incoming relations for a content object. |
||
| 1676 | * |
||
| 1677 | * The relations come only from published versions of the source content objects |
||
| 1678 | * |
||
| 1679 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1680 | * |
||
| 1681 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1682 | * |
||
| 1683 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1684 | */ |
||
| 1685 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1711 | |||
| 1712 | /** |
||
| 1713 | * Adds a relation of type common. |
||
| 1714 | * |
||
| 1715 | * The source of the relation is the content and version |
||
| 1716 | * referenced by $versionInfo. |
||
| 1717 | * |
||
| 1718 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1719 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1720 | * |
||
| 1721 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1722 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1723 | * |
||
| 1724 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1725 | */ |
||
| 1726 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * Removes a relation of type COMMON from a draft. |
||
| 1770 | * |
||
| 1771 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1772 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1773 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1774 | * |
||
| 1775 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1776 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1777 | */ |
||
| 1778 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * Adds translation information to the content object. |
||
| 1831 | * |
||
| 1832 | * @example Examples/translation_5x.php |
||
| 1833 | * |
||
| 1834 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1835 | * |
||
| 1836 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1837 | * |
||
| 1838 | * @since 5.0 |
||
| 1839 | */ |
||
| 1840 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * lists the translations done on this content object. |
||
| 1847 | * |
||
| 1848 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1849 | * |
||
| 1850 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1851 | * @param array $filter |
||
| 1852 | * |
||
| 1853 | * @todo TBD - filter by source version destination version and languages |
||
| 1854 | * |
||
| 1855 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1856 | * |
||
| 1857 | * @since 5.0 |
||
| 1858 | */ |
||
| 1859 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1863 | |||
| 1864 | /** |
||
| 1865 | * Instantiates a new content create struct object. |
||
| 1866 | * |
||
| 1867 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1868 | * @param string $mainLanguageCode |
||
| 1869 | * |
||
| 1870 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1871 | */ |
||
| 1872 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Instantiates a new content meta data update struct. |
||
| 1884 | * |
||
| 1885 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 1886 | */ |
||
| 1887 | public function newContentMetadataUpdateStruct() |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * Instantiates a new content update struct. |
||
| 1894 | * |
||
| 1895 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 1896 | */ |
||
| 1897 | public function newContentUpdateStruct() |
||
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Instantiates a new TranslationInfo object. |
||
| 1904 | * |
||
| 1905 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 1906 | */ |
||
| 1907 | public function newTranslationInfo() |
||
| 1911 | |||
| 1912 | /** |
||
| 1913 | * Instantiates a Translation object. |
||
| 1914 | * |
||
| 1915 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 1916 | */ |
||
| 1917 | public function newTranslationValues() |
||
| 1921 | } |
||
| 1922 |
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.