diff --git a/Classes/ConnectionManager.php b/Classes/ConnectionManager.php index 5d9b4db0f..1b8fc3501 100644 --- a/Classes/ConnectionManager.php +++ b/Classes/ConnectionManager.php @@ -22,6 +22,7 @@ use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException; use ApacheSolrForTypo3\Solr\Exception\InvalidConnectionException; +use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository as PagesRepositoryAtExtSolr; use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; use ApacheSolrForTypo3\Solr\System\Util\SiteUtility; @@ -92,6 +93,7 @@ public function __construct( public function getSolrConnectionForEndpoints( array $readEndpointConfiguration, array $writeEndpointConfiguration, + TypoScriptConfiguration $typoScriptConfiguration, ): SolrConnection { $connectionHash = md5(json_encode($readEndpointConfiguration) . json_encode($writeEndpointConfiguration)); if (!isset(self::$connections[$connectionHash])) { @@ -105,7 +107,12 @@ public function getSolrConnectionForEndpoints( throw new InvalidConnectionException('Invalid write endpoint'); } - self::$connections[$connectionHash] = GeneralUtility::makeInstance(SolrConnection::class, $readEndpoint, $writeEndpoint); + self::$connections[$connectionHash] = GeneralUtility::makeInstance( + SolrConnection::class, + $readEndpoint, + $writeEndpoint, + $typoScriptConfiguration, + ); } return self::$connections[$connectionHash]; @@ -155,9 +162,15 @@ protected function isValidEndpoint(Endpoint $endpoint): bool * * @throws InvalidConnectionException */ - public function getConnectionFromConfiguration(array $solrConfiguration): SolrConnection - { - return $this->getSolrConnectionForEndpoints($solrConfiguration['read'], $solrConfiguration['write']); + public function getConnectionFromConfiguration( + array $solrConfiguration, + TypoScriptConfiguration $typoScriptConfiguration, + ): SolrConnection { + return $this->getSolrConnectionForEndpoints( + $solrConfiguration['read'], + $solrConfiguration['write'], + $typoScriptConfiguration + ); } /** @@ -174,7 +187,10 @@ public function getConnectionByPageId(int $pageId, int $language = 0, string $mo 'No site for pageId ' . $pageId, ); $config = $site->getSolrConnectionConfiguration($language); - return $this->getConnectionFromConfiguration($config); + return $this->getConnectionFromConfiguration( + $config, + $site->getSolrConfiguration(), + ); } catch (Throwable $unexpectedError) { throw $this->buildNoConnectionExceptionForPageAndLanguage( $pageId, @@ -200,7 +216,10 @@ public function getConnectionByTypo3Site(Typo3Site $typo3Site, int $languageUid } try { - return $this->getConnectionFromConfiguration($config); + return $this->getConnectionFromConfiguration( + $config, + $this->siteRepository->getSiteByRootPageId($typo3Site->getRootPageId())->getSolrConfiguration(), + ); } catch (Throwable $unexpectedError) { throw $this->buildNoConnectionExceptionForPageAndLanguage( $typo3Site->getRootPageId(), @@ -223,7 +242,10 @@ public function getConnectionByRootPageId(int $pageId, ?int $language = 0): Solr $site = $this->siteRepository->getSiteByRootPageId($pageId); $this->throwExceptionOnInvalidSite($site, 'No site for pageId ' . $pageId); $config = $site->getSolrConnectionConfiguration($language ?? 0); - return $this->getConnectionFromConfiguration($config); + return $this->getConnectionFromConfiguration( + $config, + $site->getSolrConfiguration(), + ); } catch (InvalidArgumentException) { throw $this->buildNoConnectionExceptionForPageAndLanguage($pageId, $language); } @@ -242,7 +264,10 @@ public function getAllConnections(): array $solrConnections = []; foreach ($this->siteRepository->getAvailableSites() as $site) { foreach ($site->getAllSolrConnectionConfigurations() as $solrConfiguration) { - $solrConnections[] = $this->getConnectionFromConfiguration($solrConfiguration); + $solrConnections[] = $this->getConnectionFromConfiguration( + $solrConfiguration, + $site->getSolrConfiguration(), + ); } } @@ -261,7 +286,10 @@ public function getConnectionsBySite(Site $site): array $connections = []; foreach ($site->getAllSolrConnectionConfigurations() as $languageId => $solrConnectionConfiguration) { - $connections[$languageId] = $this->getConnectionFromConfiguration($solrConnectionConfiguration); + $connections[$languageId] = $this->getConnectionFromConfiguration( + $solrConnectionConfiguration, + $site->getSolrConfiguration(), + ); } return $connections; diff --git a/Classes/Domain/Site/Site.php b/Classes/Domain/Site/Site.php index c71a7a37d..de56e2341 100644 --- a/Classes/Domain/Site/Site.php +++ b/Classes/Domain/Site/Site.php @@ -228,8 +228,6 @@ public function getLabel(): string /** * Gets the site's Solr TypoScript configuration (plugin.tx_solr.*) - * - * Purpose: Interface and Unit test mocking helper method. */ public function getSolrConfiguration(): TypoScriptConfiguration { diff --git a/Classes/Report/SolrStatus.php b/Classes/Report/SolrStatus.php index 8b35de06b..39dd35305 100644 --- a/Classes/Report/SolrStatus.php +++ b/Classes/Report/SolrStatus.php @@ -111,7 +111,11 @@ protected function getConnectionStatus(Site $site, array $solrConnection): Statu $this->responseStatus = ContextualFeedbackSeverity::OK; $solrAdmin = $this->connectionManager - ->getSolrConnectionForEndpoints($solrConnection['read'], $solrConnection['write']) + ->getSolrConnectionForEndpoints( + $solrConnection['read'], + $solrConnection['write'], + $site->getSolrConfiguration() + ) ->getAdminService(); $solrVersion = $this->checkSolrVersion($solrAdmin); diff --git a/Tests/Unit/ConnectionManagerTest.php b/Tests/Unit/ConnectionManagerTest.php index 21a41b99e..423fdabeb 100644 --- a/Tests/Unit/ConnectionManagerTest.php +++ b/Tests/Unit/ConnectionManagerTest.php @@ -19,6 +19,7 @@ use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; use ApacheSolrForTypo3\Solr\Exception\InvalidConnectionException; use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; +use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; use PHPUnit\Framework\Attributes\DataProvider; @@ -141,7 +142,10 @@ public function canConnect( ]; $configuration['write'] = $configuration['read']; - $solrService = $this->connectionManager->getConnectionFromConfiguration($configuration); + $solrService = $this->connectionManager->getConnectionFromConfiguration( + $configuration, + $this->createMock(TypoScriptConfiguration::class) + ); self::assertEquals($expectedConnectionString, $solrService->getReadService()->__toString()); } catch (InvalidConnectionException $exception) { $exceptionOccurred = true;