Skip to content

Commit

Permalink
Fix TYPO3-Solr#1: Could not find a Solr connection for root page [1] …
Browse files Browse the repository at this point in the history
…and language [0] -> make default Language configurable
  • Loading branch information
sal-gassen authored and sal-lochbaum committed Jun 21, 2024
1 parent 345bc94 commit 16b8c7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Classes/IndexQueue/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe;
use ApacheSolrForTypo3\Solr\IndexQueue\Exception\IndexingException;
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
Expand Down Expand Up @@ -81,6 +82,8 @@ class Indexer extends AbstractIndexer
protected SolrLogManager $logger;
protected EventDispatcherInterface $eventDispatcher;

protected ExtensionConfiguration $extensionConfiguration;

public function __construct(
array $options = [],
PagesRepository $pagesRepository = null,
Expand All @@ -97,6 +100,7 @@ public function __construct(
$this->frontendEnvironment = $frontendEnvironment ?? GeneralUtility::makeInstance(FrontendEnvironment::class);
$this->logger = $logger ?? GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
$this->eventDispatcher = $eventDispatcher ?? GeneralUtility::makeInstance(EventDispatcherInterface::class);
$this->extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
}

/**
Expand Down Expand Up @@ -610,7 +614,7 @@ protected function getFallbackOrder(Site $site, int $languageId): array
*/
protected function getDefaultLanguageUid(Item $item, array $rootPageRecord, array $siteLanguages): int
{
$defaultLanguageUid = 0;
$defaultLanguageUid = $this->extensionConfiguration->getDefaultLanguageId();
if (($rootPageRecord['l18n_cfg'] & 1) == 1 && count($siteLanguages) == 1 && $siteLanguages[min(array_keys($siteLanguages))] > 0) {
$defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))];
} elseif (($rootPageRecord['l18n_cfg'] & 1) == 1 && count($siteLanguages) > 1) {
Expand Down
9 changes: 9 additions & 0 deletions Classes/System/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,13 @@ protected function getConfigurationOrDefaultValue(string $key, mixed $defaultVal
{
return $this->configuration[$key] ?? $defaultValue;
}

/**
* Returns the desired default language uid
* @return int
*/
public function getDefaultLanguageId(): int
{
return (int)$this->getConfigurationOrDefaultValue('defaultLanguageUid', 0);
}
}
6 changes: 5 additions & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ includeGlobalQParameterInCacheHash = 0
# cat=basic/enable/b1; type=boolean; label=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.useConfigurationFromClosestTemplate
useConfigurationFromClosestTemplate = 0

# cat=basic/enable/60; type=int+; label=Default Language Uid
defaultLanguageUid = 0

# cat=Monitoring/enable/c1; type=boolean; label=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.useConfigurationTrackRecordsOutsideSiteroot
useConfigurationTrackRecordsOutsideSiteroot = 1

Expand All @@ -23,4 +26,5 @@ monitoringType = 0
enableRouteEnhancer = 0

# cat=advanced/enable/e; type=boolean; label=LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:extConf.allowSelfSignedCertificates
allowSelfSignedCertificates = 0
allowSelfSignedCertificates = 0

0 comments on commit 16b8c7c

Please sign in to comment.