Skip to content

Commit

Permalink
NGSTACK-842: extract resolving ContentType IDs to a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Jun 28, 2024
1 parent e2a2ae5 commit 72c299e
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions bundle/Command/ScheduledVisibilityUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$since = $input->getOption('since');
$since = $since === null ? $since : (int) $since;
$pager = $this->getPager($allContentTypes, $allowedContentTypes, $since);
$pager = $this->getPager($since);

if ($pager->getNbResults() === 0) {
$this->style->info('No content found');
Expand Down Expand Up @@ -234,26 +234,9 @@ private function applyContentTypes(QueryBuilder $query, array $contentTypeIds):
;
}

private function getPager(bool $allContentTypes, array $allowedContentTypes, ?int $since): Pagerfanta
private function getPager(?int $since): Pagerfanta
{
$contentTypeIds = [];
if (!$allContentTypes && count($allowedContentTypes) > 0) {
foreach ($allowedContentTypes as $allowedContentType) {
try {
$contentTypeIds[] = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($allowedContentType)->id;
} catch (NotFoundException $exception) {
$this->logger->error(
sprintf(
"Content type with identifier '%s' does not exist: %s",
$allowedContentType,
$exception->getMessage(),
),
);

continue;
}
}
}
$contentTypeIds = $this->getContentTypeIds();

$queryBuilder = $this->getQueryBuilder($since, $contentTypeIds);

Expand All @@ -271,6 +254,39 @@ private function getPager(bool $allContentTypes, array $allowedContentTypes, ?in
return new Pagerfanta(new QueryAdapter($queryBuilder, $countQueryBuilderModifier));
}

/**
* @return int[]
*/
private function getContentTypeIds(): array
{
$allContentTypes = $this->configurationService->isAllContentTypes();
$allowedContentTypes = $this->configurationService->getAllowedContentTypes();

if ($allContentTypes || count($allowedContentTypes) === 0) {
return [];
}

$contentTypeIds = [];

foreach ($allowedContentTypes as $allowedContentType) {
try {
$contentTypeIds[] = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($allowedContentType)->id;
} catch (NotFoundException $exception) {
$this->logger->error(
sprintf(
"Content type with identifier '%s' does not exist: %s",
$allowedContentType,
$exception->getMessage(),
),
);

continue;
}
}

return $contentTypeIds;
}

private function loadLanguage(int $id): Language
{
if (!isset($this->languageCache[$id])) {
Expand Down

0 comments on commit 72c299e

Please sign in to comment.