Skip to content

Firefly III: a personal finances manager

Another fix for #2125

James Colefe738fd321b1
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index bfa19e8bc2..a29381a460 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -22,10 +22,13 @@ declare(strict_types=1);
namespace FireflyIII\Support;
+use Crypt;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
+use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection;
+use Log;
use Preferences as Prefs;
/**
@@ -221,6 +224,23 @@ 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
*
@@ -237,9 +257,12 @@ class Amount
return $cache->get(); // @codeCoverageIgnore
}
$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) {
- 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);