From c098413e2346540807caf046ece9c9dd632a6218 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sat, 2 May 2026 01:20:34 +0200 Subject: [PATCH] adasd --- modules/fx-rates/src/Domain/FxRatesService.php | 17 +++++++++++++---- .../src/Infrastructure/FxRatesRepository.php | 2 +- public/index.php | 4 ---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/fx-rates/src/Domain/FxRatesService.php b/modules/fx-rates/src/Domain/FxRatesService.php index 393cb93..86712e1 100644 --- a/modules/fx-rates/src/Domain/FxRatesService.php +++ b/modules/fx-rates/src/Domain/FxRatesService.php @@ -406,23 +406,32 @@ final class FxRatesService return $this->normalizeCurrencyApiComLatestPayload($payload, $baseCurrency, $currencies); } + $resolvedBase = $baseCurrency; $rates = []; if ($this->provider() === 'currencyapi') { + $resolvedBase = $this->normalizeCurrency((string) ($payload['base'] ?? $payload['base_currency'] ?? ($payload['query']['base_currency'] ?? 'USD'))); + if ($resolvedBase === '') { + $resolvedBase = 'USD'; + } if (($payload['valid'] ?? false) !== true || !is_array($payload['rates'] ?? null)) { throw new \RuntimeException($this->extractProviderError($payload, 'FX-Kurse konnten nicht geladen werden.')); } foreach ($payload['rates'] as $code => $rate) { $code = $this->normalizeCurrency((string) $code); - if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) { + if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) { continue; } $rates[$code] = (float) $rate; } } else { + $resolvedBase = $this->normalizeCurrency((string) ($payload['base'] ?? $payload['base_currency'] ?? $baseCurrency)); + if ($resolvedBase === '') { + $resolvedBase = $baseCurrency; + } $rawRates = is_array($payload['rates'] ?? null) ? $payload['rates'] : []; foreach ($rawRates as $code => $rate) { $code = $this->normalizeCurrency((string) $code); - if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) { + if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) { continue; } $rates[$code] = (float) $rate; @@ -441,7 +450,7 @@ final class FxRatesService } return [ - 'base' => $baseCurrency, + 'base' => $resolvedBase, 'date' => $payload['updated'] ?? $payload['date'] ?? null, 'rates' => $rates, ]; @@ -706,7 +715,7 @@ final class FxRatesService { $fromAt = $this->normalizeTimestamp($from); $toAt = $this->normalizeTimestamp($to); - $candidates = array_reverse($this->repository->listRecentFetches(max($limit * 4, 50))); + $candidates = $this->repository->listRecentFetches(max($limit * 4, 50)); $result = []; foreach ($candidates as $fetch) { diff --git a/modules/fx-rates/src/Infrastructure/FxRatesRepository.php b/modules/fx-rates/src/Infrastructure/FxRatesRepository.php index 89dff5e..bb0fa31 100644 --- a/modules/fx-rates/src/Infrastructure/FxRatesRepository.php +++ b/modules/fx-rates/src/Infrastructure/FxRatesRepository.php @@ -272,7 +272,7 @@ final class FxRatesRepository $params['to_at'] = $to; } - $sql .= ' ORDER BY f.fetched_at ASC, r.id ASC LIMIT :limit'; + $sql .= ' ORDER BY f.fetched_at DESC, r.id DESC LIMIT :limit'; $stmt = $this->pdo->prepare($sql); foreach ($params as $key => $value) { $stmt->bindValue(':' . $key, $value); diff --git a/public/index.php b/public/index.php index 235252b..a25a930 100755 --- a/public/index.php +++ b/public/index.php @@ -173,8 +173,6 @@ if (preg_match('~^api/fx-rates(?:/(.*))?$~', $uriPath, $apiMatches)) { } require_once $projectRoot . '/modules/fx-rates/bootstrap.php'; - app()->modules()->runDueIntervalTasks('fx-rates'); - app()->modules()->runDueCronTasks('fx-rates'); try { $service = module_fn('fx-rates', 'service'); @@ -261,8 +259,6 @@ if (str_starts_with($uriPath, 'modules/install')) { require_once $moduleBootstrap; } if ($modulePage) { - app()->modules()->runDueIntervalTasks($module); - app()->modules()->runDueCronTasks($module); $target = $modulePage; } else { http_response_code(404);