示例#1
0
 /**
  * Get ObjectStateService
  *
  * @return \eZ\Publish\API\Repository\ObjectStateService
  */
 public function getObjectStateService()
 {
     if ($this->objectStateService !== null) {
         return $this->objectStateService;
     }
     $this->objectStateService = new ObjectStateService($this, $this->persistenceHandler->objectStateHandler(), $this->serviceSettings['objectState']);
     return $this->objectStateService;
 }
示例#2
0
    /**
     * Copies the content to a new location. If no version is given,
     * all versions are copied, otherwise only the given version.
     *
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
     *
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
     *
     * @return \eZ\Publish\API\Repository\Values\Content\Content
     */
    public function copyContent( ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null)
    {
        if ( !$this->repository->canUser( 'content', 'create', $contentInfo, $destinationLocationCreateStruct ) )
        {
            throw new UnauthorizedException(
                'content',
                'create',
                array(
                    'parentLocationId' => $destinationLocationCreateStruct->parentLocationId,
                    'sectionId' => $contentInfo->sectionId
                )
            );
        }

        $defaultObjectStates = $this->getDefaultObjectStates();

        $this->repository->beginTransaction();
        try
        {
            $spiContent = $this->persistenceHandler->contentHandler()->copy(
                $contentInfo->id,
                $versionInfo ? $versionInfo->versionNo : null
            );

            foreach ( $defaultObjectStates as $objectStateGroupId => $objectState )
            {
                $this->persistenceHandler->objectStateHandler()->setContentState(
                    $spiContent->versionInfo->contentInfo->id,
                    $objectStateGroupId,
                    $objectState->id
                );
            }

            $content = $this->internalPublishVersion(
                $this->domainMapper->buildVersionInfoDomainObject( $spiContent->versionInfo ),
                $spiContent->versionInfo->creationDate
            );

            $this->repository->getLocationService()->createLocation(
                $content->getVersionInfo()->getContentInfo(),
                $destinationLocationCreateStruct
            );
            $this->repository->commit();
        }
        catch ( Exception $e )
        {
            $this->repository->rollback();
            throw $e;
        }

        return $content;
    }
示例#3
0
 /**
  * @return \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler
  * @todo Create cache implementation so we can avoid injecting persistenceHandler and logger
  */
 public function objectStateHandler()
 {
     $this->logger->logUnCachedHandler(__METHOD__);
     return $this->persistenceHandler->objectStateHandler();
 }