Set user ID from object, fix #10891

This commit is contained in:
James Cole
2025-09-11 19:37:34 +02:00
parent c38c752520
commit deae94b658
3 changed files with 16 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use function Safe\json_decode;
/**
@@ -74,7 +75,7 @@ class DownloadExchangeRates implements ShouldQueue
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
app('log')->debug(sprintf('Created new DownloadExchangeRates("%s")', $this->date->format('Y-m-d')));
Log::debug(sprintf('Created new DownloadExchangeRates("%s")', $this->date->format('Y-m-d')));
}
}
@@ -83,7 +84,7 @@ class DownloadExchangeRates implements ShouldQueue
*/
public function handle(): void
{
app('log')->debug('Now in handle()');
Log::debug('Now in handle()');
$currencies = $this->repository->getCompleteSet();
/** @var TransactionCurrency $currency */
@@ -97,7 +98,7 @@ class DownloadExchangeRates implements ShouldQueue
*/
private function downloadRates(TransactionCurrency $currency): void
{
app('log')->debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code));
Log::debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code));
$base = sprintf('%s/%s/%s', (string) config('cer.url'), $this->date->year, $this->date->isoWeek);
$client = new Client();
$url = sprintf('%s/%s.json', $base, $currency->code);
@@ -105,20 +106,20 @@ class DownloadExchangeRates implements ShouldQueue
try {
$res = $client->get($url);
} catch (ConnectException|RequestException $e) {
app('log')->warning(sprintf('Trying to grab "%s" resulted in error "%s".', $url, $e->getMessage()));
Log::warning(sprintf('Trying to grab "%s" resulted in error "%s".', $url, $e->getMessage()));
return;
}
$statusCode = $res->getStatusCode();
if (200 !== $statusCode) {
app('log')->warning(sprintf('Trying to grab "%s" resulted in status code %d.', $url, $statusCode));
Log::warning(sprintf('Trying to grab "%s" resulted in status code %d.', $url, $statusCode));
return;
}
$body = (string) $res->getBody();
$json = json_decode($body, true);
if (false === $json || null === $json) {
app('log')->warning(sprintf('Trying to grab "%s" resulted in bad JSON.', $url));
Log::warning(sprintf('Trying to grab "%s" resulted in bad JSON.', $url));
return;
}
@@ -134,11 +135,11 @@ class DownloadExchangeRates implements ShouldQueue
foreach ($rates as $code => $rate) {
$to = $this->getCurrency($code);
if (!$to instanceof TransactionCurrency) {
app('log')->debug(sprintf('Currency %s is not in use, do not save rate.', $code));
Log::debug(sprintf('Currency %s is not in use, do not save rate.', $code));
continue;
}
app('log')->debug(sprintf('Currency %s is in use.', $code));
Log::debug(sprintf('Currency %s is in use.', $code));
$this->saveRate($currency, $to, $date, $rate);
}
}
@@ -147,25 +148,25 @@ class DownloadExchangeRates implements ShouldQueue
{
// if we have it already, don't bother searching for it again.
if (array_key_exists($code, $this->active)) {
app('log')->debug(sprintf('Already know what the result is of searching for %s', $code));
Log::debug(sprintf('Already know what the result is of searching for %s', $code));
return $this->active[$code];
}
// find it in the database.
$currency = $this->repository->findByCode($code);
if (!$currency instanceof TransactionCurrency) {
app('log')->debug(sprintf('Did not find currency %s.', $code));
Log::debug(sprintf('Did not find currency %s.', $code));
$this->active[$code] = null;
return null;
}
if (false === $currency->enabled) {
app('log')->debug(sprintf('Currency %s is not enabled.', $code));
Log::debug(sprintf('Currency %s is not enabled.', $code));
$this->active[$code] = null;
return null;
}
app('log')->debug(sprintf('Currency %s is enabled.', $code));
Log::debug(sprintf('Currency %s is enabled.', $code));
$this->active[$code] = $currency;
return $currency;
@@ -177,7 +178,7 @@ class DownloadExchangeRates implements ShouldQueue
$this->repository->setUser($user);
$existing = $this->repository->getExchangeRate($from, $to, $date);
if (!$existing instanceof CurrencyExchangeRate) {
app('log')->debug(sprintf('Saved rate from %s to %s for user #%d.', $from->code, $to->code, $user->id));
Log::debug(sprintf('Saved rate from %s to %s for user #%d.', $from->code, $to->code, $user->id));
$this->repository->setExchangeRate($from, $to, $date, $rate);
}
}

View File

@@ -373,7 +373,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return CurrencyExchangeRate::create(
[
'user_id' => $this->user->id,
'user_group_id' => $this->user->user_group_id,
'user_group_id' => $this->userGroup->id,
'from_currency_id' => $fromCurrency->id,
'to_currency_id' => $toCurrency->id,
'date' => $date,

View File

@@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- [Issue 10854](https://github.com/firefly-iii/firefly-iii/issues/10854) (string / null in budget causes budget page to not render) reported by @4e868df3
- [Discussion 10883](https://github.com/orgs/firefly-iii/discussions/10883) (Initial balance for account is missing from exported CSV) started by @ajaskiewiczpl
- #10888
- #10891
### API