Skip to content

Commit

Permalink
[BUGFIX:BP:11.5] Fix EXT:solr route enhancer
Browse files Browse the repository at this point in the history
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.

Ports: TYPO3-Solr#3742
Relates: TYPO3-Solr#3202
Resolves: TYPO3-Solr#3741
  • Loading branch information
dkd-friedrich committed Aug 2, 2023
1 parent d095058 commit 3362baf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __invoke(BeforeProcessCachedVariablesEvent $event): void

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);

Expand Down
71 changes: 34 additions & 37 deletions Classes/Middleware/SolrRoutingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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'] ?? ''
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down

0 comments on commit 3362baf

Please sign in to comment.