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

This commit is contained in:
2026-04-29 01:57:49 +02:00
parent 00c879d029
commit 9e687455fa
3 changed files with 65 additions and 13 deletions

View File

@@ -32,7 +32,6 @@ $mm->registerFunction($moduleName, 'settings', static function (): array {
$apiUrl = rtrim((string) ($saved['api_url'] ?? (getenv('FX_RATES_API_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)));
$preferredCurrencies = $saved['preferred_currencies'] ?? ['EUR', 'USD', 'DOGE'];
if (is_string($preferredCurrencies)) {
@@ -61,7 +60,6 @@ $mm->registerFunction($moduleName, 'settings', static function (): array {
'api_url' => $apiUrl,
'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,
@@ -176,10 +174,56 @@ $mm->registerFunction($moduleName, 'run_setup_action', static function (string $
'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'] : []);
$catalog = [];
foreach (is_array($result['currencies'] ?? null) ? $result['currencies'] : [] as $item) {
if (!is_array($item)) {
continue;
}
$code = strtoupper(trim((string) ($item['code'] ?? '')));
$name = trim((string) ($item['name'] ?? ''));
if ($code === '' || $name === '') {
continue;
}
$catalog[$code] = ['code' => $code, 'name' => $name];
}
$latest = module_fn('fx-rates', 'service')->latestStatus();
if (is_array($latest) && !empty($latest['id'])) {
$snapshot = module_fn('fx-rates', 'snapshot', null, null, null, null);
$rates = is_array($snapshot['rates'] ?? null) ? $snapshot['rates'] : [];
foreach (array_keys($rates) as $code) {
$code = strtoupper(trim((string) $code));
if ($code !== '' && !isset($catalog[$code])) {
$catalog[$code] = ['code' => $code, 'name' => $code];
}
}
$baseCode = strtoupper(trim((string) ($snapshot['base_currency'] ?? '')));
if ($baseCode !== '' && !isset($catalog[$baseCode])) {
$catalog[$baseCode] = ['code' => $baseCode, 'name' => $baseCode];
}
}
foreach ([
(string) ($current['default_base_currency'] ?? ''),
(string) ($current['display_base_currency'] ?? ''),
...((is_array($current['preferred_currencies'] ?? null) ? $current['preferred_currencies'] : [])),
] as $code) {
$code = strtoupper(trim((string) $code));
if ($code !== '' && !isset($catalog[$code])) {
$catalog[$code] = ['code' => $code, 'name' => $code];
}
}
ksort($catalog);
$current['currency_catalog'] = array_values($catalog);
$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.'];
return $result + [
'currencies' => array_values($catalog),
'synced_count' => count($catalog),
'message' => 'Waehrungskatalog synchronisiert. ' . count($catalog) . ' Waehrungen verarbeitet.',
];
})(),
default => throw new \RuntimeException('Unbekannte Setup-Aktion.'),
};