-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-5385: Add option content-type to reindex command #370
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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_REQUIRED, | ||
'Content type identifier to refresh (deleted/updated/added). Implies "no-purge", cannot be combined with "since", "subtree" or "content-ids"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note, outside of the scope of this PR: |
||
)->setHelp( | ||
<<<EOT | ||
The command <info>%command.name%</info> 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; | ||
Comment on lines
+265
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given you can't add anything to that Gateway without breaking BC promise (see previous comment), I think better solution would be to either use Repository Filtering ( |
||
} else { | ||
$count = $this->gateway->countAllContent(); | ||
$generator = $this->gateway->getAllContent($iterationCount); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,6 +63,22 @@ public function countContentInSubtree(string $locationPath): int | |||||
return (int)$query->execute()->fetchOne(); | ||||||
} | ||||||
|
||||||
public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue reported is relevant. Narrowing down of return type is available for PHP 7.4+, and this version of ezplatform-kernel supports PHP 7.3, which means you cannot use this feature.
Suggested change
|
||||||
{ | ||||||
$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() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,18 @@ public function getContentInSubtree(string $locationPath, int $iterationCount): | |
*/ | ||
public function countContentInSubtree(string $locationPath): int; | ||
|
||
/** | ||
* @throws \Doctrine\DBAL\Exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as the indexing is concerned, I'm not sure if we want to declare that this can throw this exception. The fact that we are using Doctrine is irrelevant for indexing (at least for the interface). @alongosz ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You're right. On SPI level we can throw SPI or API exceptions. |
||
* | ||
* @return \Generator list of Content IDs for each iteration | ||
*/ | ||
public function getContentWithContentTypeIdentifier(string $contentTypeIdentifier, int $iterationCount): Generator; | ||
papcio122 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @throws \Doctrine\DBAL\Exception | ||
*/ | ||
public function countContentWithContentTypeIdentifier(string $contentTypeIdentifier): int; | ||
|
||
/** | ||
* @throws \Doctrine\DBAL\Exception | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Punctuation: use Oxford comma here and in the other related places please