eZ\Publish\Core\REST\Server\Controller\Content::updateContentMetadata PHP Method

updateContentMetadata() public method

Updates a content's metadata.
public updateContentMetadata ( mixed $contentId, Request $request ) : RestContent
$contentId mixed
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\Core\REST\Server\Values\RestContent
    public function updateContentMetadata($contentId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
        // update section
        if ($updateStruct->sectionId !== null) {
            $section = $this->repository->getSectionService()->loadSection($updateStruct->sectionId);
            $this->repository->getSectionService()->assignSection($contentInfo, $section);
            $updateStruct->sectionId = null;
        }
        // @todo Consider refactoring! ContentService::updateContentMetadata throws the same exception
        // in case the updateStruct is empty and if remoteId already exists. Since REST version of update struct
        // includes section ID in addition to other fields, we cannot throw exception if only sectionId property
        // is set, so we must skip updating content in that case instead of allowing propagation of the exception.
        foreach ($updateStruct as $propertyName => $propertyValue) {
            if ($propertyName !== 'sectionId' && $propertyValue !== null) {
                // update content
                $this->repository->getContentService()->updateContentMetadata($contentInfo, $updateStruct);
                $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
                break;
            }
        }
        try {
            $locationInfo = $this->repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
        } catch (NotFoundException $e) {
            $locationInfo = null;
        }
        return new Values\RestContent($contentInfo, $locationInfo);
    }