diff --git a/Classes/EventListener/EnhancedRouting/CachedPathVariableModifier.php b/Classes/EventListener/EnhancedRouting/CachedPathVariableModifier.php index cb8ef5c981..afc472bb0e 100644 --- a/Classes/EventListener/EnhancedRouting/CachedPathVariableModifier.php +++ b/Classes/EventListener/EnhancedRouting/CachedPathVariableModifier.php @@ -52,7 +52,7 @@ public function __invoke(BeforeProcessCachedVariablesEvent $event): void $this->routingService = GeneralUtility::makeInstance( RoutingService::class, - $enhancerConfiguration['solr'], + $enhancerConfiguration['solr'] ?? [], (string)$enhancerConfiguration['extensionKey'] ); diff --git a/Classes/EventListener/EnhancedRouting/PostEnhancedUriProcessor.php b/Classes/EventListener/EnhancedRouting/PostEnhancedUriProcessor.php index 28eaadfca7..3baf57f8a5 100644 --- a/Classes/EventListener/EnhancedRouting/PostEnhancedUriProcessor.php +++ b/Classes/EventListener/EnhancedRouting/PostEnhancedUriProcessor.php @@ -38,7 +38,7 @@ public function __invoke(PostProcessUriEvent $event): void /* @var RoutingService $routingService */ $routingService = GeneralUtility::makeInstance( RoutingService::class, - $configuration['solr'], + $configuration['solr'] ?? [], (string)$configuration['extensionKey'] ); diff --git a/Classes/Middleware/SolrRoutingMiddleware.php b/Classes/Middleware/SolrRoutingMiddleware.php index 37625d4971..edb5fe4477 100644 --- a/Classes/Middleware/SolrRoutingMiddleware.php +++ b/Classes/Middleware/SolrRoutingMiddleware.php @@ -101,7 +101,7 @@ public function injectRoutingService(RoutingService $routingService) */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - if (!$request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) { + if ($request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) { return $handler->handle($request); } @@ -145,7 +145,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface /* * Take slug path segments and argument from incoming URI */ - [$slug, $parameters] = $this->extractParametersFromUriPath( + [, $parameters] = $this->extractParametersFromUriPath( $request->getUri(), $enhancerConfiguration['routePath'], $page['slug'] ?? '' @@ -195,7 +195,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface */ protected function configure(array $enhancerConfiguration): void { - $this->settings = $enhancerConfiguration['solr']; + $this->settings = $enhancerConfiguration['solr'] ?? []; $this->namespace = $enhancerConfiguration['extensionKey'] ?? $this->namespace; $this->routingService = null; } @@ -320,45 +320,42 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array $path, $this->language ); + if (empty($items)) { - $this->logger - ->/** @scrutinizer ignore-call */ - error( - vsprintf( - 'Could not determine page for slug "%1$s" and language "%2$s". Given path "%3$s"', - [ - $path, - $this->language->getTwoLetterIsoCode(), - $uri->getPath(), - ] - ) - ); + if (empty($path)) { + $message = 'Could not resolve page by path "%3$s" and language "%2$s".'; + } else { + $message = 'Could not determine page for slug "%1$s" and language "%2$s". Given path "%3$s"'; + } + + $this->logger->error( + sprintf( + $message, + $path, + $this->language->getTwoLetterIsoCode(), + $uri->getPath() + ) + ); $scan = false; - } elseif (empty($path)) { - $this->logger - ->/** @scrutinizer ignore-call */ - error( - vsprintf( - 'Could not resolve page by path "%1$s" and language "%2$s".', - [ - $uri->getPath(), - $this->language->getTwoLetterIsoCode(), - ] - ) - ); + } elseif (empty($path) && count($items) === 1) { + $page = $items[0]; + $this->logger->info( + sprintf( + 'Path "%1$s" -> slug "%2$s"', + $uri->getPath(), + $page['slug'] + ) + ); $scan = false; } else { foreach ($items as $item) { - $this->logger - ->info( - vsprintf( - 'Path "%1$s" -> slug "%2$s"', - [ - $path, - $item['slug'], - ] - ) - ); + $this->logger->info( + sprintf( + 'Path "%1$s" -> slug "%2$s"', + $path, + $item['slug'] + ) + ); if ($item['slug'] === $path) { $page = $item; diff --git a/Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php b/Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php index d5111f3480..1a0ae38ed5 100644 --- a/Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php +++ b/Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php @@ -326,7 +326,7 @@ protected function getRoutingService(): RoutingService { return GeneralUtility::makeInstance( RoutingService::class, - $this->configuration['solr'], + $this->configuration['solr'] ?? [], (string)$this->configuration['extensionKey'] )->withPathArguments($this->configuration['_arguments']); } diff --git a/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php b/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php index 13d28f0ccf..386d2e5fab 100644 --- a/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php +++ b/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php @@ -87,14 +87,11 @@ public function getRequest(): ServerRequestInterface * @test * @covers \ApacheSolrForTypo3\Solr\Middleware\SolrRoutingMiddleware::process */ - public function missingEnhancerHasNoEffectTest() + public function missingEnhancerHasNoEffectTest(): void { $serverRequest = new ServerRequest( 'GET', 'https://domain.example/facet/bar,buz,foo', - [ - PageIndexerRequest::SOLR_INDEX_HEADER => '1', - ] ); $siteMatcherMock = $this->getMockBuilder(SiteMatcher::class) ->disableOriginalConstructor() @@ -144,4 +141,28 @@ public function missingEnhancerHasNoEffectTest() $uri->getPath() ); } + + /** + * @test + * @covers \ApacheSolrForTypo3\Solr\Middleware\SolrRoutingMiddleware::process + */ + public function enhancerInactiveDuringIndexingTest(): void + { + $serverRequest = new ServerRequest( + 'GET', + 'https://domain.example/', + [ + PageIndexerRequest::SOLR_INDEX_HEADER => '1', + ] + ); + + $this->routingServiceMock->expects(self::never())->method('getSiteMatcher'); + $solrRoutingMiddleware = new SolrRoutingMiddleware(); + $solrRoutingMiddleware->setLogger(new NullLogger()); + $solrRoutingMiddleware->injectRoutingService($this->routingServiceMock); + $solrRoutingMiddleware->process( + $serverRequest, + $this->responseOutputHandler + ); + } }