adasd
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-29 01:44:14 +02:00
parent af1d94a3b6
commit 488964df3a
3 changed files with 302 additions and 8 deletions

View File

@@ -30,7 +30,6 @@ $mm->registerFunction($moduleName, 'settings', static function (): array {
$saved = modules()->settings('fx-rates');
$provider = trim((string) ($saved['provider'] ?? (getenv('FX_RATES_PROVIDER') ?: getenv('MINING_CHECKER_FX_PROVIDER') ?: 'currencyapi')));
$apiUrl = rtrim((string) ($saved['api_url'] ?? (getenv('FX_RATES_API_URL') ?: getenv('MINING_CHECKER_FX_URL') ?: 'https://currencyapi.net')), '/');
$currenciesUrl = rtrim((string) ($saved['currencies_url'] ?? (getenv('FX_RATES_CURRENCIES_URL') ?: getenv('MINING_CHECKER_FX_CURRENCIES_URL') ?: getenv('MINING_CHECKER_FX_URL') ?: 'https://currencyapi.net')), '/');
$apiKey = trim((string) ($saved['api_key'] ?? (getenv('FX_RATES_API_KEY') ?: getenv('MINING_CHECKER_FX_API_KEY') ?: '')));
$timeout = max(2, (int) ($saved['timeout_sec'] ?? (getenv('FX_RATES_TIMEOUT') ?: getenv('MINING_CHECKER_FX_TIMEOUT') ?: 10)));
$cacheTtl = max(60, (int) ($saved['cache_ttl_sec'] ?? (getenv('FX_RATES_CACHE_TTL') ?: getenv('MINING_CHECKER_FX_CACHE_TTL') ?: 21600)));
@@ -44,16 +43,30 @@ $mm->registerFunction($moduleName, 'settings', static function (): array {
is_array($preferredCurrencies) ? $preferredCurrencies : []
), static fn (string $code): bool => $code !== '')));
$currencyCatalog = $saved['currency_catalog'] ?? [];
$currencyCatalog = array_values(array_filter(array_map(static function (mixed $item): ?array {
if (!is_array($item)) {
return null;
}
$code = strtoupper(trim((string) ($item['code'] ?? '')));
$name = trim((string) ($item['name'] ?? ''));
if ($code === '' || $name === '') {
return null;
}
return ['code' => $code, 'name' => $name];
}, is_array($currencyCatalog) ? $currencyCatalog : [])));
return [
'provider' => $provider !== '' ? $provider : 'currencyapi',
'api_url' => $apiUrl,
'currencies_url' => $currenciesUrl,
'api_key' => $apiKey,
'timeout_sec' => $timeout,
'cache_ttl_sec' => $cacheTtl,
'default_base_currency' => strtoupper(trim((string) ($saved['default_base_currency'] ?? 'EUR'))) ?: 'EUR',
'display_base_currency' => strtoupper(trim((string) ($saved['display_base_currency'] ?? ($saved['default_base_currency'] ?? 'EUR')))) ?: 'EUR',
'preferred_currencies' => $preferredCurrencies,
'currency_catalog' => $currencyCatalog,
'currency_catalog_synced_at' => trim((string) ($saved['currency_catalog_synced_at'] ?? '')),
'daily_refresh_enabled' => array_key_exists('daily_refresh_enabled', $saved) ? (bool) $saved['daily_refresh_enabled'] : true,
'daily_refresh_hour' => max(0, min(23, (int) ($saved['daily_refresh_hour'] ?? 18))),
'schedule_timezone' => trim((string) ($saved['schedule_timezone'] ?? 'Europe/Berlin')) ?: 'Europe/Berlin',
@@ -81,6 +94,25 @@ $mm->registerFunction($moduleName, 'save_runtime_settings', static function (arr
), static fn (string $code): bool => $code !== '')));
}
$catalogCodes = [];
foreach (($normalized['currency_catalog'] ?? []) as $currency) {
if (is_array($currency)) {
$code = strtoupper(trim((string) ($currency['code'] ?? '')));
if ($code !== '') {
$catalogCodes[$code] = true;
}
}
}
if ($catalogCodes !== [] && !isset($catalogCodes[$normalized['display_base_currency']])) {
$normalized['display_base_currency'] = $normalized['default_base_currency'];
}
if ($catalogCodes !== []) {
$normalized['preferred_currencies'] = array_values(array_filter(
$normalized['preferred_currencies'],
static fn (string $code): bool => isset($catalogCodes[$code])
));
}
$toSave = array_merge($current, [
'default_base_currency' => $normalized['default_base_currency'],
'display_base_currency' => $normalized['display_base_currency'],
@@ -141,7 +173,14 @@ $mm->registerFunction($moduleName, 'setup_actions', static function (): array {
$mm->registerFunction($moduleName, 'run_setup_action', static function (string $action): array {
return match ($action) {
'sync_currency_catalog' => module_fn('fx-rates', 'service')->refreshCurrencyCatalog(),
'sync_currency_catalog' => (static function (): array {
$result = module_fn('fx-rates', 'service')->refreshCurrencyCatalog();
$current = modules()->settings('fx-rates');
$current['currency_catalog'] = array_values(is_array($result['currencies'] ?? null) ? $result['currencies'] : []);
$current['currency_catalog_synced_at'] = gmdate('Y-m-d H:i:s');
modules()->saveSettings('fx-rates', $current);
return $result + ['message' => 'Waehrungskatalog synchronisiert. ' . (int) ($result['synced_count'] ?? 0) . ' Waehrungen verarbeitet.'];
})(),
default => throw new \RuntimeException('Unbekannte Setup-Aktion.'),
};
});