diff --git a/Classes/Controller/AbstractBaseController.php b/Classes/Controller/AbstractBaseController.php index 47facd2b88..c1850d0461 100644 --- a/Classes/Controller/AbstractBaseController.php +++ b/Classes/Controller/AbstractBaseController.php @@ -20,7 +20,6 @@ use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder; use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; use ApacheSolrForTypo3\Solr\Search; -use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager as SolrConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\System\Service\ConfigurationService; @@ -43,10 +42,8 @@ abstract class AbstractBaseController extends ActionController private ?ContentObjectRenderer $contentObjectRenderer = null; - private ?SolrConfigurationManager $solrConfigurationManager = null; - /** - * The configuration is private if you need it please get it from the SolrVariableProvider of RenderingContext. + * The configuration is private if you need it, please get it from the SolrVariableProvider of RenderingContext. */ protected ?TypoScriptConfiguration $typoScriptConfiguration = null; @@ -72,11 +69,6 @@ public function getContentObjectRenderer(): ?ContentObjectRenderer return $this->contentObjectRenderer; } - public function injectSolrConfigurationManager(SolrConfigurationManager $configurationManager): void - { - $this->solrConfigurationManager = $configurationManager; - } - public function setResetConfigurationBeforeInitialize(bool $resetConfigurationBeforeInitialize): void { $this->resetConfigurationBeforeInitialize = $resetConfigurationBeforeInitialize; @@ -91,7 +83,7 @@ protected function initializeAction(): void /** @var TypoScriptService $typoScriptService */ $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class); - // Merge settings done by typoscript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr) + // Merge settings done by TypoScript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr) $frameWorkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $pluginSettings = []; foreach (['search', 'settings', 'suggest', 'statistics', 'logging', 'general', 'solr', 'view'] as $key) { @@ -100,7 +92,11 @@ protected function initializeAction(): void } } - $this->typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptFromRequest($this->request); + $this->typoScriptConfiguration = GeneralUtility::makeInstance( + TypoScriptConfiguration::class, + $this->request->getAttribute('frontend.typoscript')->getSetupArray(), + $this->request->getAttribute('routing')->getPageId(), + ); if ($pluginSettings !== []) { $this->typoScriptConfiguration->mergeSolrConfiguration( $typoScriptService->convertPlainArrayToTypoScriptArray($pluginSettings), diff --git a/Classes/FrontendEnvironment.php b/Classes/FrontendEnvironment.php index 56fbec14ba..fa1776b1fd 100644 --- a/Classes/FrontendEnvironment.php +++ b/Classes/FrontendEnvironment.php @@ -19,7 +19,10 @@ use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; +use Doctrine\DBAL\Exception as DBALException; +use JsonException; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException; use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -37,6 +40,9 @@ class FrontendEnvironment implements SingletonInterface * Check whether the page record is within the configured allowed pages types(doktype) for indexing. * Uses TypoScript: plugin.tx_solr.index.queue..allowedPageTypes * + * @throws DBALException + * @throws JsonException + * @throws NoSuchCacheException * @throws SiteNotFoundException */ public function isAllowedPageType( @@ -74,6 +80,10 @@ public function isAllowedPageType( /** * Returns TypoScriptConfiguration for desired page ID and language id. * + * + * @throws DBALException + * @throws JsonException + * @throws NoSuchCacheException * @throws SiteNotFoundException * * @todo: check when to use $rootPageId and if it can be removed. diff --git a/Classes/FrontendEnvironment/Tsfe.php b/Classes/FrontendEnvironment/Tsfe.php index 9ae7c37b43..ba3e1d6d85 100644 --- a/Classes/FrontendEnvironment/Tsfe.php +++ b/Classes/FrontendEnvironment/Tsfe.php @@ -18,6 +18,7 @@ use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationPageResolver; use Doctrine\DBAL\Exception as DBALException; +use JsonException; use Throwable; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Context\Context; @@ -66,12 +67,11 @@ public function __construct(?SiteFinder $siteFinder = null) /** * Initializes the TSFE for a given page ID and language. * - * - * + * @throws AspectNotFoundException + * @throws DBALException * @throws Exception\Exception * @throws SiteNotFoundException - * @throws DBALException - * + * @throws JsonException * * @todo: Move whole caching stuff from this method and let return TSFE. */ @@ -179,6 +179,8 @@ protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPage * @throws SiteNotFoundException * @throws Exception\Exception * @throws DBALException + * @throws JsonException + * @throws AspectNotFoundException */ public function getTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?TypoScriptFrontendController { @@ -241,6 +243,8 @@ public function getTsfeByPageIdIgnoringLanguage(int $pageId): ?TypoScriptFronten * @throws SiteNotFoundException * @throws Exception\Exception * @throws DBALException + * @throws JsonException + * @throws AspectNotFoundException * * @noinspection PhpUnused */ @@ -258,13 +262,14 @@ public function getServerRequestForTsfeByPageIdAndLanguageId(int $pageId, int $l * @throws SiteNotFoundException * @throws Exception\Exception * @throws DBALException + * @throws JsonException + * @throws AspectNotFoundException */ protected function assureIsInitialized(int $pageId, int $language, ?int $rootPageId = null): void { $cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId); if (!array_key_exists($cacheIdentifier, $this->tsfeCache)) { $this->initializeTsfe($pageId, $language, $rootPageId); - return; } } diff --git a/Classes/System/Configuration/ConfigurationManager.php b/Classes/System/Configuration/ConfigurationManager.php index 0b75fb3382..2254fb8f3c 100644 --- a/Classes/System/Configuration/ConfigurationManager.php +++ b/Classes/System/Configuration/ConfigurationManager.php @@ -20,7 +20,10 @@ use Psr\Container\ContainerInterface; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ServerRequestInterface; +use RuntimeException; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\VisibilityAspect; use TYPO3\CMS\Core\Database\ConnectionPool; @@ -50,6 +53,7 @@ class ConfigurationManager implements SingletonInterface /** * @throws DBALException * @throws JsonException + * @throws NoSuchCacheException */ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoScriptConfiguration { @@ -68,7 +72,22 @@ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoS } } } - $fullConfig = $this->getCoreTypoScriptFrontendByRequest($request)->getSetupArray(); + try { + $fullConfig = $request->getAttribute('frontend.typoscript')?->getSetupArray(); + } catch (RuntimeException) { + $fullConfig = null; + } + if ($fullConfig === null) { + $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash'); + $cacheIdentifier = $pageId . '_' . ($request->getAttribute('language')?->getLanguageId() ?? 0); + if (!$cache->has($cacheIdentifier)) { + // Fallback to full TypoScript configuration + $fullConfig = $this->getCoreTypoScriptFrontendByRequest($request)->getSetupArray(); + $cache->set($cacheIdentifier, $fullConfig); + } else { + $fullConfig = $cache->get($cacheIdentifier); + } + } return GeneralUtility::makeInstance(TypoScriptConfiguration::class, $fullConfig, $pageId); } @@ -79,6 +98,7 @@ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoS * @throws DBALException * @throws JsonException * @throws SiteNotFoundException + * @throws NoSuchCacheException */ public function getTypoScriptConfiguration(?int $contextPageId = null, int $contextLanguageId = 0): TypoScriptConfiguration { @@ -129,6 +149,10 @@ public function getTypoScriptConfiguration(?int $contextPageId = null, int $cont */ public function getCoreTypoScriptFrontendByRequest(ServerRequestInterface $request): FrontendTypoScript { + if ($request->getAttribute('frontend.typoscript') instanceof FrontendTypoScript) { + return $request->getAttribute('frontend.typoscript'); + } + $typo3Site = $request->getAttribute('site'); $sysTemplateRows = $this->getSysTemplateRowsForAssociatedContextPageId($request);