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 |
||
| 54 | class ContentService implements ContentServiceInterface |
||
| 55 | { |
||
| 56 | /** |
||
| 57 | * @var \eZ\Publish\Core\Repository\Repository |
||
| 58 | */ |
||
| 59 | protected $repository; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 63 | */ |
||
| 64 | protected $persistenceHandler; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected $settings; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 73 | */ |
||
| 74 | protected $domainMapper; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 78 | */ |
||
| 79 | protected $relationProcessor; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 83 | */ |
||
| 84 | protected $nameSchemaService; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 88 | */ |
||
| 89 | protected $fieldTypeRegistry; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 93 | * |
||
| 94 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 95 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
| 96 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
| 97 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 98 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
| 99 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|
|||
| 100 | * @param array $settings |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function __construct( |
|
| 122 | |||
| 123 | /** |
||
| 124 | * Loads a content info object. |
||
| 125 | * |
||
| 126 | * To load fields use loadContent |
||
| 127 | * |
||
| 128 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 129 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 130 | * |
||
| 131 | * @param int $contentId |
||
| 132 | * |
||
| 133 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function loadContentInfo($contentId) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Loads a content info object. |
||
| 147 | * |
||
| 148 | * To load fields use loadContent |
||
| 149 | * |
||
| 150 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 151 | * |
||
| 152 | * @param mixed $id |
||
| 153 | * @param bool $isRemoteId |
||
| 154 | * |
||
| 155 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 156 | */ |
||
| 157 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Loads a content info object for the given remoteId. |
||
| 176 | * |
||
| 177 | * To load fields use loadContent |
||
| 178 | * |
||
| 179 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 180 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 181 | * |
||
| 182 | * @param string $remoteId |
||
| 183 | * |
||
| 184 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 185 | */ |
||
| 186 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Loads a version info of the given content object. |
||
| 199 | * |
||
| 200 | * If no version number is given, the method returns the current version |
||
| 201 | * |
||
| 202 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 203 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 204 | * |
||
| 205 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 206 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 207 | * |
||
| 208 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 209 | */ |
||
| 210 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Loads a version info of the given content object id. |
||
| 217 | * |
||
| 218 | * If no version number is given, the method returns the current version |
||
| 219 | * |
||
| 220 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 221 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 222 | * |
||
| 223 | * @param mixed $contentId |
||
| 224 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 225 | * |
||
| 226 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 227 | */ |
||
| 228 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Loads content in a version for the given content info object. |
||
| 267 | * |
||
| 268 | * If no version number is given, the method returns the current version |
||
| 269 | * |
||
| 270 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 271 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 272 | * |
||
| 273 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 274 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 275 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 276 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 277 | * |
||
| 278 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 279 | */ |
||
| 280 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Loads content in the version given by version info. |
||
| 297 | * |
||
| 298 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 299 | * |
||
| 300 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 301 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 302 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 303 | * |
||
| 304 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 305 | */ |
||
| 306 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Loads content in a version of the given content object. |
||
| 323 | * |
||
| 324 | * If no version number is given, the method returns the current version |
||
| 325 | * |
||
| 326 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 327 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
| 328 | * |
||
| 329 | * @param int $contentId |
||
| 330 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 331 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 332 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 333 | * |
||
| 334 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 335 | */ |
||
| 336 | View Code Duplication | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Loads content in a version of the given content object. |
||
| 356 | * |
||
| 357 | * If no version number is given, the method returns the current version |
||
| 358 | * |
||
| 359 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 360 | * |
||
| 361 | * @param mixed $id |
||
| 362 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 363 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 364 | * @param bool $isRemoteId |
||
| 365 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 366 | * |
||
| 367 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 368 | */ |
||
| 369 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Loads content in a version for the content object reference by the given remote id. |
||
| 428 | * |
||
| 429 | * If no version is given, the method returns the current version |
||
| 430 | * |
||
| 431 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 432 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
| 433 | * |
||
| 434 | * @param string $remoteId |
||
| 435 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 436 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 437 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 438 | * |
||
| 439 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 440 | */ |
||
| 441 | View Code Duplication | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 458 | |||
| 459 | /** |
||
| 460 | * Creates a new content draft assigned to the authenticated user. |
||
| 461 | * |
||
| 462 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 463 | * but this required special rights for the authenticated user |
||
| 464 | * (this is useful for content staging where the transfer process does not |
||
| 465 | * have to authenticate with the user which created the content object in the source server). |
||
| 466 | * The user has to publish the draft if it should be visible. |
||
| 467 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 468 | * |
||
| 469 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 470 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
| 471 | * struct are missing or invalid, or if multiple locations are under the |
||
| 472 | * same parent. |
||
| 473 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 474 | * or if a required field is missing / set to an empty value. |
||
| 475 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 476 | * or value is set for non-translatable field in language |
||
| 477 | * other than main. |
||
| 478 | * |
||
| 479 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 480 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 481 | * |
||
| 482 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 483 | */ |
||
| 484 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 485 | { |
||
| 486 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
| 487 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
| 488 | } |
||
| 489 | |||
| 490 | if ($contentCreateStruct->contentType === null) { |
||
| 491 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
| 492 | } |
||
| 493 | |||
| 494 | $contentCreateStruct = clone $contentCreateStruct; |
||
| 495 | |||
| 496 | if ($contentCreateStruct->ownerId === null) { |
||
| 497 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 498 | } |
||
| 499 | |||
| 500 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
| 501 | $contentCreateStruct->alwaysAvailable = false; |
||
| 502 | } |
||
| 503 | |||
| 504 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
| 505 | $contentCreateStruct->contentType->id |
||
| 506 | ); |
||
| 507 | |||
| 508 | if (empty($contentCreateStruct->sectionId)) { |
||
| 509 | if (isset($locationCreateStructs[0])) { |
||
| 510 | $location = $this->repository->getLocationService()->loadLocation( |
||
| 511 | $locationCreateStructs[0]->parentLocationId |
||
| 512 | ); |
||
| 513 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
| 514 | } else { |
||
| 515 | $contentCreateStruct->sectionId = 1; |
||
| 516 | } |
||
| 517 | } |
||
| 518 | |||
| 519 | if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
| 520 | throw new UnauthorizedException( |
||
| 521 | 'content', |
||
| 522 | 'create', |
||
| 523 | array( |
||
| 524 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
| 525 | $locationCreateStructs[0]->parentLocationId : |
||
| 526 | null, |
||
| 527 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 528 | ) |
||
| 529 | ); |
||
| 530 | } |
||
| 531 | |||
| 532 | if (!empty($contentCreateStruct->remoteId)) { |
||
| 533 | try { |
||
| 534 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
| 535 | |||
| 536 | throw new InvalidArgumentException( |
||
| 537 | '$contentCreateStruct', |
||
| 538 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
| 539 | ); |
||
| 540 | } catch (APINotFoundException $e) { |
||
| 541 | // Do nothing |
||
| 542 | } |
||
| 543 | } else { |
||
| 544 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
| 545 | } |
||
| 546 | |||
| 547 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
| 548 | |||
| 549 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
| 550 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
| 551 | |||
| 552 | $fieldValues = array(); |
||
| 553 | $spiFields = array(); |
||
| 554 | $allFieldErrors = array(); |
||
| 555 | $inputRelations = array(); |
||
| 556 | $locationIdToContentIdMapping = array(); |
||
| 557 | |||
| 558 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
| 559 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
| 560 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
| 561 | $fieldDefinition->fieldTypeIdentifier |
||
| 562 | ); |
||
| 563 | |||
| 564 | foreach ($languageCodes as $languageCode) { |
||
| 565 | $isEmptyValue = false; |
||
| 566 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
| 567 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
| 568 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
| 569 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
| 570 | } else { |
||
| 571 | $fieldValue = $fieldDefinition->defaultValue; |
||
| 572 | } |
||
| 573 | |||
| 574 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
| 575 | |||
| 576 | View Code Duplication | if ($fieldType->isEmptyValue($fieldValue)) { |
|
| 577 | $isEmptyValue = true; |
||
| 578 | if ($fieldDefinition->isRequired) { |
||
| 579 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
| 580 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
| 581 | null, |
||
| 582 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
| 583 | 'empty' |
||
| 584 | ); |
||
| 585 | } |
||
| 586 | } else { |
||
| 587 | $fieldErrors = $fieldType->validate( |
||
| 588 | $fieldDefinition, |
||
| 589 | $fieldValue |
||
| 590 | ); |
||
| 591 | if (!empty($fieldErrors)) { |
||
| 592 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
| 593 | } |
||
| 594 | } |
||
| 595 | |||
| 596 | if (!empty($allFieldErrors)) { |
||
| 597 | continue; |
||
| 598 | } |
||
| 599 | |||
| 600 | $this->relationProcessor->appendFieldRelations( |
||
| 601 | $inputRelations, |
||
| 602 | $locationIdToContentIdMapping, |
||
| 603 | $fieldType, |
||
| 604 | $fieldValue, |
||
| 605 | $fieldDefinition->id |
||
| 606 | ); |
||
| 607 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
| 608 | |||
| 609 | // Only non-empty value for: translatable field or in main language |
||
| 610 | if ( |
||
| 611 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
| 612 | (!$isEmptyValue && $isLanguageMain) |
||
| 613 | ) { |
||
| 614 | $spiFields[] = new SPIField( |
||
| 615 | array( |
||
| 616 | 'id' => null, |
||
| 617 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
| 618 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
| 619 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
| 620 | 'languageCode' => $languageCode, |
||
| 621 | 'versionNo' => null, |
||
| 622 | ) |
||
| 623 | ); |
||
| 624 | } |
||
| 625 | } |
||
| 626 | } |
||
| 627 | |||
| 628 | if (!empty($allFieldErrors)) { |
||
| 629 | throw new ContentFieldValidationException($allFieldErrors); |
||
| 630 | } |
||
| 631 | |||
| 632 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
| 633 | array( |
||
| 634 | 'name' => $this->nameSchemaService->resolve( |
||
| 635 | $contentCreateStruct->contentType->nameSchema, |
||
| 636 | $contentCreateStruct->contentType, |
||
| 637 | $fieldValues, |
||
| 638 | $languageCodes |
||
| 639 | ), |
||
| 640 | 'typeId' => $contentCreateStruct->contentType->id, |
||
| 641 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 642 | 'ownerId' => $contentCreateStruct->ownerId, |
||
| 643 | 'locations' => $spiLocationCreateStructs, |
||
| 644 | 'fields' => $spiFields, |
||
| 645 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
| 646 | 'remoteId' => $contentCreateStruct->remoteId, |
||
| 647 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
| 648 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 649 | $contentCreateStruct->mainLanguageCode |
||
| 650 | )->id, |
||
| 651 | ) |
||
| 652 | ); |
||
| 653 | |||
| 654 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
| 655 | |||
| 656 | $this->repository->beginTransaction(); |
||
| 657 | try { |
||
| 658 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
| 659 | $this->relationProcessor->processFieldRelations( |
||
| 660 | $inputRelations, |
||
| 661 | $spiContent->versionInfo->contentInfo->id, |
||
| 662 | $spiContent->versionInfo->versionNo, |
||
| 663 | $contentCreateStruct->contentType |
||
| 664 | ); |
||
| 665 | |||
| 666 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
| 667 | $this->persistenceHandler->objectStateHandler()->setContentState( |
||
| 668 | $spiContent->versionInfo->contentInfo->id, |
||
| 669 | $objectStateGroupId, |
||
| 670 | $objectState->id |
||
| 671 | ); |
||
| 672 | } |
||
| 673 | |||
| 674 | $this->repository->commit(); |
||
| 675 | } catch (Exception $e) { |
||
| 676 | $this->repository->rollback(); |
||
| 677 | throw $e; |
||
| 678 | } |
||
| 679 | |||
| 680 | return $this->domainMapper->buildContentDomainObject($spiContent); |
||
| 681 | } |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Returns an array of default content states with content state group id as key. |
||
| 685 | * |
||
| 686 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 687 | */ |
||
| 688 | protected function getDefaultObjectStates() |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Returns all language codes used in given $fields. |
||
| 706 | * |
||
| 707 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 708 | * |
||
| 709 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 710 | * |
||
| 711 | * @return string[] |
||
| 712 | */ |
||
| 713 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 740 | * |
||
| 741 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 742 | * or value is set for non-translatable field in language |
||
| 743 | * other than main |
||
| 744 | * |
||
| 745 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 746 | * |
||
| 747 | * @return array |
||
| 748 | */ |
||
| 749 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 785 | * |
||
| 786 | * @param Field $field |
||
| 787 | * @param array $overrides |
||
| 788 | * |
||
| 789 | * @return Field |
||
| 790 | */ |
||
| 791 | private function cloneField(Field $field, array $overrides = array()) |
||
| 805 | |||
| 806 | /** |
||
| 807 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 808 | * |
||
| 809 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 810 | * |
||
| 811 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 812 | */ |
||
| 813 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Updates the metadata. |
||
| 850 | * |
||
| 851 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 852 | * |
||
| 853 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 854 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 855 | * |
||
| 856 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 857 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 858 | * |
||
| 859 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 860 | */ |
||
| 861 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Publishes URL aliases for all locations of a given content. |
||
| 950 | * |
||
| 951 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 952 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 953 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 954 | */ |
||
| 955 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 974 | |||
| 975 | /** |
||
| 976 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 977 | * |
||
| 978 | * @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) |
||
| 979 | * |
||
| 980 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 981 | * |
||
| 982 | * @return mixed[] Affected Location Id's |
||
| 983 | */ |
||
| 984 | public function deleteContent(ContentInfo $contentInfo) |
||
| 985 | { |
||
| 986 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id); |
||
| 987 | |||
| 988 | if (!$this->repository->canUser('content', 'remove', $contentInfo)) { |
||
| 989 | throw new UnauthorizedException('content', 'remove', array('contentId' => $contentInfo->id)); |
||
| 990 | } |
||
| 991 | |||
| 992 | $affectedLocations = []; |
||
| 993 | $this->repository->beginTransaction(); |
||
| 994 | try { |
||
| 995 | // Load Locations first as deleting Content also deletes belonging Locations |
||
| 996 | $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id); |
||
| 997 | $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id); |
||
| 998 | foreach ($spiLocations as $spiLocation) { |
||
| 999 | $this->persistenceHandler->urlAliasHandler()->locationDeleted($spiLocation->id); |
||
| 1000 | $affectedLocations[] = $spiLocation->id; |
||
| 1001 | } |
||
| 1002 | $this->repository->commit(); |
||
| 1003 | } catch (Exception $e) { |
||
| 1004 | $this->repository->rollback(); |
||
| 1005 | throw $e; |
||
| 1006 | } |
||
| 1007 | |||
| 1008 | return $affectedLocations; |
||
| 1009 | } |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Creates a draft from a published or archived version. |
||
| 1013 | * |
||
| 1014 | * If no version is given, the current published version is used. |
||
| 1015 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1016 | * It can be changed on updating the version. |
||
| 1017 | * |
||
| 1018 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1019 | * |
||
| 1020 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1021 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1022 | * @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 |
||
| 1023 | * |
||
| 1024 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1025 | */ |
||
| 1026 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Loads drafts for a user. |
||
| 1091 | * |
||
| 1092 | * If no user is given the drafts for the authenticated user a returned |
||
| 1093 | * |
||
| 1094 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1095 | * |
||
| 1096 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1097 | * |
||
| 1098 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1099 | */ |
||
| 1100 | public function loadContentDrafts(User $user = null) |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * Translate a version. |
||
| 1127 | * |
||
| 1128 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 1129 | * |
||
| 1130 | * @example Examples/translation_5x.php |
||
| 1131 | * |
||
| 1132 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
| 1133 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 1134 | * @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. |
||
| 1135 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1136 | * or value is set for non-translatable field in language |
||
| 1137 | * other than main. |
||
| 1138 | * |
||
| 1139 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1140 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 1141 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
| 1142 | * |
||
| 1143 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 1144 | * |
||
| 1145 | * @since 5.0 |
||
| 1146 | */ |
||
| 1147 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
| 1148 | { |
||
| 1149 | throw new NotImplementedException(__METHOD__); |
||
| 1150 | } |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Updates the fields of a draft. |
||
| 1154 | * |
||
| 1155 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1156 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1157 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1158 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1159 | * or if a required field is missing / set to an empty value. |
||
| 1160 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1161 | * or value is set for non-translatable field in language |
||
| 1162 | * other than main. |
||
| 1163 | * |
||
| 1164 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1165 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1166 | * |
||
| 1167 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1168 | */ |
||
| 1169 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1170 | { |
||
| 1171 | $contentUpdateStruct = clone $contentUpdateStruct; |
||
| 1172 | |||
| 1173 | /** @var $content \eZ\Publish\Core\Repository\Values\Content\Content */ |
||
| 1174 | $content = $this->loadContent( |
||
| 1175 | $versionInfo->getContentInfo()->id, |
||
| 1176 | null, |
||
| 1177 | $versionInfo->versionNo |
||
| 1178 | ); |
||
| 1179 | if ($content->versionInfo->status !== APIVersionInfo::STATUS_DRAFT) { |
||
| 1180 | throw new BadStateException( |
||
| 1181 | '$versionInfo', |
||
| 1182 | 'Version is not a draft and can not be updated' |
||
| 1183 | ); |
||
| 1184 | } |
||
| 1185 | |||
| 1186 | if (!$this->repository->canUser('content', 'edit', $content)) { |
||
| 1187 | throw new UnauthorizedException('content', 'edit', array('contentId' => $content->id)); |
||
| 1188 | } |
||
| 1189 | |||
| 1190 | $mainLanguageCode = $content->contentInfo->mainLanguageCode; |
||
| 1191 | $languageCodes = $this->getLanguageCodesForUpdate($contentUpdateStruct, $content); |
||
| 1192 | $contentType = $this->repository->getContentTypeService()->loadContentType( |
||
| 1193 | $content->contentInfo->contentTypeId |
||
| 1194 | ); |
||
| 1195 | $fields = $this->mapFieldsForUpdate( |
||
| 1196 | $contentUpdateStruct, |
||
| 1197 | $contentType, |
||
| 1198 | $mainLanguageCode |
||
| 1199 | ); |
||
| 1200 | |||
| 1201 | $fieldValues = array(); |
||
| 1202 | $spiFields = array(); |
||
| 1203 | $allFieldErrors = array(); |
||
| 1204 | $inputRelations = array(); |
||
| 1205 | $locationIdToContentIdMapping = array(); |
||
| 1206 | |||
| 1207 | foreach ($contentType->getFieldDefinitions() as $fieldDefinition) { |
||
| 1208 | /** @var $fieldType \eZ\Publish\SPI\FieldType\FieldType */ |
||
| 1209 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
| 1210 | $fieldDefinition->fieldTypeIdentifier |
||
| 1211 | ); |
||
| 1212 | |||
| 1213 | foreach ($languageCodes as $languageCode) { |
||
| 1214 | $isCopied = $isEmpty = $isRetained = false; |
||
| 1215 | $isLanguageNew = !in_array($languageCode, $content->versionInfo->languageCodes); |
||
| 1216 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $mainLanguageCode; |
||
| 1217 | $isFieldUpdated = isset($fields[$fieldDefinition->identifier][$valueLanguageCode]); |
||
| 1218 | $isProcessed = isset($fieldValues[$fieldDefinition->identifier][$valueLanguageCode]); |
||
| 1219 | |||
| 1220 | if (!$isFieldUpdated && !$isLanguageNew) { |
||
| 1221 | $isRetained = true; |
||
| 1222 | $fieldValue = $content->getField($fieldDefinition->identifier, $valueLanguageCode)->value; |
||
| 1223 | } elseif (!$isFieldUpdated && $isLanguageNew && !$fieldDefinition->isTranslatable) { |
||
| 1224 | $isCopied = true; |
||
| 1225 | $fieldValue = $content->getField($fieldDefinition->identifier, $valueLanguageCode)->value; |
||
| 1226 | } elseif ($isFieldUpdated) { |
||
| 1227 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
| 1228 | } else { |
||
| 1229 | $fieldValue = $fieldDefinition->defaultValue; |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
| 1233 | |||
| 1234 | View Code Duplication | if ($fieldType->isEmptyValue($fieldValue)) { |
|
| 1235 | $isEmpty = true; |
||
| 1236 | if ($fieldDefinition->isRequired) { |
||
| 1237 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
| 1238 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
| 1239 | null, |
||
| 1240 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
| 1241 | 'empty' |
||
| 1242 | ); |
||
| 1243 | } |
||
| 1244 | } else { |
||
| 1245 | $fieldErrors = $fieldType->validate( |
||
| 1246 | $fieldDefinition, |
||
| 1247 | $fieldValue |
||
| 1248 | ); |
||
| 1249 | if (!empty($fieldErrors)) { |
||
| 1250 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
| 1251 | } |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | if (!empty($allFieldErrors)) { |
||
| 1255 | continue; |
||
| 1256 | } |
||
| 1257 | |||
| 1258 | $this->relationProcessor->appendFieldRelations( |
||
| 1259 | $inputRelations, |
||
| 1260 | $locationIdToContentIdMapping, |
||
| 1261 | $fieldType, |
||
| 1262 | $fieldValue, |
||
| 1263 | $fieldDefinition->id |
||
| 1264 | ); |
||
| 1265 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
| 1266 | |||
| 1267 | if ($isRetained || $isCopied || ($isLanguageNew && $isEmpty) || $isProcessed) { |
||
| 1268 | continue; |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | $spiFields[] = new SPIField( |
||
| 1272 | array( |
||
| 1273 | 'id' => $isLanguageNew ? |
||
| 1274 | null : |
||
| 1275 | $content->getField($fieldDefinition->identifier, $languageCode)->id, |
||
| 1276 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
| 1277 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
| 1278 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
| 1279 | 'languageCode' => $languageCode, |
||
| 1280 | 'versionNo' => $versionInfo->versionNo, |
||
| 1281 | ) |
||
| 1282 | ); |
||
| 1283 | } |
||
| 1284 | } |
||
| 1285 | |||
| 1286 | if (!empty($allFieldErrors)) { |
||
| 1287 | throw new ContentFieldValidationException($allFieldErrors); |
||
| 1288 | } |
||
| 1289 | |||
| 1290 | $spiContentUpdateStruct = new SPIContentUpdateStruct( |
||
| 1291 | array( |
||
| 1292 | 'name' => $this->nameSchemaService->resolveNameSchema( |
||
| 1293 | $content, |
||
| 1294 | $fieldValues, |
||
| 1295 | $languageCodes, |
||
| 1296 | $contentType |
||
| 1297 | ), |
||
| 1298 | 'creatorId' => $contentUpdateStruct->creatorId ?: $this->repository->getCurrentUserReference()->getUserId(), |
||
| 1299 | 'fields' => $spiFields, |
||
| 1300 | 'modificationDate' => time(), |
||
| 1301 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 1302 | $contentUpdateStruct->initialLanguageCode |
||
| 1303 | )->id, |
||
| 1304 | ) |
||
| 1305 | ); |
||
| 1306 | $existingRelations = $this->loadRelations($versionInfo); |
||
| 1307 | |||
| 1308 | $this->repository->beginTransaction(); |
||
| 1309 | try { |
||
| 1310 | $spiContent = $this->persistenceHandler->contentHandler()->updateContent( |
||
| 1311 | $versionInfo->getContentInfo()->id, |
||
| 1312 | $versionInfo->versionNo, |
||
| 1313 | $spiContentUpdateStruct |
||
| 1314 | ); |
||
| 1315 | $this->relationProcessor->processFieldRelations( |
||
| 1316 | $inputRelations, |
||
| 1317 | $spiContent->versionInfo->contentInfo->id, |
||
| 1318 | $spiContent->versionInfo->versionNo, |
||
| 1319 | $contentType, |
||
| 1320 | $existingRelations |
||
| 1321 | ); |
||
| 1322 | $this->repository->commit(); |
||
| 1323 | } catch (Exception $e) { |
||
| 1324 | $this->repository->rollback(); |
||
| 1325 | throw $e; |
||
| 1326 | } |
||
| 1327 | |||
| 1328 | return $this->domainMapper->buildContentDomainObject( |
||
| 1329 | $spiContent, |
||
| 1330 | $contentType |
||
| 1331 | ); |
||
| 1332 | } |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Returns all language codes used in given $fields. |
||
| 1336 | * |
||
| 1337 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1338 | * |
||
| 1339 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1340 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1341 | * |
||
| 1342 | * @return array |
||
| 1343 | */ |
||
| 1344 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1373 | * |
||
| 1374 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1375 | * or value is set for non-translatable field in language |
||
| 1376 | * other than main |
||
| 1377 | * |
||
| 1378 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1379 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1380 | * @param string $mainLanguageCode |
||
| 1381 | * |
||
| 1382 | * @return array |
||
| 1383 | */ |
||
| 1384 | protected function mapFieldsForUpdate( |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Publishes a content version. |
||
| 1425 | * |
||
| 1426 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1427 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1428 | * |
||
| 1429 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1430 | * |
||
| 1431 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1432 | */ |
||
| 1433 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Publishes a content version. |
||
| 1463 | * |
||
| 1464 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1465 | * |
||
| 1466 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1467 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1468 | * |
||
| 1469 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1470 | */ |
||
| 1471 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1497 | |||
| 1498 | /** |
||
| 1499 | * Removes the given version. |
||
| 1500 | * |
||
| 1501 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1502 | * published state or is the last version of the Content |
||
| 1503 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1504 | * |
||
| 1505 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1506 | */ |
||
| 1507 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Loads all versions for the given content. |
||
| 1550 | * |
||
| 1551 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1552 | * |
||
| 1553 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1554 | * |
||
| 1555 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1556 | */ |
||
| 1557 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1577 | |||
| 1578 | /** |
||
| 1579 | * Copies the content to a new location. If no version is given, |
||
| 1580 | * all versions are copied, otherwise only the given version. |
||
| 1581 | * |
||
| 1582 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1583 | * |
||
| 1584 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1585 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1586 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1587 | * |
||
| 1588 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1589 | */ |
||
| 1590 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Loads all outgoing relations for the given version. |
||
| 1640 | * |
||
| 1641 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1642 | * |
||
| 1643 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1644 | * |
||
| 1645 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1646 | */ |
||
| 1647 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Loads all incoming relations for a content object. |
||
| 1685 | * |
||
| 1686 | * The relations come only from published versions of the source content objects |
||
| 1687 | * |
||
| 1688 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1689 | * |
||
| 1690 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1691 | * |
||
| 1692 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1693 | */ |
||
| 1694 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1720 | |||
| 1721 | /** |
||
| 1722 | * Adds a relation of type common. |
||
| 1723 | * |
||
| 1724 | * The source of the relation is the content and version |
||
| 1725 | * referenced by $versionInfo. |
||
| 1726 | * |
||
| 1727 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1728 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1729 | * |
||
| 1730 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1731 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1732 | * |
||
| 1733 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1734 | */ |
||
| 1735 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1776 | |||
| 1777 | /** |
||
| 1778 | * Removes a relation of type COMMON from a draft. |
||
| 1779 | * |
||
| 1780 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1781 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1782 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1783 | * |
||
| 1784 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1785 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1786 | */ |
||
| 1787 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1837 | |||
| 1838 | /** |
||
| 1839 | * Adds translation information to the content object. |
||
| 1840 | * |
||
| 1841 | * @example Examples/translation_5x.php |
||
| 1842 | * |
||
| 1843 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1844 | * |
||
| 1845 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1846 | * |
||
| 1847 | * @since 5.0 |
||
| 1848 | */ |
||
| 1849 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1853 | |||
| 1854 | /** |
||
| 1855 | * lists the translations done on this content object. |
||
| 1856 | * |
||
| 1857 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1858 | * |
||
| 1859 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1860 | * @param array $filter |
||
| 1861 | * |
||
| 1862 | * @todo TBD - filter by source version destination version and languages |
||
| 1863 | * |
||
| 1864 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1865 | * |
||
| 1866 | * @since 5.0 |
||
| 1867 | */ |
||
| 1868 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1872 | |||
| 1873 | /** |
||
| 1874 | * Instantiates a new content create struct object. |
||
| 1875 | * |
||
| 1876 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1877 | * @param string $mainLanguageCode |
||
| 1878 | * |
||
| 1879 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1880 | */ |
||
| 1881 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Instantiates a new content meta data update struct. |
||
| 1893 | * |
||
| 1894 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 1895 | */ |
||
| 1896 | public function newContentMetadataUpdateStruct() |
||
| 1900 | |||
| 1901 | /** |
||
| 1902 | * Instantiates a new content update struct. |
||
| 1903 | * |
||
| 1904 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 1905 | */ |
||
| 1906 | public function newContentUpdateStruct() |
||
| 1910 | |||
| 1911 | /** |
||
| 1912 | * Instantiates a new TranslationInfo object. |
||
| 1913 | * |
||
| 1914 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 1915 | */ |
||
| 1916 | public function newTranslationInfo() |
||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Instantiates a Translation object. |
||
| 1923 | * |
||
| 1924 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 1925 | */ |
||
| 1926 | public function newTranslationValues() |
||
| 1930 | } |
||
| 1931 |
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.