Skip to content

Commit

Permalink
!!![TASK] Configuration option enableRouteEnhancer
Browse files Browse the repository at this point in the history
EXT:solr offers the possibility to create speaking URLs for Solr
facets, but as this feature requires additional configuration and
costly processing this feature is now disabled by default.

If you've already used the route enhancer you must set option
"enableRouteEnhancer":
$TYPO3_CONF_VARS['EXTENSIONS']['solr']['enableRouteEnhancer']

Resolves: #3810
  • Loading branch information
dkd-friedrich authored and dkd-kaehm committed Oct 10, 2023
1 parent 3c402b4 commit 529b21a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
19 changes: 17 additions & 2 deletions Classes/Routing/Enhancer/SolrFacetMaskAndCombineEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
namespace ApacheSolrForTypo3\Solr\Routing\Enhancer;

use ApacheSolrForTypo3\Solr\Routing\RoutingService;
use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\Utility\RoutingUtility;
use TYPO3\CMS\Core\Routing\Enhancer\AbstractEnhancer;
use TYPO3\CMS\Core\Routing\Enhancer\RoutingEnhancerInterface;
Expand All @@ -25,6 +27,7 @@

class SolrFacetMaskAndCombineEnhancer extends AbstractEnhancer implements RoutingEnhancerInterface, SolrRouteEnhancerInterface
{
protected bool $isEnabled;
protected array $configuration;

protected string $namespace;
Expand All @@ -33,13 +36,25 @@ public function __construct(array $configuration)
{
$this->configuration = $configuration;
$this->namespace = $this->configuration['extensionKey'] ?? 'tx_solr';

$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$this->isEnabled = $extensionConfiguration->getIsRouteEnhancerEnabled();
}

/**
* {@inheritdoc}
*/
public function enhanceForMatching(RouteCollection $collection): void
{
if (!$this->isEnabled) {
$logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
$logger->error(
'Solr routing enhancer deactivated in Solr configuration,'
. ' set enableRouteEnhancer or remove SolrFacetMaskAndCombineEnhancer'
);
return;
}

/** @var Route $defaultPageRoute */
$defaultPageRoute = $collection->get('default');
$variant = $this->getVariant($defaultPageRoute, $this->configuration);
Expand Down Expand Up @@ -79,8 +94,8 @@ protected function getVariant(Route $defaultPageRoute, array $configuration): Ro
*/
public function enhanceForGeneration(RouteCollection $collection, array $parameters): void
{
// No parameter for this namespace given, so this route does not fit the requirements
if (!is_array($parameters[$this->namespace] ?? null)) {
// Disabled or no parameter for this namespace given, so this route does not fit the requirements
if (!$this->isEnabled || !is_array($parameters[$this->namespace] ?? null)) {
return;
}
/** @var Route $defaultPageRoute */
Expand Down
8 changes: 8 additions & 0 deletions Classes/System/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public function getMonitoringType(): int
return (int)$this->getConfigurationOrDefaultValue('monitoringType', 0);
}

/**
* Get configuration for enableRouteEnhancer
*/
public function getIsRouteEnhancerEnabled(): bool
{
return (bool)$this->getConfigurationOrDefaultValue('enableRouteEnhancer', false);
}

protected function getConfigurationOrDefaultValue(string $key, mixed $defaultValue = null): mixed
{
return $this->configuration[$key] ?? $defaultValue;
Expand Down
34 changes: 21 additions & 13 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?php

/** @noinspection PhpFullyQualifiedNameUsageInspection */
return [
'frontend' => [
'apache-solr-for-typo3/page-indexer-initialization' => [
'target' => \ApacheSolrForTypo3\Solr\Middleware\PageIndexerInitialization::class,
'before' => ['typo3/cms-frontend/tsfe'],
'after' => ['typo3/cms-core/normalized-params-attribute'],
],
'apache-solr-for-typo3/solr-route-enhancer' => [
'target' => \ApacheSolrForTypo3\Solr\Middleware\SolrRoutingMiddleware::class,
'before' => [
'typo3/cms-frontend/site',
],
],
$requestMiddlewares = [
'apache-solr-for-typo3/page-indexer-initialization' => [
'target' => \ApacheSolrForTypo3\Solr\Middleware\PageIndexerInitialization::class,
'before' => ['typo3/cms-frontend/tsfe'],
'after' => ['typo3/cms-core/normalized-params-attribute'],
],
];

$extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration::class
);
if ($extensionConfiguration->getIsRouteEnhancerEnabled()) {
$requestMiddlewares['apache-solr-for-typo3/solr-route-enhancer'] = [
'target' => \ApacheSolrForTypo3\Solr\Middleware\SolrRoutingMiddleware::class,
'before' => [
'typo3/cms-frontend/site',
],
];
}

return [
'frontend' => $requestMiddlewares,
];
13 changes: 12 additions & 1 deletion Documentation/Releases/solr-release-12-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,22 @@ If you've used this class or the SolrConnection directly, you have to adapt your
- use \Solarium\Core\Client\Endpoint instead of \ApacheSolrForTypo3\Solr\System\Solr\Node
- call \ApacheSolrForTypo3\Solr\System\Solr\SolrConnection->getEndpoint() instead of \ApacheSolrForTypo3\Solr\System\Solr\SolrConnection\getNode(),
method will return Solarium Endpoint
- Node could be converted to string to get the core base URI, getCoreBaseUri() can be used instead.
- Node could be converted to string to get the core base URI, getCoreBaseUri() can be used instead.

Note: With dropping the Node implementation we also dropped the backwards compatibility that allows to define the Solr path segment "/solr" within "solr_path_read" or "solr_path_write". Be sure your configuration doesn't contain this path segment!


!!! Solr route enhancer disabled by default
-------------------------------------------

EXT:solr offers the possibility to create speaking URLs for Solr facets, but as this feature requires additional configuration and costly processing this feature is now disabled by default.

If you've already used the route enhancer you must set option "enableRouteEnhancer":

:php:`$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['solr']['enableRouteEnhancer']`



Frontend Helper Changes
-----------------------

Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<file source-language="en" datatype="plaintext" original="EXT:solr/Resources/Private/Language/locallang_be.xlf" date="2021-12-15T13:10:00Z" product-name="solr">
<header/>
<body>
<trans-unit id="extConf.category.routeEnhancer" resname="extConf.category.routeEnhancer">
<source>Route Enhancer</source>
</trans-unit>
<trans-unit id="extConf.monitoringType" xml:space="preserve">
<source>Monitoring: Define how data updates should be monitored</source>
</trans-unit>
Expand All @@ -15,6 +18,9 @@
<trans-unit id="extConf.monitoringType.I.2" xml:space="preserve">
<source>No monitoring at all</source>
</trans-unit>
<trans-unit id="extConf.enableRouteEnhancer" xml:space="preserve">
<source>Enable route enhancer: If you want to use speaking URLs for Solr facets, you have to enable this option, otherwise the required Middleware is not active and the route enhancer has no effect.</source>
</trans-unit>

<trans-unit id="task.eventQueueWorkerTask.title" xml:space="preserve">
<source>Event Queue Worker</source>
Expand Down
7 changes: 6 additions & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# customcategory=Routes=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.category.routeEnhancer

# cat=basic/enable/8; type=string; label=A list of white listed plugin namespaces (Required by cacheHash/excludedParameters and plugin flex form): Note: This list only is available in Plugin -> Options -> Plugin Namespace
pluginNamespaces = tx_solr

Expand All @@ -17,4 +19,7 @@ useConfigurationMonitorTables =
allowSelfSignedCertificates = 0

# cat=basic/enable/50; type=options[LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.monitoringType.I.0=0,LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.monitoringType.I.1=1,LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.monitoringType.I.2=2]; label=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.monitoringType
monitoringType = 0
monitoringType = 0

# cat=Routes/enable/10; type=boolean; label=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.enableRouteEnhancer
enableRouteEnhancer = 0

0 comments on commit 529b21a

Please sign in to comment.