From 06a3b9d57aeafed03e3edc75efc3b4fed5423f46 Mon Sep 17 00:00:00 2001 From: pawelpawlik Date: Mon, 24 Apr 2023 10:26:45 +0200 Subject: [PATCH 1/3] IBX-5385 add option content-type to reindex command --- .../Command/ReindexCommand.php | 15 ++++++++-- .../Search/Legacy/Content/IndexerGateway.php | 28 +++++++++++++++++++ .../SPI/Search/Content/IndexerGateway.php | 12 ++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php b/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php index ca3dc61c30..2394d24b07 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php +++ b/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php @@ -128,23 +128,28 @@ protected function configure() 'since', null, InputOption::VALUE_OPTIONAL, - 'Refresh changes since a time provided in any format understood by DateTime. Implies "no-purge", cannot be combined with "content-ids" or "subtree"' + 'Refresh changes since a time provided in any format understood by DateTime. Implies "no-purge", cannot be combined with "content-ids", "subtree" or "content-type"' )->addOption( 'content-ids', null, InputOption::VALUE_OPTIONAL, - 'Comma-separated list of content ID\'s to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since" or "subtree"' + 'Comma-separated list of content ID\'s to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree" or "content-type"' )->addOption( 'subtree', null, InputOption::VALUE_OPTIONAL, - 'Location ID whose subtree will be indexed (including the Location itself). Implies "no-purge", cannot be combined with "since" or "content-ids"' + 'Location ID whose subtree will be indexed (including the Location itself). Implies "no-purge", cannot be combined with "since", "content-ids" or "content-type"' )->addOption( 'processes', null, InputOption::VALUE_OPTIONAL, 'Number of child processes to run in parallel for iterations, if set to "auto" it will set to number of CPU cores -1, set to "1" or "0" to disable', 'auto' + )->addOption( + 'content-type', + null, + InputOption::VALUE_OPTIONAL, + 'Content type identifier to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree" or "content-ids"' )->setHelp( <<%command.name% indexes the current configured database in the configured search engine index. @@ -256,6 +261,10 @@ protected function indexIncrementally( $count = $this->gateway->countContentInSubtree($location->pathString); $generator = $this->gateway->getContentInSubtree($location->pathString, $iterationCount); $purge = false; + } elseif ($contentType = $input->getOption('content-type')) { + $count = $this->gateway->countContentWithContentTypeIdentifier($contentType); + $generator = $this->gateway->getContentWithContentTypeIdentifier($contentType, $iterationCount); + $purge = false; } else { $count = $this->gateway->countAllContent(); $generator = $this->gateway->getAllContent($iterationCount); diff --git a/eZ/Publish/Core/Search/Legacy/Content/IndexerGateway.php b/eZ/Publish/Core/Search/Legacy/Content/IndexerGateway.php index 5e44cf975b..e1a368c475 100644 --- a/eZ/Publish/Core/Search/Legacy/Content/IndexerGateway.php +++ b/eZ/Publish/Core/Search/Legacy/Content/IndexerGateway.php @@ -63,6 +63,22 @@ public function countContentInSubtree(string $locationPath): int return (int)$query->execute()->fetchOne(); } + public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator + { + $query = $this->buildQueryForContentWithContentTypeIdentifier($contentTypeIdentifier); + + yield from $this->fetchIteration($query->execute(), $iterationCount); + } + + public function countContentWithContentTypeIdentifier(string $contentTypeIdentifier): int + { + $query = $this->buildCountingQuery( + $this->buildQueryForContentWithContentTypeIdentifier($contentTypeIdentifier) + ); + + return (int)$query->execute()->fetchOne(); + } + public function getAllContent(int $iterationCount): Generator { $query = $this->buildQueryForAllContent(); @@ -101,6 +117,18 @@ private function buildQueryForContentInSubtree(string $locationPath): QueryBuild ->setParameter('path', $locationPath . '%', ParameterType::STRING); } + private function buildQueryForContentWithContentTypeIdentifier(string $contentTypeIdentifier): QueryBuilder + { + return $this->connection->createQueryBuilder() + ->select('DISTINCT c.id') + ->from('ezcontentobject', 'c') + ->innerJoin('c', 'ezcontentclass', 'cc', 'cc.id = c.contentclass_id') + ->where('c.status = :status') + ->andWhere('cc.identifier LIKE :identifier') + ->setParameter('status', ContentInfo::STATUS_PUBLISHED, ParameterType::INTEGER) + ->setParameter('identifier', $contentTypeIdentifier, ParameterType::STRING); + } + private function buildQueryForAllContent(): QueryBuilder { return $this->connection->createQueryBuilder() diff --git a/eZ/Publish/SPI/Search/Content/IndexerGateway.php b/eZ/Publish/SPI/Search/Content/IndexerGateway.php index 8f14ee3259..704345f9bf 100644 --- a/eZ/Publish/SPI/Search/Content/IndexerGateway.php +++ b/eZ/Publish/SPI/Search/Content/IndexerGateway.php @@ -40,6 +40,18 @@ public function getContentInSubtree(string $locationPath, int $iterationCount): */ public function countContentInSubtree(string $locationPath): int; + /** + * @throws \Doctrine\DBAL\Exception + * + * @return \Generator list of Content IDs for each iteration + */ + public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator; + + /** + * @throws \Doctrine\DBAL\Exception + */ + public function countContentWithContentTypeIdentifier(string $contentTypeIdentifier): int; + /** * @throws \Doctrine\DBAL\Exception * From 112b69d97f6231f9de007de14ca7e816416b6907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pawlik?= Date: Mon, 24 Apr 2023 12:14:29 +0200 Subject: [PATCH 2/3] Update eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed from VALUE_OPTIONAL to VALUE_REQUIRED for content-type option Co-authored-by: Paweł Niedzielski --- eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php b/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php index 2394d24b07..2ac658d8a7 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php +++ b/eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php @@ -148,7 +148,7 @@ protected function configure() )->addOption( 'content-type', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'Content type identifier to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree" or "content-ids"' )->setHelp( << Date: Wed, 26 Apr 2023 09:31:41 +0200 Subject: [PATCH 3/3] Update eZ/Publish/SPI/Search/Content/IndexerGateway.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relaxed constraints for getContentWithContentTypeIdentifier in IndexerGateway interface. Co-authored-by: Paweł Niedzielski --- eZ/Publish/SPI/Search/Content/IndexerGateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/SPI/Search/Content/IndexerGateway.php b/eZ/Publish/SPI/Search/Content/IndexerGateway.php index 704345f9bf..8321d4b992 100644 --- a/eZ/Publish/SPI/Search/Content/IndexerGateway.php +++ b/eZ/Publish/SPI/Search/Content/IndexerGateway.php @@ -43,9 +43,9 @@ public function countContentInSubtree(string $locationPath): int; /** * @throws \Doctrine\DBAL\Exception * - * @return \Generator list of Content IDs for each iteration + * @return iterable list of Content IDs for each iteration */ - public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator; + public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): iterable; /** * @throws \Doctrine\DBAL\Exception