createVersionInfoForContent() public method

Creates a new version for the given $content.
public createVersionInfoForContent ( eZ\Publish\SPI\Persistence\Content $content, mixed $versionNo, mixed $userId ) : eZ\Publish\SPI\Persistence\Content\VersionInfo
$content eZ\Publish\SPI\Persistence\Content
$versionNo mixed
$userId mixed
return eZ\Publish\SPI\Persistence\Content\VersionInfo
コード例 #1
0
ファイル: Handler.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Creates a new draft version from $contentId in $version.
  *
  * Copies all fields from $contentId in $srcVersion and creates a new
  * version of the referred Content from it.
  *
  * Note: When creating a new draft in the old admin interface there will
  * also be an entry in the `eznode_assignment` created for the draft. This
  * is ignored in this implementation.
  *
  * @param mixed $contentId
  * @param mixed $srcVersion
  * @param mixed $userId
  *
  * @return \eZ\Publish\SPI\Persistence\Content
  */
 public function createDraftFromVersion($contentId, $srcVersion, $userId)
 {
     $content = $this->load($contentId, $srcVersion);
     // Create new version
     $content->versionInfo = $this->mapper->createVersionInfoForContent($content, $this->contentGateway->getLastVersionNumber($contentId) + 1, $userId);
     $content->versionInfo->id = $this->contentGateway->insertVersion($content->versionInfo, $content->fields);
     // Clone fields from previous version and append them to the new one
     $this->fieldHandler->createExistingFieldsInNewVersion($content);
     // Create relations for new version
     $relations = $this->contentGateway->loadRelations($contentId, $srcVersion);
     foreach ($relations as $relation) {
         $this->contentGateway->insertRelation(new RelationCreateStruct(array('sourceContentId' => $contentId, 'sourceContentVersionNo' => $content->versionInfo->versionNo, 'sourceFieldDefinitionId' => $relation['ezcontentobject_link_contentclassattribute_id'], 'destinationContentId' => $relation['ezcontentobject_link_to_contentobject_id'], 'type' => (int) $relation['ezcontentobject_link_relation_type'])));
     }
     // Create content names for new version
     foreach ($content->versionInfo->names as $language => $name) {
         $this->contentGateway->setName($contentId, $content->versionInfo->versionNo, $name, $language);
     }
     return $content;
 }