/** * Maps Repository ContentInfo to the Site ContentInfo. * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param string $languageCode * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType * * @return \Netgen\EzPlatformSiteApi\API\Values\ContentInfo */ public function mapContentInfo(VersionInfo $versionInfo, $languageCode, ContentType $contentType = null) { $contentInfo = $versionInfo->contentInfo; if ($contentType === null) { $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId); } return new ContentInfo(['name' => $versionInfo->getName($languageCode), 'languageCode' => $languageCode, 'innerContentInfo' => $versionInfo->contentInfo, 'innerContentType' => $contentType]); }
/** * Returns content name, translated, from a VersionInfo object. * By default this method uses prioritized languages, unless $forcedLanguage is provided. * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param string $forcedLanguage * * @return string */ private function getTranslatedContentNameByVersionInfo(VersionInfo $versionInfo, $forcedLanguage = null) { foreach ($this->getLanguages($forcedLanguage) as $lang) { $translatedName = $versionInfo->getName($lang); if ($translatedName !== null) { return $translatedName; } } return ''; }
public function __get($property) { switch ($property) { case 'contentInfo': return $this->getContentInfo(); } return parent::__get($property); }
/** * Publishes a content version. * * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param int|null $publicationDate * * @return \eZ\Publish\API\Repository\Values\Content\Content */ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) { if ($versionInfo->status !== APIVersionInfo::STATUS_DRAFT) { throw new BadStateException('$versionInfo', 'Only versions in draft status can be published.'); } $metadataUpdateStruct = new SPIMetadataUpdateStruct(); $metadataUpdateStruct->publicationDate = isset($publicationDate) ? $publicationDate : time(); $metadataUpdateStruct->modificationDate = $metadataUpdateStruct->publicationDate; $spiContent = $this->persistenceHandler->contentHandler()->publish($versionInfo->getContentInfo()->id, $versionInfo->versionNo, $metadataUpdateStruct); $content = $this->domainMapper->buildContentDomainObject($spiContent); $this->publishUrlAliasesForContent($content); return $content; }
/** * Publishes a content version. * * Publishes a content version and deletes archive versions if they overflow max archive versions. * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. * * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) { if ($versionInfo->status !== APIVersionInfo::STATUS_DRAFT) { throw new BadStateException('$versionInfo', 'Only versions in draft status can be published.'); } $currentTime = time(); if ($publicationDate === null && $versionInfo->versionNo === 1) { $publicationDate = $currentTime; } $metadataUpdateStruct = new SPIMetadataUpdateStruct(); $metadataUpdateStruct->publicationDate = $publicationDate; $metadataUpdateStruct->modificationDate = $currentTime; $contentId = $versionInfo->getContentInfo()->id; $spiContent = $this->persistenceHandler->contentHandler()->publish($contentId, $versionInfo->versionNo, $metadataUpdateStruct); $content = $this->domainMapper->buildContentDomainObject($spiContent); $this->publishUrlAliasesForContent($content); // Delete version archive overflow if any, limit is 0-50 (however 0 will mean 1 if content is unpublished) $archiveList = $this->persistenceHandler->contentHandler()->listVersions($contentId, APIVersionInfo::STATUS_ARCHIVED, 100); $maxVersionArchiveCount = max(0, min(50, $this->settings['default_version_archive_limit'])); while (!empty($archiveList) && count($archiveList) > $maxVersionArchiveCount) { /** @var \eZ\Publish\SPI\Persistence\Content\VersionInfo $archiveVersion */ $archiveVersion = array_shift($archiveList); $this->persistenceHandler->contentHandler()->deleteVersion($contentId, $archiveVersion->versionNo); } return $content; }
/** * Loads content in the version given by version info. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param array $languages A language filter for fields. If not given all languages are returned * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) { $contentInfo = $versionInfo->getContentInfo(); return $this->loadContent($contentInfo->id, $languages, $versionInfo->versionNo); }
/** * Loads content in the version given by version info. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param array $languages A language filter for fields. If not given all languages are returned * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null) { $contentInfo = $versionInfo->getContentInfo(); return $this->loadContent($contentInfo->id, $languages, $versionInfo->versionNo); }
/** * Auto-generates the URL aliases for $versionInfo * * ATTENTION: This method is not part of the Public API but is only used * internally in this implementation. * * @access private * * @internal * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * * @return void */ public function createAliasesForVersion(VersionInfo $versionInfo) { $locationService = $this->repository->getLocationService(); $locations = $locationService->loadLocations($versionInfo->getContentInfo()); foreach ($locations as $location) { $this->obsoleteOldAliases($location); $this->createAliasesForLocation($location); } }
/** * Publishes a content version * * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * @param int|null $publicationDate * * @return \eZ\Publish\API\Repository\Values\Content\Content */ protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) { if ($versionInfo->status !== APIVersionInfo::STATUS_DRAFT) { throw new BadStateException("\$versionInfo", "Only versions in draft status can be published."); } $metadataUpdateStruct = new SPIMetadataUpdateStruct(); $metadataUpdateStruct->publicationDate = time(); if (!is_null($versionInfo->creationDate->getTimestamp())) { $metadataUpdateStruct->publicationDate = $versionInfo->creationDate->getTimestamp(); } if (isset($publicationDate)) { $metadataUpdateStruct->publicationDate = $publicationDate; } $metadataUpdateStruct->modificationDate = $metadataUpdateStruct->publicationDate; if ($versionInfo->contentInfo->currentVersionNo != 1) { $metadataUpdateStruct->modificationDate = time(); } $spiContent = $this->persistenceHandler->contentHandler()->publish($versionInfo->getContentInfo()->id, $versionInfo->versionNo, $metadataUpdateStruct); $content = $this->domainMapper->buildContentDomainObject($spiContent); $this->publishUrlAliasesForContent($content); return $content; }
public function __isset($propertyName) { switch ($propertyName) { case 'contentInfo': return true; } return parent::__isset($propertyName); }
/** * Removes a relation of type COMMON from a draft. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent */ public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) { if (false === $this->repository->hasAccess('content', 'edit')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } if (VersionInfo::STATUS_DRAFT !== $sourceVersion->status) { throw new BadStateExceptionStub('What error code should be used?'); } $relationNotFound = true; $relationNoCommon = true; foreach ($this->relation as $i => $relation) { if ($relation->getDestinationContentInfo() !== $destinationContent) { continue; } if ($relation->getSourceContentInfo() !== $sourceVersion->getContentInfo()) { continue; } $relationNotFound = false; if ($relation->type !== Relation::COMMON) { continue; } $relationNoCommon = false; unset($this->relation[$i]); break; } if ($relationNotFound || $relationNoCommon) { throw new InvalidArgumentExceptionStub('What error code should be used?'); } }