Skip to content

Commit 9cd2ddc

Browse files
committed
[BUGFIX] Don't re-instantiate TypoScript in FE/Search context
Fixes: #4340, #4419
1 parent 7aea09a commit 9cd2ddc

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

Classes/Controller/AbstractBaseController.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder;
2121
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
2222
use ApacheSolrForTypo3\Solr\Search;
23-
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager as SolrConfigurationManager;
2423
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
2524
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
2625
use ApacheSolrForTypo3\Solr\System\Service\ConfigurationService;
@@ -43,10 +42,8 @@ abstract class AbstractBaseController extends ActionController
4342

4443
private ?ContentObjectRenderer $contentObjectRenderer = null;
4544

46-
private ?SolrConfigurationManager $solrConfigurationManager = null;
47-
4845
/**
49-
* The configuration is private if you need it please get it from the SolrVariableProvider of RenderingContext.
46+
* The configuration is private if you need it, please get it from the SolrVariableProvider of RenderingContext.
5047
*/
5148
protected ?TypoScriptConfiguration $typoScriptConfiguration = null;
5249

@@ -72,11 +69,6 @@ public function getContentObjectRenderer(): ?ContentObjectRenderer
7269
return $this->contentObjectRenderer;
7370
}
7471

75-
public function injectSolrConfigurationManager(SolrConfigurationManager $configurationManager): void
76-
{
77-
$this->solrConfigurationManager = $configurationManager;
78-
}
79-
8072
public function setResetConfigurationBeforeInitialize(bool $resetConfigurationBeforeInitialize): void
8173
{
8274
$this->resetConfigurationBeforeInitialize = $resetConfigurationBeforeInitialize;
@@ -91,7 +83,7 @@ protected function initializeAction(): void
9183
/** @var TypoScriptService $typoScriptService */
9284
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
9385

94-
// Merge settings done by typoscript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr)
86+
// Merge settings done by TypoScript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr)
9587
$frameWorkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
9688
$pluginSettings = [];
9789
foreach (['search', 'settings', 'suggest', 'statistics', 'logging', 'general', 'solr', 'view'] as $key) {
@@ -100,7 +92,11 @@ protected function initializeAction(): void
10092
}
10193
}
10294

