first commit
This commit is contained in:
@@ -58,30 +58,16 @@ class SiteUtility
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to retrieve the connection configuration from the TYPO3 site configuration.
|
||||
*
|
||||
* Note: Language context properties have precedence over global settings.
|
||||
*
|
||||
* The configuration is done in the globals configuration of a site, and be extended in the language specific configuration
|
||||
* of a site.
|
||||
*
|
||||
* Typically everything except the core name is configured on the global level and the core name differs for each language.
|
||||
*
|
||||
* In addition every property can be defined for the ```read``` and ```write``` scope.
|
||||
*
|
||||
* The convention for property keys is "meilisearch_{propertyName}_{scope}". With the configuration "meilisearch_host_read" you define the host
|
||||
* for the meilisearch read connection.
|
||||
*
|
||||
* @param Site $typo3Site
|
||||
* @param string $property
|
||||
* @param int $languageId
|
||||
* @param string $scope
|
||||
* @param string $defaultValue
|
||||
* @return string
|
||||
*/
|
||||
public static function getConnectionProperty(Site $typo3Site, string $property, int $languageId, string $scope, string $defaultValue = null): string
|
||||
public static function getConnectionProperty(Site $typo3Site, string $property, string $defaultValue = null): string
|
||||
{
|
||||
$value = self::getConnectionPropertyOrFallback($typo3Site, $property, $languageId, $scope);
|
||||
$value = self::getConnectionPropertyOrFallback($typo3Site, $property);
|
||||
if ($value === null) {
|
||||
return $defaultValue;
|
||||
}
|
||||
@@ -94,72 +80,31 @@ class SiteUtility
|
||||
*
|
||||
* @param Site $typo3Site
|
||||
* @param string $property
|
||||
* @param int $languageId
|
||||
* @param string $scope
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getConnectionPropertyOrFallback(Site $typo3Site, string $property, int $languageId, string $scope)
|
||||
protected static function getConnectionPropertyOrFallback(Site $typo3Site, string $property)
|
||||
{
|
||||
if ($scope === 'write' && !self::writeConnectionIsEnabled($typo3Site, $languageId)) {
|
||||
$scope = 'read';
|
||||
}
|
||||
|
||||
// convention key meilisearch_$property_$scope
|
||||
$keyToCheck = 'meilisearch_' . $property . '_' . $scope;
|
||||
|
||||
// convention fallback key meilisearch_$property_read
|
||||
$fallbackKey = 'meilisearch_' . $property . '_read';
|
||||
|
||||
// try to find language specific setting if found return it
|
||||
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
|
||||
$value = self::getValueOrFallback($languageSpecificConfiguration, $keyToCheck, $fallbackKey);
|
||||
if ($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
$keyToCheck = 'meilisearch_' . $property;
|
||||
|
||||
// if not found check global configuration
|
||||
$siteBaseConfiguration = $typo3Site->getConfiguration();
|
||||
return self::getValueOrFallback($siteBaseConfiguration, $keyToCheck, $fallbackKey);
|
||||
return self::getValueOrFallback($siteBaseConfiguration, $keyToCheck);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether write connection is enabled.
|
||||
* Language context properties have precedence over global settings.
|
||||
*
|
||||
* @param Site $typo3Site
|
||||
* @param int $languageId
|
||||
* @return bool
|
||||
*/
|
||||
protected static function writeConnectionIsEnabled(Site $typo3Site, int $languageId): bool
|
||||
{
|
||||
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
|
||||
$value = self::getValueOrFallback($languageSpecificConfiguration, 'meilisearch_use_write_connection', 'meilisearch_use_write_connection');
|
||||
if ($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$siteBaseConfiguration = $typo3Site->getConfiguration();
|
||||
$value = self::getValueOrFallback($siteBaseConfiguration, 'meilisearch_use_write_connection', 'meilisearch_use_write_connection');
|
||||
if ($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $keyToCheck
|
||||
* @param string $fallbackKey
|
||||
* @return string|bool|null
|
||||
*/
|
||||
protected static function getValueOrFallback(array $data, string $keyToCheck, string $fallbackKey)
|
||||
protected static function getValueOrFallback(array $data, string $keyToCheck)
|
||||
{
|
||||
$value = $data[$keyToCheck] ?? null;
|
||||
if ($value === '0' || $value === 0 || !empty($value)) {
|
||||
return self::evaluateConfigurationData($value);
|
||||
}
|
||||
|
||||
return self::evaluateConfigurationData($data[$fallbackKey] ?? null);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +121,8 @@ class SiteUtility
|
||||
{
|
||||
if ($value === 'true') {
|
||||
return true;
|
||||
} elseif ($value === 'false') {
|
||||
}
|
||||
if ($value === 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user