Builds a Content domain object from value object returned from persistence.
public buildContentDomainObject ( eZ\Publish\SPI\Persistence\Content $spiContent, eZ\Publish\API\Repository\Values\ContentType\ContentType | eZ\Publish\SPI\Persistence\Content\Type $contentType = null, array $fieldLanguages = null, string | null $fieldAlwaysAvailableLanguage = null ) : |
||
$spiContent | eZ\Publish\SPI\Persistence\Content | |
$contentType | eZ\Publish\API\Repository\Values\ContentType\ContentType | eZ\Publish\SPI\Persistence\Content\Type | |
$fieldLanguages | array | Language codes to filter fields on |
$fieldAlwaysAvailableLanguage | string | null | Language code fallback if a given field is not found in $fieldLanguages |
Résultat |
/** * 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; }
/** * 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; }