eZ\Publish\Core\REST\Server\Controller\Content::updateVersion PHP 메소드

updateVersion() 공개 메소드

A specific draft is updated.
public updateVersion ( mixed $contentId, mixed $versionNumber, Request $request ) : Version
$contentId mixed
$versionNumber mixed
$request Symfony\Component\HttpFoundation\Request
리턴 eZ\Publish\Core\REST\Server\Values\Version
    public function updateVersion($contentId, $versionNumber, Request $request)
    {
        $contentUpdateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type'), 'Url' => $this->router->generate('ezpublish_rest_updateVersion', array('contentId' => $contentId, 'versionNumber' => $versionNumber))), $request->getContent()));
        $versionInfo = $this->repository->getContentService()->loadVersionInfo($this->repository->getContentService()->loadContentInfo($contentId), $versionNumber);
        if ($versionInfo->status !== VersionInfo::STATUS_DRAFT) {
            throw new ForbiddenException('Only version in status DRAFT can be updated');
        }
        try {
            $this->repository->getContentService()->updateContent($versionInfo, $contentUpdateStruct);
        } catch (ContentValidationException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (ContentFieldValidationException $e) {
            throw new RESTContentFieldValidationException($e);
        }
        $languages = null;
        if ($request->query->has('languages')) {
            $languages = explode(',', $request->query->get('languages'));
        }
        // Reload the content to handle languages GET parameter
        $content = $this->repository->getContentService()->loadContent($contentId, $languages, $versionInfo->versionNo);
        $contentType = $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
        return new Values\Version($content, $contentType, $this->repository->getContentService()->loadRelations($content->getVersionInfo()), $request->getPathInfo());
    }

Usage Example

예제 #1
0
 /**
  * If the updated content is a user, update it using the user API, and return a Version object.
  *
  * @param mixed $contentId
  * @param int $versionNumber
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \eZ\Publish\Core\REST\Server\Values\Version
  */
 public function updateVersion($contentId, $versionNumber, Request $request)
 {
     if (!$this->isUserContent($contentId)) {
         return parent::updateVersion($contentId, $versionNumber, $request);
     }
     $updatedUser = $this->repository->getUserService()->updateUser($this->repository->getUserService()->loadUser($contentId), $this->mapRequestToUserUpdateStruct($request));
     return $this->mapUserToVersion($updatedUser, $request);
 }