Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[TASK:BP:11] Add language cache to SiteUtility
Fixes: #2908
Back ported from: #2909
  • Loading branch information
Konafets authored and dkd-kaehm committed Jul 16, 2021
1 parent 19baedc commit 6f7e4d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Classes/System/Util/SiteUtility.php
Expand Up @@ -37,6 +37,9 @@
class SiteUtility
{

/** @var array */
public static $languages = [];

/**
* Determines if the site where the page belongs to is managed with the TYPO3 site management.
*
Expand Down Expand Up @@ -111,8 +114,10 @@ protected static function getConnectionPropertyOrFallback(Site $typo3Site, strin
$fallbackKey = 'solr_' . $property . '_read';

// try to find language specific setting if found return it
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
$value = self::getValueOrFallback($languageSpecificConfiguration, $keyToCheck, $fallbackKey);
if (isset(self::$languages[$languageId]) === false) {
self::$languages[$languageId] = $typo3Site->getLanguageById($languageId)->toArray();
}
$value = self::getValueOrFallback(self::$languages[$languageId], $keyToCheck, $fallbackKey);
if ($value !== null) {
return $value;
}
Expand All @@ -132,8 +137,10 @@ protected static function getConnectionPropertyOrFallback(Site $typo3Site, strin
*/
protected static function writeConnectionIsEnabled(Site $typo3Site, int $languageId): bool
{
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
$value = self::getValueOrFallback($languageSpecificConfiguration, 'solr_use_write_connection', 'solr_use_write_connection');
if (isset(self::$languages[$languageId]) === false) {
self::$languages[$languageId] = $typo3Site->getLanguageById($languageId)->toArray();
}
$value = self::getValueOrFallback(self::$languages[$languageId], 'solr_use_write_connection', 'solr_use_write_connection');
if ($value !== null) {
return $value;
}
Expand Down
7 changes: 6 additions & 1 deletion Tests/Unit/System/Util/SiteUtilityTest.php
Expand Up @@ -36,6 +36,11 @@
*/
class SiteUtilityTest extends UnitTest
{
public function tearDown()
{
SiteUtility::$languages = [];
}

/**
* @test
*/
Expand Down Expand Up @@ -286,4 +291,4 @@ public function canHandleSiteConfigurationValues (

$this->assertEquals($expectedConfigurationValue, $property, 'Value from site configuration not read/handled correctly.');
}
}
}

0 comments on commit 6f7e4d1

Please sign in to comment.