eZ\Publish\Core\Persistence\Legacy\Content\Gateway::copyRelations PHP Method

copyRelations() abstract public method

Is meant to be used during content copy, so assumes the following: - version number is the same - content type, and hence content type attribute is the same - relation type is the same - target relation is the same
abstract public copyRelations ( integer $originalContentId, integer $copiedContentId, integer | null $versionNo = null )
$originalContentId integer
$copiedContentId integer
$versionNo integer | null If specified only copy for a given version number, otherwise all.
    public abstract function copyRelations($originalContentId, $copiedContentId, $versionNo = null);

Usage Example

Esempio n. 1
0
 /**
  * Copy Content with Fields, Versions & Relations from $contentId in $version.
  *
  * {@inheritdoc}
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If content or version is not found
  *
  * @param mixed $contentId
  * @param mixed|null $versionNo Copy all versions if left null
  *
  * @return \eZ\Publish\SPI\Persistence\Content
  */
 public function copy($contentId, $versionNo = null)
 {
     $currentVersionNo = isset($versionNo) ? $versionNo : $this->loadContentInfo($contentId)->currentVersionNo;
     // Copy content in given version or current version
     $createStruct = $this->mapper->createCreateStructFromContent($this->load($contentId, $currentVersionNo));
     $content = $this->internalCreate($createStruct, $currentVersionNo);
     // If version was not passed also copy other versions
     if (!isset($versionNo)) {
         $contentType = $this->contentTypeHandler->load($createStruct->typeId);
         foreach ($this->listVersions($contentId) as $versionInfo) {
             if ($versionInfo->versionNo === $currentVersionNo) {
                 continue;
             }
             $versionContent = $this->load($contentId, $versionInfo->versionNo);
             $versionContent->versionInfo->contentInfo->id = $content->versionInfo->contentInfo->id;
             $versionContent->versionInfo->modificationDate = $createStruct->modified;
             $versionContent->versionInfo->creationDate = $createStruct->modified;
             $versionContent->versionInfo->id = $this->contentGateway->insertVersion($versionContent->versionInfo, $versionContent->fields);
             $this->fieldHandler->createNewFields($versionContent, $contentType);
             // Create names
             foreach ($versionContent->versionInfo->names as $language => $name) {
                 $this->contentGateway->setName($content->versionInfo->contentInfo->id, $versionInfo->versionNo, $name, $language);
             }
         }
         // Batch copy relations for all versions
         $this->contentGateway->copyRelations($contentId, $content->versionInfo->contentInfo->id);
     } else {
         // Batch copy relations for published version
         $this->contentGateway->copyRelations($contentId, $content->versionInfo->contentInfo->id, $versionNo);
     }
     return $content;
 }
All Usage Examples Of eZ\Publish\Core\Persistence\Legacy\Content\Gateway::copyRelations