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);
}