ddfsdfdf
This commit is contained in:
@@ -194,7 +194,7 @@ final class FxRatesService
|
||||
return $amount * (float) $rate['rate'];
|
||||
}
|
||||
|
||||
public function refreshLatestRates(?array $currencies = null, ?string $baseCurrency = null): array
|
||||
public function refreshLatestRates(?array $currencies = null, ?string $baseCurrency = null, string $triggerSource = 'manual'): array
|
||||
{
|
||||
$requestedBase = $this->normalizeCurrency($baseCurrency ?: $this->defaultBaseCurrency());
|
||||
$payload = $this->fetchLatestPayload($requestedBase, null);
|
||||
@@ -209,7 +209,8 @@ final class FxRatesService
|
||||
$this->provider(),
|
||||
$rateDate,
|
||||
$rates,
|
||||
gmdate('Y-m-d H:i:s')
|
||||
gmdate('Y-m-d H:i:s'),
|
||||
$triggerSource
|
||||
);
|
||||
|
||||
return [
|
||||
@@ -223,7 +224,7 @@ final class FxRatesService
|
||||
];
|
||||
}
|
||||
|
||||
public function ensureFreshLatestRates(float $maxAgeHours = 24.0, ?string $baseCurrency = null, ?array $currencies = null): array
|
||||
public function ensureFreshLatestRates(float $maxAgeHours = 24.0, ?string $baseCurrency = null, ?array $currencies = null, string $triggerSource = 'manual'): array
|
||||
{
|
||||
$base = $this->normalizeCurrency($baseCurrency ?: $this->defaultBaseCurrency());
|
||||
$latest = $this->repository->getLatestFetch($base);
|
||||
@@ -242,16 +243,16 @@ final class FxRatesService
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->refreshLatestRates($currencies, $base);
|
||||
$result = $this->refreshLatestRates($currencies, $base, $triggerSource);
|
||||
$result['reused'] = false;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function autoRefreshLatestRates(?string $baseCurrency = null, ?array $currencies = null, ?int $maxAgeMinutes = null): array
|
||||
public function autoRefreshLatestRates(?string $baseCurrency = null, ?array $currencies = null, ?int $maxAgeMinutes = null, string $triggerSource = 'api'): array
|
||||
{
|
||||
$minutes = $maxAgeMinutes ?? $this->refreshMaxAgeMinutes();
|
||||
$hours = max(1, $minutes) / 60;
|
||||
return $this->ensureFreshLatestRates($hours, $baseCurrency, $currencies);
|
||||
return $this->ensureFreshLatestRates($hours, $baseCurrency, $currencies, $triggerSource);
|
||||
}
|
||||
|
||||
public function history(string $fromCurrency, string $toCurrency, ?string $from = null, ?string $to = null, int $limit = 200): array
|
||||
@@ -302,7 +303,8 @@ final class FxRatesService
|
||||
|
||||
public function runScheduledRefresh(array $context = []): array
|
||||
{
|
||||
$result = $this->refreshLatestRates(null, $this->defaultBaseCurrency());
|
||||
$triggerSource = ($context['trigger'] ?? null) === 'manual_test' ? 'manual' : 'cron';
|
||||
$result = $this->refreshLatestRates(null, $this->defaultBaseCurrency(), $triggerSource);
|
||||
return [
|
||||
'ok' => true,
|
||||
'message' => 'Geplanter FX-Abruf ausgefuehrt: ' . (int) ($result['updated_count'] ?? 0) . ' Kurse gespeichert.',
|
||||
@@ -751,6 +753,7 @@ final class FxRatesService
|
||||
|
||||
$fetch['fetched_at_display'] = $this->formatDisplayTimestamp($fetch['fetched_at'] ?? null);
|
||||
$fetch['created_at_display'] = $this->formatDisplayTimestamp($fetch['created_at'] ?? null);
|
||||
$fetch['trigger_source_label'] = $this->triggerSourceLabel((string) ($fetch['trigger_source'] ?? 'manual'));
|
||||
return $fetch;
|
||||
}
|
||||
|
||||
@@ -962,4 +965,13 @@ final class FxRatesService
|
||||
{
|
||||
return $this->scheduleTimezone();
|
||||
}
|
||||
|
||||
private function triggerSourceLabel(string $source): string
|
||||
{
|
||||
return match (strtolower(trim($source))) {
|
||||
'cron' => 'Cron',
|
||||
'api' => 'API',
|
||||
default => 'Manuell',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user