From 72c299e628e222ace254331a2bdf0541470e3489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Fri, 28 Jun 2024 07:02:15 +0200 Subject: [PATCH] NGSTACK-842: extract resolving ContentType IDs to a separate method --- .../ScheduledVisibilityUpdateCommand.php | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/bundle/Command/ScheduledVisibilityUpdateCommand.php b/bundle/Command/ScheduledVisibilityUpdateCommand.php index ad34f3d..65eee6d 100644 --- a/bundle/Command/ScheduledVisibilityUpdateCommand.php +++ b/bundle/Command/ScheduledVisibilityUpdateCommand.php @@ -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'); @@ -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); @@ -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])) {