Skip to content

Commit

Permalink
[FIX] Indexing fails with SOLR_* cObj in TypoScript
Browse files Browse the repository at this point in the history
TYPO3 BE context properties from `$GLOBALS['TYPO3_REQUEST']` is used on actions 
from TYPO3 BE modules.
Most probably no usage of `$GLOBALS['TYPO3_REQUEST']` in EXT:solr context required at all, 
but leaving it for possible page-indexing context, which it is just fine to use original TYPO3 core bootstrapped FE stack.

Fixes: #4221
Relates: #3995
  • Loading branch information
dkd-kaehm committed Dec 17, 2024
1 parent 7fec14d commit bcb2521
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ public function getRootPageId(
/** @var Rootline $rootLine */
$rootLine = GeneralUtility::makeInstance(Rootline::class);

// frontend
if (!empty($GLOBALS['TSFE']->rootLine)) {
$rootLine->setRootLineArray($GLOBALS['TSFE']->rootLine);
}

// fallback, backend
if ($forceFallback || !$rootLine->getHasRootPage()) {
/** @var RootlineUtility $rootlineUtility */
Expand Down
38 changes: 28 additions & 10 deletions Classes/IndexQueue/AbstractIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
use Doctrine\DBAL\Exception as DBALException;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
Expand Down Expand Up @@ -63,7 +64,14 @@ public static function isAllowedToOverrideField(string $solrFieldName): bool
* @param Document $document base document to add fields to
* @param array $indexingConfiguration Indexing configuration / mapping
* @param array $data Record data
* @param TypoScriptFrontendController $tsfe The context-bound TSFE object
* @param int|SiteLanguage $language The site language object or UID as int
* @return Document Modified document with added fields
*
* @throws ContentRenderingException
* @throws DBALException
* @throws FrontendEnvironmentException
* @throws SiteNotFoundException
*/
protected function addDocumentFieldsFromTyposcript(
Document $document,
Expand Down Expand Up @@ -158,11 +166,16 @@ protected function resolveFieldValue(
chdir(Environment::getPublicPath() . '/');

$cObject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe);
$request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class)
->getServerRequestForTsfeByPageIdAndLanguageId(
$tsfe->id,
$language instanceof SiteLanguage ? $language->getLanguageId() : $language
);
/** @noinspection PhpInternalEntityUsedInspection */
if (($GLOBALS['TYPO3_REQUEST'] ?? null)?->getAttribute('applicationType') === SystemEnvironmentBuilder::REQUESTTYPE_FE) {
$request = $GLOBALS['TYPO3_REQUEST'];
} else {
$request = GeneralUtility::makeInstance(Tsfe::class)
->getServerRequestForTsfeByPageIdAndLanguageId(
$tsfe->id,
$language instanceof SiteLanguage ? $language->getLanguageId() : $language
);
}
$cObject->setRequest($request);
$cObject->start($data, $this->type);
$fieldValue = $cObject->cObjGetSingle(
Expand Down Expand Up @@ -200,11 +213,16 @@ protected function resolveFieldValue(
chdir(Environment::getPublicPath() . '/');

$cObject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe);
$request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class)
->getServerRequestForTsfeByPageIdAndLanguageId(
$tsfe->id,
$language instanceof SiteLanguage ? $language->getLanguageId() : $language
);
/** @noinspection PhpInternalEntityUsedInspection */
if (($GLOBALS['TYPO3_REQUEST'] ?? null)?->getAttribute('applicationType') === SystemEnvironmentBuilder::REQUESTTYPE_FE) {
$request = $GLOBALS['TYPO3_REQUEST'];
} else {
$request = GeneralUtility::makeInstance(Tsfe::class)
->getServerRequestForTsfeByPageIdAndLanguageId(
$tsfe->id,
$language instanceof SiteLanguage ? $language->getLanguageId() : $language
);
}
$cObject->setRequest($request);
$cObject->start($data, $this->type);
$fieldValue = $cObject->cObjGetSingle($name, $conf);
Expand Down

0 comments on commit bcb2521

Please sign in to comment.