The system creates a new draft version as a copy from the current version.

@param mixed $contentId

@throws ForbiddenException if the current version is already a draft

@return \eZ\Publish\Core\REST\Server\Values\CreatedVersion
489
public function createDraftFromCurrentVersion($contentId)
    {
        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
        $contentType = $this->repository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
        $versionInfo = $this->repository->getContentService()->loadVersionInfo(
            $contentInfo
        );

        if ($versionInfo->isDraft()) {
            throw new ForbiddenException('Current version is already in status DRAFT');
        }

        $contentDraft = $this->repository->getContentService()->createContentDraft($contentInfo);

        return new Values\CreatedVersion(
            array(
                'version' => new Values\Version(
                    $contentDraft,
                    $contentType,
                    $this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo())
                ),
            )
        );
    }
208693
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->isAuthor) {
            if ($model->load(Yii::$app->request->post()) && $model->save()) {
                Yii::$app->getSession()->setFlash('success', Yii::t('article', 'Article updated.'));
                return $this->redirect(['view', 'uuid' => $model->uuid]);
            }
            return $this->render('update', ['model' => $model]);
        }
        throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
    }
35867
public function createContentTypeDraft($contentTypeId, Request $request)
    {
        $contentType = $this->contentTypeService->loadContentType($contentTypeId);

        try {
            $contentTypeDraft = $this->contentTypeService->createContentTypeDraft(
                $contentType
            );
        } catch (BadStateException $e) {
            throw new ForbiddenException($e->getMessage());
        }

        $contentTypeUpdateStruct = $this->inputDispatcher->parse(
            new Message(
                array(
                    'Content-Type' => $request->headers->get('Content-Type'),
                ),
                $request->getContent()
            )
        );

        try {
            $this->contentTypeService->updateContentTypeDraft(
                $contentTypeDraft,
                $contentTypeUpdateStruct
            );
        } catch (InvalidArgumentException $e) {
            throw new ForbiddenException($e->getMessage());
        }

        return new Values\CreatedContentType(
            array(
                'contentType' => new Values\RestContentType(
                    // Reload the content type draft to get the updated values
                    $this->contentTypeService->loadContentTypeDraft(
                        $contentTypeDraft->id
                    )
                ),
            )
        );
    }
903101
public static function fromString(string $id): self
    {
        list($contentId, $versionNo) = explode(':', $id);

        return new self((int) $contentId, (int) $versionNo);
    }
851814
public function getLastVersionNumber($contentId)
    {
        try {
            return $this->innerGateway->getLastVersionNumber($contentId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1185314
public function copy($userId, $contentTypeId, $status)
    {
        $createStruct = $this->mapper->createCreateStructFromType(
            $this->load($contentTypeId, $status)
        );
        $createStruct->modifierId = $userId;
        $createStruct->created = $createStruct->modified = time();
        $createStruct->creatorId = $userId;
        $createStruct->remoteId = md5(uniqid(get_class($createStruct), true));

        // extract actual identifier name, without "copy_of_" and number
        $originalIdentifier = preg_replace('/^copy_of_(.+)_\d+$/', '$1', $createStruct->identifier);

        // set temporary identifier
        $createStruct->identifier = $createStruct->remoteId;

        // Set FieldDefinition ids to null to trigger creating new id
        foreach ($createStruct->fieldDefinitions as $fieldDefinition) {
            $fieldDefinition->id = null;
        }

        $contentTypeCopy = $this->internalCreate($createStruct);
        $updateStruct = $this->mapper->createUpdateStructFromType($contentTypeCopy);
        $updateStruct->identifier = 'copy_of_' . $originalIdentifier . '_' . $contentTypeCopy->id;

        return $this->update($contentTypeCopy->id, $contentTypeCopy->status, $updateStruct);
    }
803318
public function copyContent($contentId, Request $request)
    {
        $destination = $request->headers->get('Destination');

        $parentLocationParts = explode('/', $destination);
        $copiedContent = $this->repository->getContentService()->copyContent(
            $this->repository->getContentService()->loadContentInfo($contentId),
            $this->repository->getLocationService()->newLocationCreateStruct(array_pop($parentLocationParts))
        );

        return new Values\ResourceCreated(
            $this->router->generate(
                'ezpublish_rest_loadContent',
                array('contentId' => $copiedContent->id)
            )
        );
    }
902288
public function setContentIdVersion($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->content_id_version !== $v) {
            $this->content_id_version = $v;
            $this->modifiedColumns[DealerContentVersionTableMap::CONTENT_ID_VERSION] = true;
        }


        return $this;
    }
524309
protected function getContent($contentId)
    {
        $content = null;
        if (!is_null($contentId)) {
            $language = $this->currentSiteManager->getSiteLanguage();
            $content = $this->contentRepository->findPublishedVersion($contentId, $language);
        }

        if (is_null($content) && $this->requestStack->getMasterRequest()->get('token')) {
            $content = new FakeContent();
        }

        return $content;
    }
778415
private function getContentIdentifier($contentId)
    {
        $contentType = $this->contentTypeService->loadContentType(
            $this->contentService
                ->loadContent($contentId)
                ->contentInfo
                ->contentTypeId
        );

        return $contentType->identifier;
    }
66513
public function lastModified($contenttypeslug, $contentid = null)
    {
        // Let's find out how we should determine what the latest changes were:
        $contentLogEnabled = (bool) $this->getOption('general/changelog/enabled');

        if ($contentLogEnabled) {
            return $this->getLastmodifiedByContentLog($contenttypeslug, $contentid);
        }

        return $this->getLastmodifiedSimple($contenttypeslug);
    }
937782
public function createExistingFieldsInNewVersion(Content $content)
    {
        foreach ($content->fields as $field) {
            $this->createExistingFieldInNewVersion($field, $content);
        }
    }
1082587
public function contentId($id = null)
    {
        if ($id === null) {
            return $this->_contentId;
        }
        $this->_contentId = $id;
    }
97273
private function loadVersionInfo($contentId): VersionInfo
    {
        return $this->repository->sudo(
            static function (Repository $repository) use ($contentId): VersionInfo {
                return $repository->getContentService()->loadVersionInfoById($contentId);
            }
        );
    }
1223519
public function loadContentType($contentTypeId)
    {
        $contentType = $this->contentTypeService->loadContentType($contentTypeId, Language::ALL);

        return new Values\RestContentType(
            $contentType,
            $contentType->getFieldDefinitions()
        );
    }
934799
public function deleteNames($contentId, $versionNo = null)
    {
        $query = $this->dbHandler->createDeleteQuery();
        $query->deleteFrom('ezcontentobject_name')
            ->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('contentobject_id'),
                    $query->bindValue($contentId, null, \PDO::PARAM_INT)
                )
            );

        if (isset($versionNo)) {
            $query->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('content_version'),
                    $query->bindValue($versionNo, null, \PDO::PARAM_INT)
                )
            );
        }

        $query->prepare()->execute();
    }
704052
public function deleteContent($contentId)
    {
        $this->repository->getContentService()->deleteContent(
            $this->repository->getContentService()->loadContentInfo($contentId)
        );

        return new Values\NoContent();
    }