Skip to content

Commit

Permalink
[FIX] Garbage collector does not get configuration
Browse files Browse the repository at this point in the history
Garbage collector and RecordMonitor triggered by RecordMonitor 
do not have infos about PID or Site. 
This change contains first step for refactoring of configuration retrieval. 
The delegation of TypoScriptConfiguration object, which will be moved to strict aggregation structure.

Fixes: TYPO3-Solr#4203, TYPO3-Solr#4207, TYPO3-Solr#4208
Relates: TYPO3-Solr#3995
  • Loading branch information
dkd-kaehm committed Nov 28, 2024
1 parent 4690528 commit b928022
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
46 changes: 37 additions & 9 deletions Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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])) {
Expand All @@ -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];
Expand Down Expand Up @@ -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
);
}

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

Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions Classes/Domain/Site/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 5 additions & 1 deletion Classes/Report/SolrStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion Tests/Unit/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b928022

Please sign in to comment.