diff --git a/Classes/Domain/Site/SiteRepository.php b/Classes/Domain/Site/SiteRepository.php index f8ce346fd5..d4761f5375 100644 --- a/Classes/Domain/Site/SiteRepository.php +++ b/Classes/Domain/Site/SiteRepository.php @@ -20,7 +20,6 @@ use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException; use ApacheSolrForTypo3\Solr\FrontendEnvironment; -use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe; use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration; use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; @@ -33,7 +32,6 @@ use TYPO3\CMS\Core\Site\Entity\Site as CoreSite; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * Class SiteRepository is responsible to retrieve instances of Site objects @@ -238,17 +236,6 @@ protected function buildTypo3ManagedSite(array $rootPageRecord): ?Site return $language->getLanguageId(); }, $typo3Site->getLanguages()); - // Try to get first instantiable TSFE for one of site languages, to get TypoScript with `plugin.tx_solr.index.*`, - // to be able to collect indexing configuration, - // which are required for BE-Modules/CLI-Commands or RecordMonitor within BE/TCE-commands. - // If TSFE for none of languages can be initialized, then the \ApacheSolrForTypo3\Solr\Domain\Site\Site object unusable at all, - // so the rest of the steps in this method are not necessary, and therefore the null will be returned. - $tsfeFactory = GeneralUtility::makeInstance(Tsfe::class); - $tsfeToUseForTypoScriptConfiguration = $tsfeFactory->getTsfeByPageIdAndLanguageFallbackChain($typo3Site->getRootPageId(), ...$availableLanguageIds); - if (!$tsfeToUseForTypoScriptConfiguration instanceof TypoScriptFrontendController) { - return null; - } - $solrConnectionConfigurations = []; foreach ($availableLanguageIds as $languageUid) { @@ -258,10 +245,8 @@ protected function buildTypo3ManagedSite(array $rootPageRecord): ?Site } } - $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId( - $rootPageRecord['uid'], - $tsfeToUseForTypoScriptConfiguration->getLanguage()->getLanguageId() - ); + $solrConfiguration = $this->frontendEnvironment + ->getSolrConfigurationFromPageId($rootPageRecord['uid']); return GeneralUtility::makeInstance( Site::class, diff --git a/Classes/FrontendEnvironment.php b/Classes/FrontendEnvironment.php index 19db32cecf..44062f5831 100644 --- a/Classes/FrontendEnvironment.php +++ b/Classes/FrontendEnvironment.php @@ -17,14 +17,12 @@ namespace ApacheSolrForTypo3\Solr; -use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe; use ApacheSolrForTypo3\Solr\FrontendEnvironment\TypoScript; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use Doctrine\DBAL\Exception as DBALException; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * Class FrontendEnvironment is responsible for initializing/simulating the frontend in backend context @@ -45,11 +43,9 @@ class FrontendEnvironment implements SingletonInterface public function getConfigurationFromPageId( int $pageId, ?string $path = '', - ?int $language = 0, - ?int $rootPageId = null, + ?int $rootPageId = null ): TypoScriptConfiguration { - $typoScript = GeneralUtility::makeInstance(TypoScript::class); - return $typoScript->getConfigurationFromPageId($pageId, $path, $language, $rootPageId); + return GeneralUtility::makeInstance(TypoScript::class)->getConfigurationFromPageId($pageId, $path, $rootPageId); } /** @@ -73,11 +69,7 @@ public function isAllowedPageType( $rootPageRecordUid = $pageRecord['l10n_parent']; } - $tsfe = GeneralUtility::makeInstance(Tsfe::class)->getTsfeByPageIdIgnoringLanguage($rootPageRecordUid); - if (!$tsfe instanceof TypoScriptFrontendController) { - return false; - } - $configuration = $this->getConfigurationFromPageId($rootPageRecordUid, '', $tsfe->getLanguage()->getLanguageId()); + $configuration = $this->getConfigurationFromPageId($rootPageRecordUid); if ($configurationName !== null) { $allowedPageTypes = $configuration->getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName); } else { @@ -95,9 +87,8 @@ public function isAllowedPageType( */ public function getSolrConfigurationFromPageId( int $pageId, - ?int $language = 0, - ?int $rootPageId = null, + ?int $rootPageId = null ): TypoScriptConfiguration { - return $this->getConfigurationFromPageId($pageId, '', $language, $rootPageId); + return $this->getConfigurationFromPageId($pageId, '', $rootPageId); } } diff --git a/Classes/FrontendEnvironment/Tsfe.php b/Classes/FrontendEnvironment/Tsfe.php deleted file mode 100644 index 167e57bcaa..0000000000 --- a/Classes/FrontendEnvironment/Tsfe.php +++ /dev/null @@ -1,391 +0,0 @@ -siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class); - } - - /** - * Initializes the TSFE for a given page ID and language. - * - * - * - * @throws Exception\Exception - * @throws SiteNotFoundException - * @throws DBALException - * - * - * @todo: Move whole caching stuff from this method and let return TSFE. - */ - protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPageId = null): void - { - $cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId); - - // Handle spacer and sys-folders, since they are not accessible in frontend, and TSFE can not be fully initialized on them. - // Apart from this, the plugin.tx_solr.index.queue.[indexConfig].additionalPageIds is handled as well. - $pidToUse = $this->getPidToUseForTsfeInitialization($pageId, $rootPageId); - if ($pidToUse !== $pageId) { - $this->initializeTsfe($pidToUse, $language, $rootPageId); - $reusedCacheIdentifier = $this->getCacheIdentifier($pidToUse, $language, $rootPageId); - $this->serverRequestCache[$cacheIdentifier] = $this->serverRequestCache[$reusedCacheIdentifier]; - $this->tsfeCache[$cacheIdentifier] = $this->tsfeCache[$reusedCacheIdentifier]; - // if ($rootPageId === null) { - // // @Todo: Resolve and set TSFE object for $rootPageId. - // } - return; - } - - /** @var Context $context */ - $context = clone GeneralUtility::makeInstance(Context::class); - $site = $this->siteFinder->getSiteByPageId($pageId); - // $siteLanguage and $languageAspect takes the language id into account. - // See: $site->getLanguageById($language); - // Therefore the whole TSFE stack is initialized and must be used as is. - // Note: ServerRequest, Context, Language, cObj of TSFE MUST NOT be changed or touched in any way, - // Otherwise the caching of TSFEs makes no sense anymore. - // If you want something to change in TSFE object, please use cloned one! - $siteLanguage = $site->getLanguageById($language); - $languageAspect = LanguageAspectFactory::createFromSiteLanguage($siteLanguage); - $context->setAspect('language', $languageAspect); - - $serverRequest = $this->serverRequestCache[$cacheIdentifier] ?? null; - if (!isset($this->serverRequestCache[$cacheIdentifier])) { - $serverRequest = GeneralUtility::makeInstance(ServerRequest::class); - $this->serverRequestCache[$cacheIdentifier] = $serverRequest = - $serverRequest->withAttribute('site', $site) - ->withAttribute('language', $siteLanguage) - ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE) - ->withUri($site->getBase()); - } - - if (!isset($this->tsfeCache[$cacheIdentifier])) { - // TYPO3 by default enables a preview mode if a backend user is logged in, - // the VisibilityAspect is configured to show hidden elements. - // Due to this setting hidden relations/translations might be indexed - // when running the Solr indexer via the TYPO3 backend. - // To avoid this, the VisibilityAspect is adapted for indexing. - $context->setAspect( - 'visibility', - GeneralUtility::makeInstance( - VisibilityAspect::class, - false, - false - ) - ); - - /** @var FrontendUserAuthentication $feUser */ - $feUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class); - // for certain situations we need to trick TSFE into granting us - // access to the page in any case to make getPageAndRootline() work - // see http://forge.typo3.org/issues/42122 - $pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); - if (!empty($pageRecord['fe_group'])) { - $userGroups = explode(',', $pageRecord['fe_group']); - } else { - $userGroups = [0, -1]; - } - $feUser->user = ['uid' => 0, 'username' => '', 'usergroup' => implode(',', $userGroups) ]; - $feUser->fetchGroupData($serverRequest); - $context->setAspect('frontend.user', GeneralUtility::makeInstance(UserAspect::class, $feUser, $userGroups)); - - /** @var PageArguments $pageArguments */ - $pageArguments = GeneralUtility::makeInstance(PageArguments::class, $pageId, '0', []); - - /** @var TypoScriptFrontendController $tsfe */ - $tsfe = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $siteLanguage, $pageArguments, $feUser); - - // @extensionScannerIgnoreLine - /** Done in {@link TypoScriptFrontendController::settingLanguage} */ - //$tsfe->sys_page = GeneralUtility::makeInstance(PageRepository::class); - - $template = GeneralUtility::makeInstance(TemplateService::class, $context, null, $tsfe); - $template->tt_track = false; - $tsfe->tmpl = $template; - $context->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true)); - $tsfe->no_cache = true; - - $backedUpBackendUser = $GLOBALS['BE_USER'] ?? null; - try { - $tsfe->determineId($serverRequest); - $serverRequest->withAttribute('frontend.controller', $tsfe); - $tsfe->no_cache = false; - // @todo T12: Check if following line really needed - $tsfe->getFromCache($serverRequest); - // The manual releasing of locks is low level api and should be avoided in EXT:solr. - $tsfe->releaseLocks(); - - $tsfe->newCObj($serverRequest); - $tsfe->absRefPrefix = self::getAbsRefPrefixFromTSFE($tsfe); - $tsfe->calculateLinkVars([]); - } catch (Throwable $exception) { - // @todo: logging - $this->serverRequestCache[$cacheIdentifier] = null; - $this->tsfeCache[$cacheIdentifier] = null; - // Restore backend user, happens when initializeTsfe() is called from Backend context - if ($backedUpBackendUser) { - $GLOBALS['BE_USER'] = $backedUpBackendUser; - } - return; - } - // Restore backend user, happens when initializeTsfe() is called from Backend context - if ($backedUpBackendUser) { - $GLOBALS['BE_USER'] = $backedUpBackendUser; - } - - $this->tsfeCache[$cacheIdentifier] = $tsfe; - } - - // @todo: Not right place for that action, move on more convenient place: indexing a single item+id+lang. - Locales::setSystemLocaleFromSiteLanguage($siteLanguage); - } - - /** - * Returns TypoScriptFrontendController with sand cast context. - * - * @throws SiteNotFoundException - * @throws Exception\Exception - * @throws DBALException - */ - public function getTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?TypoScriptFrontendController - { - $this->assureIsInitialized($pageId, $language, $rootPageId); - return $this->tsfeCache[$this->getCacheIdentifier($pageId, $language, $rootPageId)]; - } - - /** - * Returns TypoScriptFrontendController for first available language id in fallback chain. - * - * Is usable for BE-Modules/CLI-Commands stack only, where the rendered TypoScript configuration - * of EXT:solr* stack is wanted and the language id does not matter. - * - * NOTE: This method MUST NOT be used on indexing context. - * - * @param int ...$languageFallbackChain - */ - public function getTsfeByPageIdAndLanguageFallbackChain(int $pageId, int ...$languageFallbackChain): ?TypoScriptFrontendController - { - foreach ($languageFallbackChain as $languageId) { - try { - $tsfe = $this->getTsfeByPageIdAndLanguageId($pageId, $languageId); - if ($tsfe instanceof TypoScriptFrontendController) { - return $tsfe; - } - } catch (Throwable $e) { - // no needs to log or do anything, the method MUST not return anything if it can't. - continue; - } - } - return null; - } - - /** - * Returns TSFE for first initializable site language. - * - * Is usable for BE-Modules/CLI-Commands stack only, where the rendered TypoScript configuration - * of EXT:solr* stack is wanted and the language id does not matter. - */ - public function getTsfeByPageIdIgnoringLanguage(int $pageId): ?TypoScriptFrontendController - { - try { - $typo3Site = $this->siteFinder->getSiteByPageId($pageId); - } catch (Throwable $e) { - return null; - } - $availableLanguageIds = array_map(static function ($siteLanguage) { - return $siteLanguage->getLanguageId(); - }, $typo3Site->getLanguages()); - - if (empty($availableLanguageIds)) { - return null; - } - return $this->getTsfeByPageIdAndLanguageFallbackChain($pageId, ...$availableLanguageIds); - } - - /** - * Returns TypoScriptFrontendController with sand cast context. - * - * @throws SiteNotFoundException - * @throws Exception\Exception - * @throws DBALException - * - * @noinspection PhpUnused - */ - public function getServerRequestForTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?ServerRequest - { - $this->assureIsInitialized($pageId, $language, $rootPageId); - return $this->serverRequestCache[$this->getCacheIdentifier($pageId, $language, $rootPageId)]; - } - - /** - * Initializes the TSFE, ServerRequest, Context if not already done. - * - * - * - * @throws SiteNotFoundException - * @throws Exception\Exception - * @throws DBALException - */ - 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; - } - if ($this->tsfeCache[$cacheIdentifier] instanceof TypoScriptFrontendController) { - $this->tsfeCache[$cacheIdentifier]->newCObj($this->serverRequestCache[$cacheIdentifier]); - } - } - - /** - * Returns the cache identifier for cached TSFE and ServerRequest objects. - */ - protected function getCacheIdentifier(int $pageId, int $language, ?int $rootPageId = null): string - { - return 'root:' . ($rootPageId ?? 'null') . '|page:' . $pageId . '|lang:' . $language; - } - - /** - * The TSFE can not be initialized for Spacer and sys-folders. - * See: "Spacer and sys folders is not accessible in frontend" on {@link TypoScriptFrontendController::getPageAndRootline} - * - * Note: The requested $pidToUse can be one of configured plugin.tx_solr.index.queue.[indexConfig].additionalPageIds. - * - * @throws Exception\Exception - * @throws DBALException - */ - protected function getPidToUseForTsfeInitialization(int $pidToUse, ?int $rootPageId = null): ?int - { - $incomingPidToUse = $pidToUse; - $incomingRootPageId = $rootPageId; - - // handle plugin.tx_solr.index.queue.[indexConfig].additionalPageIds - if (isset($rootPageId) && !$this->isRequestedPageAPartOfRequestedSite($pidToUse)) { - return $rootPageId; - } - $pageRecord = BackendUtility::getRecord('pages', $pidToUse); - $isSpacerOrSysfolder = ($pageRecord['doktype'] ?? null) == PageRepository::DOKTYPE_SPACER || ($pageRecord['doktype'] ?? null) == PageRepository::DOKTYPE_SYSFOLDER; - if ($isSpacerOrSysfolder === false) { - return $pidToUse; - } - /** @var ConfigurationPageResolver $configurationPageResolver */ - $configurationPageResolver = GeneralUtility::makeInstance(ConfigurationPageResolver::class); - $askedPid = $pidToUse; - $pidToUse = $configurationPageResolver->getClosestPageIdWithActiveTemplate($pidToUse); - if (!isset($pidToUse) && !isset($rootPageId)) { - throw new Exception\Exception( - "The closest page with active template to page \"$askedPid\" could not be resolved and alternative rootPageId is not provided.", - 1637339439 - ); - } - if (isset($rootPageId)) { - return $rootPageId; - } - - // Check for recursion that can happen if the root page is a sysfolder with a typoscript template - if ($pidToUse === $incomingPidToUse && $rootPageId === $incomingRootPageId) { - throw new Exception\Exception( - "Infinite recursion detected while looking for the closest page with active template to page \"$askedPid\" . Please note that the page with active template (usually the root page of the current tree) MUST NOT be a sysfolder.", - 1637339476 - ); - } - - return $this->getPidToUseForTsfeInitialization($pidToUse, $rootPageId); - } - - /** - * Checks if the requested page belongs to site of given root page. - */ - protected function isRequestedPageAPartOfRequestedSite(int $pageId, ?int $rootPageId = null): bool - { - if (!isset($rootPageId)) { - return false; - } - try { - $site = $this->siteFinder->getSiteByPageId($pageId); - } catch (SiteNotFoundException $e) { - return false; - } - return $rootPageId === $site->getRootPageId(); - } - - /** - * Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix - * is set to "auto". - */ - private function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE): string - { - $absRefPrefix = ''; - if (empty($TSFE->config['config']['absRefPrefix'])) { - return $absRefPrefix; - } - - $absRefPrefix = trim($TSFE->config['config']['absRefPrefix']); - if ($absRefPrefix === 'auto') { - $absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'); - } - - return $absRefPrefix; - } -} diff --git a/Classes/FrontendEnvironment/TypoScript.php b/Classes/FrontendEnvironment/TypoScript.php index b4435796c1..20f7395c2a 100644 --- a/Classes/FrontendEnvironment/TypoScript.php +++ b/Classes/FrontendEnvironment/TypoScript.php @@ -20,12 +20,9 @@ use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; -use Doctrine\DBAL\Exception as DBALException; -use TYPO3\CMS\Core\Error\Http\InternalServerErrorException; -use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException; -use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; /** * Class TypoScript @@ -44,19 +41,15 @@ class TypoScript implements SingletonInterface * * @param int $pageId The page id of the (root) page to get the Solr configuration from. * @param string $path The TypoScript configuration path to retrieve. - * @param int $language System language uid, optional, defaults to 0 * * @return TypoScriptConfiguration The Solr configuration for the requested tree. - * - * @throws DBALException */ public function getConfigurationFromPageId( int $pageId, string $path, - int $language = 0, ?int $rootPageId = null ): TypoScriptConfiguration { - $cacheId = md5($pageId . '|' . $path . '|' . $language); + $cacheId = md5($pageId . '|' . $path); if (isset($this->configurationObjectCache[$cacheId])) { return $this->configurationObjectCache[$cacheId]; } @@ -66,7 +59,7 @@ public function getConfigurationFromPageId( // getRootline() below throws an exception (since #typo3-60 ) // as UID 0 cannot have any parent rootline by design. if ($pageId === 0 && $rootPageId === null) { - return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray([], $pageId, $language, $path); + return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray([], $pageId, $path); } /** @var TwoLevelCache $cache */ @@ -75,33 +68,25 @@ public function getConfigurationFromPageId( if (!empty($configurationArray)) { // we have a cache hit and can return it. - return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); + return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $path); } // we have nothing in the cache. We need to build the configurationToUse - $configurationArray = $this->buildConfigurationArray($pageId, $path, $language); + $configurationArray = $this->buildConfigurationArray($path); $cache->set($cacheId, $configurationArray); - return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); + return $this->configurationObjectCache[$cacheId] = $this->buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $path); } /** * Builds a configuration array, containing the solr configuration. - * - * @throws DBALException */ - protected function buildConfigurationArray(int $pageId, string $path, int $language): array + protected function buildConfigurationArray(string $path): array { - /** @var Tsfe $tsfeManager */ - $tsfeManager = GeneralUtility::makeInstance(Tsfe::class); - try { - $tsfe = $tsfeManager->getTsfeByPageIdAndLanguageId($pageId, $language); - } catch (InternalServerErrorException | ServiceUnavailableException | SiteNotFoundException | Exception\Exception $e) { - // @todo logging! - return []; - } - $getConfigurationFromInitializedTSFEAndWriteToCache = $this->ext_getSetup($tsfe->tmpl->setup ?? [], $path); + $typoscriptSetup = GeneralUtility::makeInstance(ConfigurationManagerInterface::class) + ->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); + $getConfigurationFromInitializedTSFEAndWriteToCache = $this->ext_getSetup($typoscriptSetup ?? [], $path); return $getConfigurationFromInitializedTSFEAndWriteToCache[0] ?? []; } @@ -130,9 +115,9 @@ public function ext_getSetup(array $theSetup, string $theKey): array /** * Builds the configuration object from a config array and returns it. */ - protected function buildTypoScriptConfigurationFromArray(array $configurationToUse, int $pageId, int $languageId, string $typoScriptPath): TypoScriptConfiguration + protected function buildTypoScriptConfigurationFromArray(array $configurationToUse, int $pageId, string $typoScriptPath): TypoScriptConfiguration { $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); - return $configurationManager->getTypoScriptConfiguration($configurationToUse, $pageId, $languageId, $typoScriptPath); + return $configurationManager->getTypoScriptConfiguration($configurationToUse, $pageId, $typoScriptPath); } } diff --git a/Classes/IndexQueue/AbstractIndexer.php b/Classes/IndexQueue/AbstractIndexer.php index 768ca740eb..4e41229d6d 100644 --- a/Classes/IndexQueue/AbstractIndexer.php +++ b/Classes/IndexQueue/AbstractIndexer.php @@ -24,7 +24,6 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use UnexpectedValueException; /** @@ -58,8 +57,11 @@ public static function isAllowedToOverrideField(string $solrFieldName): bool * @param array $data Record data * @return Document Modified document with added fields */ - protected function addDocumentFieldsFromTyposcript(Document $document, array $indexingConfiguration, array $data, TypoScriptFrontendController $tsfe): Document - { + protected function addDocumentFieldsFromTyposcript( + Document $document, + array $indexingConfiguration, + array $data, + ): Document { $data = static::addVirtualContentFieldToRecord($document, $data); // mapping of record fields => solr document fields, resolving cObj @@ -76,7 +78,7 @@ protected function addDocumentFieldsFromTyposcript(Document $document, array $in ); } - $fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data, $tsfe); + $fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data); if ($fieldValue === null) { continue; } @@ -118,7 +120,6 @@ protected function resolveFieldValue( array $indexingConfiguration, string $solrFieldName, array $data, - TypoScriptFrontendController $tsfe ): array|float|int|string|null { if (isset($indexingConfiguration[$solrFieldName . '.'])) { // configuration found => need to resolve a cObj @@ -128,8 +129,8 @@ protected function resolveFieldValue( $backupWorkingDirectory = getcwd(); chdir(Environment::getPublicPath() . '/'); - $tsfe->cObj->start($data, $this->type); - $fieldValue = $tsfe->cObj->cObjGetSingle( + $GLOBALS['TSFE']->cObj->start($data, $this->type); + $fieldValue = $GLOBALS['TSFE']->cObj->cObjGetSingle( $indexingConfiguration[$solrFieldName], $indexingConfiguration[$solrFieldName . '.'] ); @@ -159,8 +160,8 @@ protected function resolveFieldValue( $backupWorkingDirectory = getcwd(); chdir(Environment::getPublicPath() . '/'); - $tsfe->cObj->start($data, $this->type); - $fieldValue = $tsfe->cObj->cObjGetSingle($name, $conf); + $GLOBALS['TSFE']->cObj->start($data, $this->type); + $fieldValue = $GLOBALS['TSFE']->cObj->cObjGetSingle($name, $conf); chdir($backupWorkingDirectory); diff --git a/Classes/IndexQueue/Indexer.php b/Classes/IndexQueue/Indexer.php index 065cdca188..2add958c43 100644 --- a/Classes/IndexQueue/Indexer.php +++ b/Classes/IndexQueue/Indexer.php @@ -25,7 +25,6 @@ use ApacheSolrForTypo3\Solr\FieldProcessor\Service; use ApacheSolrForTypo3\Solr\FrontendEnvironment; use ApacheSolrForTypo3\Solr\FrontendEnvironment\Exception\Exception as FrontendEnvironmentException; -use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe; use ApacheSolrForTypo3\Solr\IndexQueue\Exception\IndexingException; use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; @@ -234,11 +233,7 @@ protected function getItemRecordOverlayed(Item $item, int $language): ?array return null; } - $pidToUse = $this->getPageIdOfItem($item); - - return GeneralUtility::makeInstance(Tsfe::class) - ->getTsfeByPageIdAndLanguageId($pidToUse, $language, $item->getRootPageUid()) - ->sys_page->getLanguageOverlay($item->getType(), $itemRecord); + return $GLOBALS['TSFE']->sys_page->getLanguageOverlay($item->getType(), $itemRecord); } protected function isAFreeContentModeItemRecord(Item $item): bool @@ -269,7 +264,7 @@ protected function isAFreeContentModeItemRecord(Item $item): bool protected function getItemTypeConfiguration(Item $item, int $language = 0): array { $indexConfigurationName = $item->getIndexingConfigurationName(); - $fields = $this->getFieldConfigurationFromItemRecordPage($item, $language, $indexConfigurationName); + $fields = $this->getFieldConfigurationFromItemRecordPage($item, $indexConfigurationName); if (!$this->isRootPageIdPartOfRootLine($item) || count($fields) === 0) { $fields = $this->getFieldConfigurationFromItemRootPage($item, $language, $indexConfigurationName); if (count($fields) === 0) { @@ -284,13 +279,13 @@ protected function getItemTypeConfiguration(Item $item, int $language = 0): arra /** * The method retrieves the field configuration of the items record page id (pid). */ - protected function getFieldConfigurationFromItemRecordPage(Item $item, int $language, string $indexConfigurationName): array + protected function getFieldConfigurationFromItemRecordPage(Item $item, string $indexConfigurationName): array { try { $pageId = $this->getPageIdOfItem($item); - $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($pageId, $language, $item->getRootPageUid()); - return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName); - } catch (Throwable) { + $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($pageId, $item->getRootPageUid()); + return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []); + } catch (Throwable $e) { return []; } } @@ -354,9 +349,7 @@ protected function itemToDocument(Item $item, int $language = 0): ?Document if (!is_null($itemRecord)) { $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language); $document = $this->getBaseDocument($item, $itemRecord); - $pidToUse = $this->getPageIdOfItem($item); - $tsfe = GeneralUtility::makeInstance(Tsfe::class)->getTsfeByPageIdAndLanguageId($pidToUse, $language, $item->getRootPageUid()); - $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord, $tsfe); + $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord); } return $document; diff --git a/Classes/System/Configuration/ConfigurationManager.php b/Classes/System/Configuration/ConfigurationManager.php index becf52b7cd..9a22a853c4 100644 --- a/Classes/System/Configuration/ConfigurationManager.php +++ b/Classes/System/Configuration/ConfigurationManager.php @@ -43,8 +43,7 @@ public function reset(): void public function getTypoScriptConfiguration( array $configurationArray = null, int $contextPageId = null, - int $contextLanguageId = 0, - string $contextTypoScriptPath = '', + string $contextTypoScriptPath = '' ): TypoScriptConfiguration { if ($configurationArray == null) { if (isset($this->typoScriptConfigurations['default'])) { @@ -67,7 +66,7 @@ public function getTypoScriptConfiguration( $contextPageId = $GLOBALS['TSFE']->id; } - $hash = md5(serialize($configurationArray)) . '-' . $contextPageId . '-' . $contextLanguageId . '-' . $contextTypoScriptPath; + $hash = md5(serialize($configurationArray)) . '-' . $contextPageId . '-' . $contextTypoScriptPath; if (isset($this->typoScriptConfigurations[$hash])) { return $this->typoScriptConfigurations[$hash]; } diff --git a/Tests/Unit/FrontendEnvironment/TypoScriptTest.php b/Tests/Unit/FrontendEnvironment/TypoScriptTest.php index 6943b2b64c..c3925dac32 100644 --- a/Tests/Unit/FrontendEnvironment/TypoScriptTest.php +++ b/Tests/Unit/FrontendEnvironment/TypoScriptTest.php @@ -50,7 +50,7 @@ public function getConfigurationFromPageIdReturnsCachedConfiguration(): void $pageId = 12; $path = ''; $language = 0; - $cacheId = md5($pageId . '|' . $path . '|' . $language); + $cacheId = md5($pageId . '|' . $path); // prepare first call $twoLevelCache = $this->createMock(TwoLevelCache::class); @@ -72,8 +72,7 @@ public function getConfigurationFromPageIdReturnsCachedConfiguration(): void $newConfiguration = $this->typoScriptMock->getConfigurationFromPageId( $pageId, - $path, - $language + $path ); self::assertInstanceOf(TypoScriptConfiguration::class, $newConfiguration);