Last attempt I hope for #2125

This commit is contained in:
James Cole 2019-02-28 19:56:41 +01:00
parent 39321b320e
commit 3379b723cf

View File

@ -224,23 +224,6 @@ class Amount
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
*
@ -260,7 +243,13 @@ class Amount
// 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();
// could still be json encoded:
if (\strlen($currencyCode) > 3) {
$currencyCode = null === json_decode($currencyCode) ? 'EUR' : $currencyCode;
}
$currency = TransactionCurrency::where('code', $currencyCode)->first();
if (null === $currency) {
throw new FireflyException(sprintf('No currency found with code "%s"', $currencyCode));
}
@ -288,4 +277,20 @@ class Amount
'zero' => $positive,
];
}
/**
* @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;
}
}