From 9e687455fa4a7ab7e60e7c0d597f4936cb2fa83c Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Wed, 29 Apr 2026 01:57:49 +0200 Subject: [PATCH] sdadas --- modules/fx-rates/bootstrap.php | 52 +++++++++++++++++++++++-- modules/fx-rates/module.json | 3 +- partials/landingpages/modules/setup.php | 23 +++++++---- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/modules/fx-rates/bootstrap.php b/modules/fx-rates/bootstrap.php index 78815b4..9c17065 100644 --- a/modules/fx-rates/bootstrap.php +++ b/modules/fx-rates/bootstrap.php @@ -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.'), }; diff --git a/modules/fx-rates/module.json b/modules/fx-rates/module.json index 7300396..fd28973 100644 --- a/modules/fx-rates/module.json +++ b/modules/fx-rates/module.json @@ -1,6 +1,6 @@ { "title": "Waehrungskurse", - "version": "0.1.2", + "version": "0.1.3", "description": "Zentrales Modul fuer Waehrungskurse, Historie und API-Abrufe.", "enabled_by_default": true, "setup": { @@ -17,7 +17,6 @@ { "name": "api_url", "label": "FX API URL", "type": "text", "required": false, "help": "Nur die Basis-URL eintragen, z.B. https://api.currencyapi.com oder https://currencyapi.net." }, { "name": "api_key", "label": "FX API Key", "type": "password", "required": false }, { "name": "timeout_sec", "label": "Timeout (Sek.)", "type": "number", "required": false }, - { "name": "cache_ttl_sec", "label": "Datei-Cache TTL (Sek.)", "type": "number", "required": false }, { "name": "default_base_currency", "label": "Standard-Basiswaehrung", "type": "text", "required": false, "help": "Wird fuer taegliche Abrufe und Snapshot-Abfragen verwendet." }, { "name": "display_base_currency", "label": "Anzeige-Basiswaehrung", "type": "select", "required": false, "help": "Basis fuer die Anzeige der zuletzt gespeicherten Kurse im Modul." }, { "name": "preferred_currencies", "label": "Bevorzugte Waehrungen", "type": "multiselect", "required": false, "help": "Auswahl aus dem synchronisierten Waehrungskatalog." }, diff --git a/partials/landingpages/modules/setup.php b/partials/landingpages/modules/setup.php index b0b1193..fe8893b 100644 --- a/partials/landingpages/modules/setup.php +++ b/partials/landingpages/modules/setup.php @@ -579,7 +579,9 @@ $activeDbGroup = $testGroup !== null && array_key_exists($testGroup, $dbGroups)