103-
$this->typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptFromRequest($this->request);
95+
$this->typoScriptConfiguration = GeneralUtility::makeInstance(
96+
TypoScriptConfiguration::class,
97+
$this->request->getAttribute('frontend.typoscript')->getSetupArray(),
98+
$this->request->getAttribute('routing')->getPageId(),
99+
);
104100
if ($pluginSettings !== []) {
105101
$this->typoScriptConfiguration->mergeSolrConfiguration(
106102
$typoScriptService->convertPlainArrayToTypoScriptArray($pluginSettings),

Classes/FrontendEnvironment.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
2121
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
22+
use Doctrine\DBAL\Exception as DBALException;
23+
use JsonException;
2224
use TYPO3\CMS\Backend\Utility\BackendUtility;
25+
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
2326
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
2427
use TYPO3\CMS\Core\SingletonInterface;
2528
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -37,6 +40,9 @@ class FrontendEnvironment implements SingletonInterface
3740
* Check whether the page record is within the configured allowed pages types(doktype) for indexing.
3841
* Uses TypoScript: plugin.tx_solr.index.queue.<queue name>.allowedPageTypes
3942
*
43+
* @throws DBALException
44+
* @throws JsonException
45+
* @throws NoSuchCacheException
4046
* @throws SiteNotFoundException
4147
*/
4248
public function isAllowedPageType(
@@ -74,6 +80,10 @@ public function isAllowedPageType(
7480
/**
7581
* Returns TypoScriptConfiguration for desired page ID and language id.
7682
*
83+
*
84+
* @throws DBALException
85+
* @throws JsonException
86+
* @throws NoSuchCacheException
7787
* @throws SiteNotFoundException
7888
*
7989
* @todo: check when to use $rootPageId and if it can be removed.

Classes/FrontendEnvironment/Tsfe.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
1919
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationPageResolver;
2020
use Doctrine\DBAL\Exception as DBALException;
21+
use JsonException;
2122
use Throwable;
2223
use TYPO3\CMS\Backend\Utility\BackendUtility;
2324
use TYPO3\CMS\Core\Context\Context;
@@ -66,12 +67,11 @@ public function __construct(?SiteFinder $siteFinder = null)
6667
/**
6768
* Initializes the TSFE for a given page ID and language.
6869
*
69-
*
70-
*
70+
* @throws AspectNotFoundException
71+
* @throws DBALException
7172
* @throws Exception\Exception
7273
* @throws SiteNotFoundException
73-
* @throws DBALException
74-
*
74+
* @throws JsonException
7575
*
7676
* @todo: Move whole caching stuff from this method and let return TSFE.
7777
*/
@@ -179,6 +179,8 @@ protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPage
179179
* @throws SiteNotFoundException
180180
* @throws Exception\Exception
181181
* @throws DBALException
182+
* @throws JsonException
183+
* @throws AspectNotFoundException
182184
*/
183185
public function getTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?TypoScriptFrontendController
184186
{
@@ -241,6 +243,8 @@ public function getTsfeByPageIdIgnoringLanguage(int $pageId): ?TypoScriptFronten
241243
* @throws SiteNotFoundException
242244
* @throws Exception\Exception
243245
* @throws DBALException
246+
* @throws JsonException
247+
* @throws AspectNotFoundException
244248
*
245249
* @noinspection PhpUnused
246250
*/
@@ -258,13 +262,14 @@ public function getServerRequestForTsfeByPageIdAndLanguageId(int $pageId, int $l
258262
* @throws SiteNotFoundException
259263
* @throws Exception\Exception
260264
* @throws DBALException
265+
* @throws JsonException
266+
* @throws AspectNotFoundException
261267
*/
262268
protected function assureIsInitialized(int $pageId, int $language, ?int $rootPageId = null): void
263269
{
264270
$cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId);
265271
if (!array_key_exists($cacheIdentifier, $this->tsfeCache)) {
266272
$this->initializeTsfe($pageId, $language, $rootPageId);
267-
return;
268273
}
269274
}
270275

Classes/System/Configuration/ConfigurationManager.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
use Psr\Container\ContainerInterface;
2121
use Psr\EventDispatcher\EventDispatcherInterface;
2222
use Psr\Http\Message\ServerRequestInterface;
23+
use RuntimeException;
2324
use TYPO3\CMS\Backend\Utility\BackendUtility;
25+
use TYPO3\CMS\Core\Cache\CacheManager;
26+
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
2427
use TYPO3\CMS\Core\Context\Context;
2528
use TYPO3\CMS\Core\Context\VisibilityAspect;
2629
use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -50,6 +53,7 @@ class ConfigurationManager implements SingletonInterface
5053
/**
5154
* @throws DBALException
5255
* @throws JsonException
56+
* @throws NoSuchCacheException
5357
*/
5458
public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoScriptConfiguration
5559
{
@@ -68,7 +72,22 @@ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoS
6872
}
6973
}
7074
}
71-
$fullConfig = $this->getCoreTypoScriptFrontendByRequest($request)->getSetupArray();
75+
try {
76+
$fullConfig = $request->getAttribute('frontend.typoscript')?->getSetupArray();
77+
} catch (RuntimeException) {
78+
$fullConfig = null;
79+
}
80+
if ($fullConfig === null) {
81+
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
82+
$cacheIdentifier = $pageId . '_' . ($request->getAttribute('language')?->getLanguageId() ?? 0);
83+
if (!$cache->has($cacheIdentifier)) {
84+
// Fallback to full TypoScript configuration
85+
$fullConfig = $this->getCoreTypoScriptFrontendByRequest($request)->getSetupArray();
86+
$cache->set($cacheIdentifier, $fullConfig);
87+
} else {
88+
$fullConfig = $cache->get($cacheIdentifier);
89+
}
90+
}
7291
return GeneralUtility::makeInstance(TypoScriptConfiguration::class, $fullConfig, $pageId);
7392
}
7493

@@ -79,6 +98,7 @@ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoS
7998
* @throws DBALException
8099
* @throws JsonException
81100
* @throws SiteNotFoundException
101+
* @throws NoSuchCacheException
82102
*/
83103
public function getTypoScriptConfiguration(?int $contextPageId = null, int $contextLanguageId = 0): TypoScriptConfiguration
84104
{
@@ -129,6 +149,10 @@ public function getTypoScriptConfiguration(?int $contextPageId = null, int $cont
129149
*/
130150
public function getCoreTypoScriptFrontendByRequest(ServerRequestInterface $request): FrontendTypoScript
131151
{
152+
if ($request->getAttribute('frontend.typoscript') instanceof FrontendTypoScript) {
153+
return $request->getAttribute('frontend.typoscript');
154+
}
155+
132156
$typo3Site = $request->getAttribute('site');
133157
$sysTemplateRows = $this->getSysTemplateRowsForAssociatedContextPageId($request);
134158

0 commit comments

Comments
 (0)