adasd
This commit is contained in:
@@ -406,23 +406,32 @@ final class FxRatesService
|
|||||||
return $this->normalizeCurrencyApiComLatestPayload($payload, $baseCurrency, $currencies);
|
return $this->normalizeCurrencyApiComLatestPayload($payload, $baseCurrency, $currencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolvedBase = $baseCurrency;
|
||||||
$rates = [];
|
$rates = [];
|
||||||
if ($this->provider() === 'currencyapi') {
|
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)) {
|
if (($payload['valid'] ?? false) !== true || !is_array($payload['rates'] ?? null)) {
|
||||||
throw new \RuntimeException($this->extractProviderError($payload, 'FX-Kurse konnten nicht geladen werden.'));
|
throw new \RuntimeException($this->extractProviderError($payload, 'FX-Kurse konnten nicht geladen werden.'));
|
||||||
}
|
}
|
||||||
foreach ($payload['rates'] as $code => $rate) {
|
foreach ($payload['rates'] as $code => $rate) {
|
||||||
$code = $this->normalizeCurrency((string) $code);
|
$code = $this->normalizeCurrency((string) $code);
|
||||||
if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) {
|
if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$rates[$code] = (float) $rate;
|
$rates[$code] = (float) $rate;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$resolvedBase = $this->normalizeCurrency((string) ($payload['base'] ?? $payload['base_currency'] ?? $baseCurrency));
|
||||||
|
if ($resolvedBase === '') {
|
||||||
|
$resolvedBase = $baseCurrency;
|
||||||
|
}
|
||||||
$rawRates = is_array($payload['rates'] ?? null) ? $payload['rates'] : [];
|
$rawRates = is_array($payload['rates'] ?? null) ? $payload['rates'] : [];
|
||||||
foreach ($rawRates as $code => $rate) {
|
foreach ($rawRates as $code => $rate) {
|
||||||
$code = $this->normalizeCurrency((string) $code);
|
$code = $this->normalizeCurrency((string) $code);
|
||||||
if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) {
|
if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$rates[$code] = (float) $rate;
|
$rates[$code] = (float) $rate;
|
||||||
@@ -441,7 +450,7 @@ final class FxRatesService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'base' => $baseCurrency,
|
'base' => $resolvedBase,
|
||||||
'date' => $payload['updated'] ?? $payload['date'] ?? null,
|
'date' => $payload['updated'] ?? $payload['date'] ?? null,
|
||||||
'rates' => $rates,
|
'rates' => $rates,
|
||||||
];
|
];
|
||||||
@@ -706,7 +715,7 @@ final class FxRatesService
|
|||||||
{
|
{
|
||||||
$fromAt = $this->normalizeTimestamp($from);
|
$fromAt = $this->normalizeTimestamp($from);
|
||||||
$toAt = $this->normalizeTimestamp($to);
|
$toAt = $this->normalizeTimestamp($to);
|
||||||
$candidates = array_reverse($this->repository->listRecentFetches(max($limit * 4, 50)));
|
$candidates = $this->repository->listRecentFetches(max($limit * 4, 50));
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach ($candidates as $fetch) {
|
foreach ($candidates as $fetch) {
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ final class FxRatesRepository
|
|||||||
$params['to_at'] = $to;
|
$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);
|
$stmt = $this->pdo->prepare($sql);
|
||||||
foreach ($params as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
$stmt->bindValue(':' . $key, $value);
|
$stmt->bindValue(':' . $key, $value);
|
||||||
|
|||||||
@@ -173,8 +173,6 @@ if (preg_match('~^api/fx-rates(?:/(.*))?$~', $uriPath, $apiMatches)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once $projectRoot . '/modules/fx-rates/bootstrap.php';
|
require_once $projectRoot . '/modules/fx-rates/bootstrap.php';
|
||||||
app()->modules()->runDueIntervalTasks('fx-rates');
|
|
||||||
app()->modules()->runDueCronTasks('fx-rates');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$service = module_fn('fx-rates', 'service');
|
$service = module_fn('fx-rates', 'service');
|
||||||
@@ -261,8 +259,6 @@ if (str_starts_with($uriPath, 'modules/install')) {
|
|||||||
require_once $moduleBootstrap;
|
require_once $moduleBootstrap;
|
||||||
}
|
}
|
||||||
if ($modulePage) {
|
if ($modulePage) {
|
||||||
app()->modules()->runDueIntervalTasks($module);
|
|
||||||
app()->modules()->runDueCronTasks($module);
|
|
||||||
$target = $modulePage;
|
$target = $modulePage;
|
||||||
} else {
|
} else {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
|
|||||||
Reference in New Issue
Block a user