mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Another fix for #2125
This commit is contained in:
parent
95720673d2
commit
fe738fd321
@ -22,10 +22,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support;
|
namespace FireflyIII\Support;
|
||||||
|
|
||||||
|
use Crypt;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
use Preferences as Prefs;
|
use Preferences as Prefs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,6 +224,23 @@ class Amount
|
|||||||
return $this->getDefaultCurrencyByUser($user);
|
return $this->getDefaultCurrencyByUser($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function tryDecrypt(string $value): string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$value = Crypt::decrypt($value);
|
||||||
|
} catch (DecryptException $e) {
|
||||||
|
Log::debug(sprintf('Could not decrypt. %s', $e->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
@ -237,9 +257,12 @@ class Amount
|
|||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$currencyPreference = Prefs::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
|
$currencyPreference = Prefs::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
|
||||||
$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
|
|
||||||
|
// at this point the currency preference could be encrypted, if coming from an old version.
|
||||||
|
$currencyCode = $this->tryDecrypt((string)$currencyPreference->data);
|
||||||
|
$currency = TransactionCurrency::where('code', $currencyCode)->first();
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
throw new FireflyException(sprintf('No currency found with code "%s"', $currencyPreference->data));
|
throw new FireflyException(sprintf('No currency found with code "%s"', $currencyCode));
|
||||||
}
|
}
|
||||||
$cache->store($currency);
|
$cache->store($currency);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user