Skip to content
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

[BUGFIX] Fix EXT:solr route enhancer #3742

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[BUGFIX] Fix EXT:solr route enhancer
SolrRoutingMiddleware was limited to indexing processs, but
as the SolrFacetMaskAndCombineEnhancer requires this middleware
to add the required parameters from the route path, this limitation
causes that the route enhancer is ineffective.

This commit fixes this issue by reenabling the middleware for
frontend requests and also ensures that route paths can be resolved
correctly if PageTypeSuffix enhancer is active.

Relates: #3202
Resolves: #3741
  • Loading branch information
dkd-friedrich committed Aug 2, 2023
commit b46c926ba2f9fdd786da76566aef8cabcffbb9a0
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public function __invoke(BeforeCachedVariablesAreProcessedEvent $event): void

$this->routingService = GeneralUtility::makeInstance(
RoutingService::class,
$enhancerConfiguration['solr'],
$enhancerConfiguration['solr'] ?? [],
(string)$enhancerConfiguration['extensionKey']
);

Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public function __invoke(AfterUriIsProcessedEvent $event): void
/** @var RoutingService $routingService */
$routingService = GeneralUtility::makeInstance(
RoutingService::class,
$configuration['solr'],
$configuration['solr'] ?? [],
(string)$configuration['extensionKey']
);

71 changes: 34 additions & 37 deletions Classes/Middleware/SolrRoutingMiddleware.php
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ public function injectRoutingService(RoutingService $routingService): void
*/
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);
}

@@ -128,7 +128,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']
@@ -175,7 +175,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;
}
@@ -287,45 +287,42 @@ protected function retrievePageInformation(UriInterface $uri, Site $site): array
$path,
$this->language
);

if (empty($items)) {
$this->logger
->
error(
vsprintf(
'Could not determine page for slug "%1$s" and language "%2$s". Given path "%3$s"',
[
$path,
$this->language->getLocale()->getLanguageCode(),
$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
->
error(
vsprintf(
'Could not resolve page by path "%1$s" and language "%2$s".',
[
$uri->getPath(),
$this->language->getLocale()->getLanguageCode(),
]
)
);
} 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;
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ protected function getRoutingService(): RoutingService
/** @var RoutingService $routingService */
$routingService = GeneralUtility::makeInstance(
RoutingService::class,
$this->configuration['solr'],
$this->configuration['solr'] ?? [],
(string)$this->configuration['extensionKey']
);
return $routingService->withPathArguments($this->configuration['_arguments']);
27 changes: 24 additions & 3 deletions Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -81,9 +81,6 @@ 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()
@@ -132,4 +129,28 @@ public function missingEnhancerHasNoEffectTest(): void
$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
);
}
}