eZ\Publish\Core\Repository\ContentService::updateContentMetadata PHP Method

updateContentMetadata() public method

(see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
public updateContentMetadata ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct ) : eZ\Publish\API\Repository\Values\Content\Content
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
$contentMetadataUpdateStruct eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
return eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
    public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
    {
        $propertyCount = 0;
        foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) {
            if (isset($contentMetadataUpdateStruct->{$propertyName})) {
                $propertyCount += 1;
            }
        }
        if ($propertyCount === 0) {
            throw new InvalidArgumentException('$contentMetadataUpdateStruct', 'At least one property must be set');
        }
        $loadedContentInfo = $this->loadContentInfo($contentInfo->id);
        if (!$this->repository->canUser('content', 'edit', $loadedContentInfo)) {
            throw new UnauthorizedException('content', 'edit', array('contentId' => $loadedContentInfo->id));
        }
        if (isset($contentMetadataUpdateStruct->remoteId)) {
            try {
                $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId);
                if ($existingContentInfo->id !== $loadedContentInfo->id) {
                    throw new InvalidArgumentException('$contentMetadataUpdateStruct', "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists");
                }
            } catch (APINotFoundException $e) {
                // Do nothing
            }
        }
        $this->repository->beginTransaction();
        try {
            if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) {
                $this->persistenceHandler->contentHandler()->updateMetadata($loadedContentInfo->id, new SPIMetadataUpdateStruct(array('ownerId' => $contentMetadataUpdateStruct->ownerId, 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ? $contentMetadataUpdateStruct->publishedDate->getTimestamp() : null, 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ? $contentMetadataUpdateStruct->modificationDate->getTimestamp() : null, 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ? $this->repository->getContentLanguageService()->loadLanguage($contentMetadataUpdateStruct->mainLanguageCode)->id : null, 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable, 'remoteId' => $contentMetadataUpdateStruct->remoteId)));
            }
            // Change main location
            if (isset($contentMetadataUpdateStruct->mainLocationId) && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) {
                $this->persistenceHandler->locationHandler()->changeMainLocation($loadedContentInfo->id, $contentMetadataUpdateStruct->mainLocationId);
            }
            // Republish URL aliases to update always-available flag
            if (isset($contentMetadataUpdateStruct->alwaysAvailable) && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) {
                $content = $this->loadContent($loadedContentInfo->id);
                $this->publishUrlAliasesForContent($content, false);
            }
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
        return isset($content) ? $content : $this->loadContent($loadedContentInfo->id);
    }