From b74cd70bc9b529857232cd7c0a7b4c4a7fda1e57 Mon Sep 17 00:00:00 2001 From: Kamil Madejski Date: Wed, 19 Dec 2018 20:02:08 +0100 Subject: [PATCH 1/3] EZP-29451: As an Administrator I want to have a CLI command for database cleanup (#2431) * As an Administrator I want to have a CLI command for database cleanup * fixup! As an Administrator I want to have a CLI command for database cleanup * fixup! fixup! As an Administrator I want to have a CLI command for database cleanup * fixup! fixup! fixup! As an Administrator I want to have a CLI command for database cleanup * Changed command name * Adapt command for 6.7 * fixup! Adapt command for 6.7 * Review improvements * Fixed invalid behavior of version counter * Improved mapping of version status * fixup! Improved mapping of version status * fixup! fixup! Improved mapping of version status * Covered edge-case with keep = 0 --- .../Command/CleanupVersionsCommand.php | 266 ++++++++++++++++++ .../Resources/config/services.yml | 9 + 2 files changed, 275 insertions(+) create mode 100644 eZ/Bundle/EzPublishCoreBundle/Command/CleanupVersionsCommand.php diff --git a/eZ/Bundle/EzPublishCoreBundle/Command/CleanupVersionsCommand.php b/eZ/Bundle/EzPublishCoreBundle/Command/CleanupVersionsCommand.php new file mode 100644 index 00000000000..a9b4ddb1c03 --- /dev/null +++ b/eZ/Bundle/EzPublishCoreBundle/Command/CleanupVersionsCommand.php @@ -0,0 +1,266 @@ + VersionInfo::STATUS_DRAFT, + self::VERSION_ARCHIVED => VersionInfo::STATUS_ARCHIVED, + self::VERSION_PUBLISHED => VersionInfo::STATUS_PUBLISHED, + ]; + + /** + * @var \eZ\Publish\API\Repository\Repository + */ + private $repository; + + /** + * @var \eZ\Publish\API\Repository\UserService + */ + private $userService; + + /** + * @var \eZ\Publish\API\Repository\ContentService + */ + private $contentService; + + /** + * @var \eZ\Publish\API\Repository\PermissionResolver + */ + private $permissionResolver; + + /** + * @var \eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider + */ + private $repositoryConfigurationProvider; + + /** + * @var \Doctrine\DBAL\Driver\Connection + */ + private $connection; + + public function __construct( + Repository $repository, + RepositoryConfigurationProvider $repositoryConfigurationProvider, + Connection $connection + ) { + $this->repository = $repository; + $this->repositoryConfigurationProvider = $repositoryConfigurationProvider; + $this->connection = $connection; + + parent::__construct(); + } + + protected function initialize(InputInterface $input, OutputInterface $output) + { + parent::initialize($input, $output); + + $this->userService = $this->repository->getUserService(); + $this->contentService = $this->repository->getContentService(); + $this->permissionResolver = $this->repository->getPermissionResolver(); + + $this->permissionResolver->setCurrentUserReference( + $this->userService->loadUserByLogin($input->getOption('user')) + ); + } + + protected function configure() + { + $config = $this->repositoryConfigurationProvider->getRepositoryConfig(); + + $this + ->setName('ezplatform:content:cleanup-versions') + ->setDescription('Remove unwanted content versions. It keeps published version untouched. By default, it keeps also the last archived/draft version.') + ->addOption( + 'status', + 't', + InputOption::VALUE_OPTIONAL, + sprintf( + "Select which version types should be removed: '%s', '%s', '%s'.", + self::VERSION_DRAFT, + self::VERSION_ARCHIVED, + self::VERSION_ALL + ), + self::VERSION_ALL + ) + ->addOption( + 'keep', + 'k', + InputOption::VALUE_OPTIONAL, + "Sets number of the most recent versions (both drafts and archived) which won't be removed.", + $config['options']['default_version_archive_limit'] + ) + ->addOption( + 'user', + 'u', + InputOption::VALUE_OPTIONAL, + 'eZ Platform username (with Role containing at least Content policies: remove, read, versionread)', + self::DEFAULT_REPOSITORY_USER + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if (($keep = (int) $input->getOption('keep')) < 0) { + throw new InvalidArgumentException( + 'status', + 'Keep value can not be negative.' + ); + } + + $status = $input->getOption('status'); + + $contentIds = $this->getObjectsIds($keep, $status); + $contentIdsCount = count($contentIds); + + if ($contentIdsCount === 0) { + $output->writeln('There is no Content matching given criteria.'); + + return; + } + + $output->writeln(sprintf( + 'Found %d Content IDs matching given criteria.', + $contentIdsCount + )); + + $removedVersionsCounter = 0; + + $removeAll = $status === self::VERSION_ALL; + $removeDrafts = $status === self::VERSION_DRAFT; + $removeArchived = $status === self::VERSION_ARCHIVED; + + foreach ($contentIds as $contentId) { + try { + $contentInfo = $this->contentService->loadContentInfo((int) $contentId); + $versions = $this->contentService->loadVersions($contentInfo); + $versionsCount = count($versions); + + $output->writeln(sprintf( + 'Content %d has %d version(s)', + (int) $contentId, + $versionsCount + ), Output::VERBOSITY_VERBOSE); + + $versions = array_filter($versions, function ($version) use ($removeAll, $removeDrafts, $removeArchived) { + if ( + ($removeAll && $version->status !== VersionInfo::STATUS_PUBLISHED) || + ($removeDrafts && $version->status === VersionInfo::STATUS_DRAFT) || + ($removeArchived && $version->status === VersionInfo::STATUS_ARCHIVED) + ) { + return $version; + } + }); + + if ($keep > 0) { + $versions = array_slice($versions, 0, -$keep); + } + + $output->writeln(sprintf( + "Found %d content's (%d) version(s) to remove.", + count($versions), + (int) $contentId + ), Output::VERBOSITY_VERBOSE); + + /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $version */ + foreach ($versions as $version) { + $this->contentService->deleteVersion($version); + ++$removedVersionsCounter; + $output->writeln(sprintf( + "Content's (%d) version (%d) has been deleted.", + $contentInfo->id, + $version->id + ), Output::VERBOSITY_VERBOSE); + } + } catch (Exception $e) { + $output->writeln(sprintf( + '%s', + $e->getMessage() + )); + } + } + + $output->writeln(sprintf( + 'Removed %d unwanted contents version(s).', + $removedVersionsCounter + )); + } + + /** + * @param int $keep + * @param string $status + * + * @return array + * + * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException + */ + protected function getObjectsIds($keep, $status) + { + $query = $this->connection->createQueryBuilder() + ->select('c.id') + ->from('ezcontentobject', 'c') + ->join('c', 'ezcontentobject_version', 'v', 'v.contentobject_id = c.id') + ->groupBy('c.id', 'v.status') + ->having('count(c.id) > :keep'); + $query->setParameter('keep', $keep); + + if ($status !== self::VERSION_ALL) { + $query->where('v.status = :status'); + $query->setParameter('status', $this->mapStatusToVersionInfoStatus($status)); + } else { + $query->andWhere('v.status != :status'); + $query->setParameter('status', $this->mapStatusToVersionInfoStatus(self::VERSION_PUBLISHED)); + } + + $stmt = $query->execute(); + + return $stmt->fetchAll(PDO::FETCH_COLUMN); + } + + /** + * @param string $status + * + * @return int + * + * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException + */ + private function mapStatusToVersionInfoStatus($status) + { + if (array_key_exists($status, self::VERSION_STATUS)) { + return self::VERSION_STATUS[$status]; + } + + throw new InvalidArgumentException( + 'status', + sprintf( + "Status %s can't be mapped to VersionInfo status.", + $status + ) + ); + } +} diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml index 163a1793bd8..8e37d70a136 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/services.yml @@ -237,3 +237,12 @@ services: class: eZ\Publish\Core\MVC\Symfony\Translation\ValidationErrorFileVisitor tags: - { name: jms_translation.file_visitor, alias: ez_validation_error } + + ezplatform.core.command.cleanup_versions: + class: eZ\Bundle\EzPublishCoreBundle\Command\CleanupVersionsCommand + arguments: + - "@ezpublish.signalslot.repository" + - "@ezpublish.api.repository_configuration_provider" + - "@ezpublish.persistence.connection" + tags: + - { name: console.command } From bac3e8925d2ae058fd0ad0b45888cb5bf4c64d40 Mon Sep 17 00:00:00 2001 From: Kamil Madejski Date: Thu, 20 Dec 2018 16:26:54 +0100 Subject: [PATCH 2/3] EZP-29749: As an Administrator I want to configure Imagine ProxyResolver (#2470) * EZP-29749: As an Administrator I want to configure Imagine ProxyResolver * Update eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml --- .../Configuration/Parser/Image.php | 5 +++ .../Imagine/ResolverFactory.php | 44 +++++++++++++++++++ .../Resources/config/default_settings.yml | 2 + .../Resources/config/image.yml | 14 ++++++ 4 files changed, 65 insertions(+) create mode 100644 eZ/Bundle/EzPublishCoreBundle/Imagine/ResolverFactory.php diff --git a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/Parser/Image.php b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/Parser/Image.php index af64b98e68e..a8c5b5fe01e 100644 --- a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/Parser/Image.php +++ b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/Parser/Image.php @@ -115,12 +115,17 @@ function ($v) { ->end() ->end() ->end() + ->end() + ->scalarNode('image_host') + ->info('Images host. All system images URLs are prefixed with given host if configured.') + ->example('https://ezplatform.com') ->end(); } public function preMap(array $config, ContextualizerInterface $contextualizer) { $contextualizer->mapConfigArray('image_variations', $config); + $contextualizer->mapSetting('image_host', $config); } public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer) diff --git a/eZ/Bundle/EzPublishCoreBundle/Imagine/ResolverFactory.php b/eZ/Bundle/EzPublishCoreBundle/Imagine/ResolverFactory.php new file mode 100644 index 00000000000..96960e30df6 --- /dev/null +++ b/eZ/Bundle/EzPublishCoreBundle/Imagine/ResolverFactory.php @@ -0,0 +1,44 @@ +resolver = $resolver; + $this->proxyResolverClass = $proxyResolverClass; + + if ($configResolver->hasParameter('image_host') && + ($imageHost = $configResolver->getParameter('image_host')) !== '') { + $this->hosts = [$imageHost]; + } + } + + public function createCacheResolver() + { + return new $this->proxyResolverClass($this->resolver, $this->hosts); + } +} diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/default_settings.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/default_settings.yml index 7a65c2c5ece..0f219ccbf0b 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/default_settings.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/default_settings.yml @@ -211,6 +211,8 @@ parameters: resize: "-resize {1}" optimize: "-strip" + ezsettings.default.image_host: '' + ### # default ezpage settings ## diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml index b0a9a3e5982..b09a4bdf9a3 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml @@ -1,7 +1,9 @@ parameters: liip_imagine.filter.configuration.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Filter\FilterConfiguration + liip_imagine.cache_resolver.proxy.class: Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver ezpublish.image_alias.imagine.binary_loader.class: eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader + ezpublish.image_alias.imagine.decorated_cache_resolver_factory.class: eZ\Bundle\EzPublishCoreBundle\Imagine\ResolverFactory ezpublish.image_alias.imagine.cache_resolver.class: eZ\Bundle\EzPublishCoreBundle\Imagine\IORepositoryResolver ezpublish.image_alias.imagine.cache.alias_generator_decorator.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator ezpublish.image_alias.imagine.variation.imagine_alias_generator.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Variation\ImagineAwareAliasGenerator @@ -83,6 +85,18 @@ services: tags: - { name: liip_imagine.cache.resolver, resolver: ezpublish } + ezpublish.image_alias.imagine.cache_resolver_decorator_factory: + class: '%ezpublish.image_alias.imagine.decorated_cache_resolver_factory.class%' + arguments: + - '@ezpublish.config.resolver' + - '@ezpublish.image_alias.imagine.cache_resolver_decorator.inner' + - '%liip_imagine.cache_resolver.proxy.class%' + + ezpublish.image_alias.imagine.cache_resolver_decorator: + class: '%liip_imagine.cache_resolver.proxy.class%' + factory: 'ezpublish.image_alias.imagine.cache_resolver_decorator_factory:createCacheResolver' + decorates: ezpublish.image_alias.imagine.cache_resolver + ezpublish.image_alias.imagine.cache.alias_generator_decorator: class: '%ezpublish.image_alias.imagine.cache.alias_generator_decorator.class%' arguments: From 9d44b532287921a16abe92ec660695555089893e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R?= Date: Thu, 20 Dec 2018 16:28:25 +0100 Subject: [PATCH 3/3] EZP-29899: Content loading can end up loading wrong version under concurrency (#2502) * EZP-29899: Content loading can end up loading wrong version under concurrency Under concurrency it's possible that current version number we get in content info is out of date by the time we ask for full content object. So change SPI to allow loading current version number directly. --- .../Core/Persistence/Cache/ContentHandler.php | 9 +++-- .../Cache/Tests/ContentHandlerTest.php | 36 +++++++++++++++++-- .../Persistence/Legacy/Content/Gateway.php | 4 +-- .../Content/Gateway/DoctrineDatabase.php | 32 +++-------------- .../Content/Gateway/ExceptionConversion.php | 12 ++----- .../Persistence/Legacy/Content/Handler.php | 23 ++++-------- .../Tests/Content/ContentHandlerTest.php | 20 ++++++----- .../_fixtures/extract_content_from_rows.php | 26 -------------- ...ct_content_from_rows_multiple_versions.php | 8 ----- eZ/Publish/Core/Repository/ContentService.php | 10 +----- eZ/Publish/Core/Repository/SearchService.php | 2 +- .../Tests/Service/Mock/ContentTest.php | 14 ++------ .../SPI/Persistence/Content/Handler.php | 10 +++--- 13 files changed, 75 insertions(+), 131 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php index 5a97d7d007a..21e6295b31b 100644 --- a/eZ/Publish/Core/Persistence/Cache/ContentHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/ContentHandler.php @@ -23,6 +23,7 @@ class ContentHandler extends AbstractHandler implements ContentHandlerInterface { const ALL_TRANSLATIONS_KEY = '0'; + const PUBLISHED_VERSION = 0; /** * @see \eZ\Publish\SPI\Persistence\Content\Handler::create @@ -62,10 +63,10 @@ public function copy($contentId, $versionNo = null, $newOwnerId = null) /** * @see \eZ\Publish\SPI\Persistence\Content\Handler::load */ - public function load($contentId, $version, array $translations = null) + public function load($contentId, $version = null, array $translations = null) { $translationsKey = empty($translations) ? self::ALL_TRANSLATIONS_KEY : implode('|', $translations); - $cache = $this->cache->getItem('content', $contentId, $version, $translationsKey); + $cache = $this->cache->getItem('content', $contentId, $version ?: self::PUBLISHED_VERSION, $translationsKey); $content = $cache->get(); if ($cache->isMiss()) { $this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $version, 'translations' => $translations)); @@ -152,6 +153,7 @@ public function setStatus($contentId, $status, $version) $return = $this->persistenceHandler->contentHandler()->setStatus($contentId, $status, $version); $this->cache->clear('content', $contentId, $version); + $this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); if ($status === VersionInfo::STATUS_PUBLISHED) { $this->cache->clear('content', 'info', $contentId); $this->cache->clear('content', 'info', 'remoteId'); @@ -172,6 +174,7 @@ public function updateMetadata($contentId, MetadataUpdateStruct $struct) $contentInfo = $this->persistenceHandler->contentHandler()->updateMetadata($contentId, $struct); $this->cache->clear('content', $contentId, $contentInfo->currentVersionNo); + $this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); $this->cache->clear('content', 'info', $contentId); if ($struct->remoteId) { @@ -192,6 +195,7 @@ public function updateContent($contentId, $versionNo, UpdateStruct $struct) $this->logger->logCall(__METHOD__, array('content' => $contentId, 'version' => $versionNo, 'struct' => $struct)); $content = $this->persistenceHandler->contentHandler()->updateContent($contentId, $versionNo, $struct); $this->cache->clear('content', $contentId, $versionNo); + $this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); $this->cache->clear('content', 'info', $contentId, 'versioninfo', $versionNo); return $content; @@ -239,6 +243,7 @@ public function deleteVersion($contentId, $versionNo) $return = $this->persistenceHandler->contentHandler()->deleteVersion($contentId, $versionNo); $this->cache->clear('content', $contentId, $versionNo); + $this->cache->clear('content', $contentId, self::PUBLISHED_VERSION); $this->cache->clear('content', 'info', $contentId); $this->cache->clear('content', 'info', 'remoteId'); $this->cache->clear('location', 'subtree'); diff --git a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php index bb811d37fb5..a8636cc025c 100644 --- a/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Cache/Tests/ContentHandlerTest.php @@ -416,6 +416,12 @@ public function testSetStatus() $this->cacheMock ->expects($this->at(1)) ->method('clear') + ->with('content', 2, ContentHandler::PUBLISHED_VERSION) + ->will($this->returnValue(null)); + + $this->cacheMock + ->expects($this->at(2)) + ->method('clear') ->with('content', 'info', 2, 'versioninfo', 1) ->will($this->returnValue(null)); @@ -451,6 +457,12 @@ public function testSetStatusPublished() $this->cacheMock ->expects($this->at(1)) ->method('clear') + ->with('content', 2, ContentHandler::PUBLISHED_VERSION) + ->will($this->returnValue(null)); + + $this->cacheMock + ->expects($this->at(2)) + ->method('clear') ->with('content', 'info', 2) ->will($this->returnValue(null)); @@ -486,11 +498,17 @@ public function testUpdateMetadata() $this->cacheMock ->expects($this->at(1)) ->method('clear') + ->with('content', 2, ContentHandler::PUBLISHED_VERSION) + ->will($this->returnValue(null)); + + $this->cacheMock + ->expects($this->at(2)) + ->method('clear') ->with('content', 'info', 2) ->willReturn(null); $this->cacheMock - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('clear') ->with('content', 'info', 'remoteId', 'o34') ->willReturn(null); @@ -541,6 +559,12 @@ public function testUpdateContent() $this->cacheMock ->expects($this->at(1)) ->method('clear') + ->with('content', 2, ContentHandler::PUBLISHED_VERSION) + ->will($this->returnValue(null)); + + $this->cacheMock + ->expects($this->at(2)) + ->method('clear') ->with('content', 'info', 2, 'versioninfo', 1) ->will($this->returnValue(null)); @@ -659,18 +683,24 @@ public function testDeleteVersion() $this->cacheMock ->expects($this->at(1)) ->method('clear') - ->with('content', 'info', 2) + ->with('content', 2, ContentHandler::PUBLISHED_VERSION) ->will($this->returnValue(null)); $this->cacheMock ->expects($this->at(2)) ->method('clear') - ->with('content', 'info', 'remoteId') + ->with('content', 'info', 2) ->will($this->returnValue(null)); $this->cacheMock ->expects($this->at(3)) ->method('clear') + ->with('content', 'info', 'remoteId') + ->will($this->returnValue(null)); + + $this->cacheMock + ->expects($this->at(4)) + ->method('clear') ->with('location', 'subtree') ->will($this->returnValue(null)); diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway.php b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway.php index a7c7944c891..f02bff9f7b5 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway.php @@ -144,12 +144,12 @@ abstract public function updateNonTranslatableField( * Returns an array with the relevant data. * * @param mixed $contentId - * @param mixed $version + * @param int|null $version Current version on null value. * @param string[] $translations * * @return array */ - abstract public function load($contentId, $version, array $translations = null); + abstract public function load($contentId, $version = null, array $translations = null); /** * Loads current version for a list of content objects. diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php index e6d5e3d15c6..5a0697cb81d 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php @@ -818,35 +818,11 @@ public function updateNonTranslatableField( } /** - * Loads data for a content object. - * - * Returns an array with the relevant data. - * - * @param mixed $contentId - * @param mixed $version - * @param string[] $translations - * - * @return array + * {@inheritdoc} */ - public function load($contentId, $version, array $translations = null) + public function load($contentId, $version = null, array $translations = null) { - $query = $this->queryBuilder->createFindQuery($translations); - $query->where( - $query->expr->lAnd( - $query->expr->eq( - $this->dbHandler->quoteColumn('id', 'ezcontentobject'), - $query->bindValue($contentId) - ), - $query->expr->eq( - $this->dbHandler->quoteColumn('version', 'ezcontentobject_version'), - $query->bindValue($version) - ) - ) - ); - $statement = $query->prepare(); - $statement->execute(); - - return $statement->fetchAll(\PDO::FETCH_ASSOC); + return $this->internalLoadContent([$contentId], $version, $translations); } /** @@ -861,7 +837,7 @@ public function loadContentList(array $contentIds, array $translations = null) * @see loadContentList() * * @param array $contentIds - * @param int $version + * @param int|null $version * @param string[]|null $translations * * @return array diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/ExceptionConversion.php b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/ExceptionConversion.php index 427bbe87cb2..ece3f044ed7 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/ExceptionConversion.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Gateway/ExceptionConversion.php @@ -255,17 +255,9 @@ public function updateNonTranslatableField( } /** - * Loads data for a content object. - * - * Returns an array with the relevant data. - * - * @param mixed $contentId - * @param mixed $version - * @param string[] $translations - * - * @return array + * {@inheritdoc} */ - public function load($contentId, $version, array $translations = null) + public function load($contentId, $version = null, array $translations = null) { try { return $this->innerGateway->load($contentId, $version, $translations); diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php b/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php index eb94bda1b33..7cc5c2c580d 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Handler.php @@ -303,23 +303,9 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId) } /** - * Returns the raw data of a content object identified by $id, in a struct. - * - * A version to load must be specified. If you want to load the current - * version of a content object use SearchHandler::findSingle() with the - * ContentId criterion. - * - * Optionally a translation filter may be specified. If specified only the - * translations with the listed language codes will be retrieved. If not, - * all translations will be retrieved. - * - * @param int|string $id - * @param int|string $version - * @param string[] $translations - * - * @return \eZ\Publish\SPI\Persistence\Content Content value object + * {@inheritdoc} */ - public function load($id, $version, array $translations = null) + public function load($id, $version = null, array $translations = null) { $rows = $this->contentGateway->load($id, $version, $translations); @@ -329,7 +315,10 @@ public function load($id, $version, array $translations = null) $contentObjects = $this->mapper->extractContentFromRows( $rows, - $this->contentGateway->loadVersionedNameData(array(array('id' => $id, 'version' => $version))) + $this->contentGateway->loadVersionedNameData([[ + 'id' => $id, + 'version' => $rows[0]['ezcontentobject_version_version'], + ]]) ); $content = $contentObjects[0]; diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ContentHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ContentHandlerTest.php index 31bc020e93f..072c1ae83c7 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ContentHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ContentHandlerTest.php @@ -246,15 +246,15 @@ public function testPublishFirstVersion() ) ); + $contentRows = [['ezcontentobject_version_version' => 1]]; + $gatewayMock->expects($this->once()) ->method('load') ->with( $this->equalTo(23), $this->equalTo(1), $this->equalTo(null) - )->will( - $this->returnValue(array(42)) - ); + )->willReturn($contentRows); $gatewayMock->expects($this->once()) ->method('loadVersionedNameData') @@ -266,7 +266,7 @@ public function testPublishFirstVersion() $mapperMock->expects($this->once()) ->method('extractContentFromRows') - ->with($this->equalTo(array(42)), $this->equalTo(array(22))) + ->with($this->equalTo($contentRows), $this->equalTo(array(22))) ->will($this->returnValue(array($this->getContentFixtureForDraft()))); $fieldHandlerMock->expects($this->once()) @@ -323,6 +323,8 @@ public function testPublish() ->method('setStatus') ->with(23, VersionInfo::STATUS_ARCHIVED, 1); + $contentRows = [['ezcontentobject_version_version' => 2]]; + $gatewayMock->expects($this->once()) ->method('load') ->with( @@ -330,7 +332,7 @@ public function testPublish() $this->equalTo(2), $this->equalTo(null) ) - ->will($this->returnValue(array(42))); + ->willReturn($contentRows); $gatewayMock->expects($this->once()) ->method('loadVersionedNameData') @@ -342,7 +344,7 @@ public function testPublish() $mapperMock->expects($this->once()) ->method('extractContentFromRows') - ->with($this->equalTo(array(42)), $this->equalTo(array(22))) + ->with($this->equalTo($contentRows), $this->equalTo(array(22))) ->will($this->returnValue(array($this->getContentFixtureForDraft()))); $fieldHandlerMock->expects($this->once()) @@ -474,6 +476,8 @@ public function testLoad() $mapperMock = $this->getMapperMock(); $fieldHandlerMock = $this->getFieldHandlerMock(); + $contentRows = [['ezcontentobject_version_version' => 2]]; + $gatewayMock->expects($this->once()) ->method('load') ->with( @@ -481,7 +485,7 @@ public function testLoad() $this->equalTo(2), $this->equalTo(array('eng-GB')) )->will( - $this->returnValue(array(42)) + $this->returnValue($contentRows) ); $gatewayMock->expects($this->once()) @@ -494,7 +498,7 @@ public function testLoad() $mapperMock->expects($this->once()) ->method('extractContentFromRows') - ->with($this->equalTo(array(42)), $this->equalTo(array(22))) + ->with($this->equalTo($contentRows), $this->equalTo(array(22))) ->will($this->returnValue(array($this->getContentFixtureForDraft()))); $fieldHandlerMock->expects($this->once()) diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows.php index f807c0896f0..0ceae5cd7c9 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows.php @@ -21,7 +21,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '4000', @@ -29,7 +28,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezsrrating', 'ezcontentobject_attribute_language_code' => 'eng-GB', 'ezcontentobject_attribute_language_id' => '4', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => '', @@ -57,7 +55,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1332', @@ -65,7 +62,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => 'New test article (2)', @@ -93,7 +89,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1333', @@ -101,7 +96,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => 'Something', @@ -129,7 +123,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1334', @@ -137,7 +130,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezauthor', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => ' @@ -167,7 +159,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1335', @@ -175,7 +166,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezrichtext', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '1045487555', 'ezcontentobject_attribute_data_text' => ' @@ -205,7 +195,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1336', @@ -213,7 +202,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezrichtext', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '1045487555', 'ezcontentobject_attribute_data_text' => ' @@ -243,7 +231,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1337', @@ -251,7 +238,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezboolean', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '1', 'ezcontentobject_attribute_data_text' => '', @@ -279,7 +265,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1338', @@ -287,7 +272,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezimage', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => ' @@ -317,7 +301,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1339', @@ -325,7 +308,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezrichtext', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '1045487555', 'ezcontentobject_attribute_data_text' => ' @@ -355,7 +337,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1340', @@ -363,7 +344,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezdatetime', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => '', @@ -391,7 +371,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1341', @@ -399,7 +378,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezdatetime', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => '', @@ -427,7 +405,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1342', @@ -435,7 +412,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezkeyword', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => '', @@ -463,7 +439,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1313061317', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '226', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '1343', @@ -471,7 +446,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezsrrating', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '2', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => null, 'ezcontentobject_attribute_data_text' => '', diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows_multiple_versions.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows_multiple_versions.php index 4c16fa3f470..12cd2218796 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows_multiple_versions.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/_fixtures/extract_content_from_rows_multiple_versions.php @@ -21,7 +21,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1033920737', 'ezcontentobject_version_status' => '3', - 'ezcontentobject_version_contentobject_id' => '11', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '22', @@ -29,7 +28,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '3', - 'ezcontentobject_attribute_version' => '1', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => 'Guest accounts', @@ -57,7 +55,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1033920737', 'ezcontentobject_version_status' => '3', - 'ezcontentobject_version_contentobject_id' => '11', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '23', @@ -65,7 +62,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '3', - 'ezcontentobject_attribute_version' => '1', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => '', @@ -93,7 +89,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1311154215', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '11', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '22', @@ -101,7 +96,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '3', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => 'Members', @@ -129,7 +123,6 @@ 'ezcontentobject_version_creator_id' => '14', 'ezcontentobject_version_created' => '1311154215', 'ezcontentobject_version_status' => '1', - 'ezcontentobject_version_contentobject_id' => '11', 'ezcontentobject_version_language_mask' => '3', 'ezcontentobject_version_initial_language_id' => '2', 'ezcontentobject_attribute_id' => '23', @@ -137,7 +130,6 @@ 'ezcontentobject_attribute_data_type_string' => 'ezstring', 'ezcontentobject_attribute_language_code' => 'eng-US', 'ezcontentobject_attribute_language_id' => '3', - 'ezcontentobject_attribute_version' => '2', 'ezcontentobject_attribute_data_float' => '0.0', 'ezcontentobject_attribute_data_int' => '0', 'ezcontentobject_attribute_data_text' => '', diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index 3f2f61f3ec8..5591533994b 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -376,18 +376,10 @@ public function internalLoadContent($id, array $languages = null, $versionNo = n $id = $spiContentInfo->id; } - // Get current version if $versionNo is not defined - if ($versionNo === null) { - if (!isset($spiContentInfo)) { - $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); - } - - $versionNo = $spiContentInfo->currentVersionNo; - } - $loadLanguages = $languages; $alwaysAvailableLanguageCode = null; // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true + // @todo Move use always available logic to SPI load methods, like done in location handler in 7.x if (!empty($loadLanguages) && $useAlwaysAvailable) { if (!isset($spiContentInfo)) { $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); diff --git a/eZ/Publish/Core/Repository/SearchService.php b/eZ/Publish/Core/Repository/SearchService.php index 52598b45ab8..0ef9cc36b5f 100644 --- a/eZ/Publish/Core/Repository/SearchService.php +++ b/eZ/Publish/Core/Repository/SearchService.php @@ -110,7 +110,7 @@ public function findContent(Query $query, array $languageFilter = array(), $filt $result = $this->internalFindContentInfo($query, $languageFilter, $filterOnUserPermissions); foreach ($result->searchHits as $key => $hit) { try { - // As we get ContentInfo from SPI, we need to load full content (avoids getting stale content data) + // As ContentInfo is from Search index, being async, we let Content Service figure out current version $hit->valueObject = $contentService->internalLoadContent( $hit->valueObject->id, (!empty($languageFilter['languages']) ? $languageFilter['languages'] : null), diff --git a/eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php b/eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php index a8c01c2023d..c3891334efb 100644 --- a/eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php +++ b/eZ/Publish/Core/Repository/Tests/Service/Mock/ContentTest.php @@ -510,26 +510,16 @@ public function testInternalLoadContent($id, $languages, $versionNo, $isRemoteId $contentService = $this->getPartlyMockedContentService(); /** @var \PHPUnit_Framework_MockObject_MockObject $contentHandler */ $contentHandler = $this->getPersistenceMock()->contentHandler(); - $realVersionNo = $versionNo; $realId = $id; if ($isRemoteId) { - $realVersionNo = $versionNo ?: 7; $realId = 123; - $spiContentInfo = new SPIContentInfo(array('currentVersionNo' => $realVersionNo, 'id' => $realId)); + $spiContentInfo = new SPIContentInfo(array('currentVersionNo' => $versionNo ?: 7, 'id' => $realId)); $contentHandler ->expects($this->once()) ->method('loadContentInfoByRemoteId') ->with($id) ->will($this->returnValue($spiContentInfo)); - } elseif ($versionNo === null) { - $realVersionNo = 7; - $spiContentInfo = new SPIContentInfo(array('currentVersionNo' => $realVersionNo)); - $contentHandler - ->expects($this->once()) - ->method('loadContentInfo') - ->with($id) - ->will($this->returnValue($spiContentInfo)); } elseif (!empty($languages) && $useAlwaysAvailable) { $spiContentInfo = new SPIContentInfo(array('alwaysAvailable' => false)); $contentHandler @@ -543,7 +533,7 @@ public function testInternalLoadContent($id, $languages, $versionNo, $isRemoteId $contentHandler ->expects($this->once()) ->method('load') - ->with($realId, $realVersionNo, $languages) + ->with($realId, $versionNo, $languages) ->will($this->returnValue($spiContent)); $content = $this->getMock('eZ\Publish\API\Repository\Values\Content\Content'); $this->getDomainMapperMock() diff --git a/eZ/Publish/SPI/Persistence/Content/Handler.php b/eZ/Publish/SPI/Persistence/Content/Handler.php index 3dfa107de57..4fbe1268c6c 100644 --- a/eZ/Publish/SPI/Persistence/Content/Handler.php +++ b/eZ/Publish/SPI/Persistence/Content/Handler.php @@ -51,21 +51,21 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId); /** * Returns the raw data of a content object identified by $id, in a struct. * - * A version to load must be specified. If you want to load the current - * version of a content object use SearchHandler::findSingle() with the - * ContentId criterion. + * If you want to load current version, $version number can be omitted to make sure + * you don't need to rely on search index (async) or having to load in two steps + * (first content info then content, risking changes in between to current version). * * Optionally a translation filter may be specified. If specified only the * translations with the listed language codes will be retrieved. If not, * all translations will be retrieved. * * @param int|string $id - * @param int|string $version + * @param int|null $version * @param string[] $translations * * @return \eZ\Publish\SPI\Persistence\Content Content value object */ - public function load($id, $version, array $translations = null); + public function load($id, $version = null, array $translations = null); /** * Return list of unique Content, with content id as key.