Skip to content

Commit

Permalink
!!![TASK:T12] Don't initialize TSFE in TYPO3 BE (Record Monitoring) c…
Browse files Browse the repository at this point in the history
…ontext

EXT:solr does not want really the initialized TSFE object on multiple places at all. The TSFE object was necessary in EXT:solr versions, which used the TypoScript conditions for configure/map the Apache Solr cores to appropriated TYPO3 languages.  The indexing stack required this approach as well to be able to index  different pages and/or its records in single PHP-Process.

Nova-days this all hacks not required on TYPO3 12+ LTS anymore,  so the whole TSFE-Fake initialization stack will be removed and  "isolated TYPO3 Application" approach will be used. This will lead to more isolated and less exceptional behavior on TYPO3 components on EXT:solr side/feature set.

Relates: TYPO3-Solr#3376
Replaces: TYPO3-Solr#3582
  • Loading branch information
dkd-kaehm committed May 26, 2023
1 parent 950b05e commit cb8f79d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 475 deletions.
19 changes: 2 additions & 17 deletions Classes/Domain/Site/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -235,17 +233,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) {
Expand All @@ -255,10 +242,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,
Expand Down
19 changes: 5 additions & 14 deletions Classes/FrontendEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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 {
Expand All @@ -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);
}
}
Loading

0 comments on commit cb8f79d

Please sign in to comment.