From 6e12f434ad149cc34d6ed79b5410aa92f45f2672 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 5 Mar 2019 16:55:03 +0100 Subject: [PATCH] Fix issue #2144 --- app/Console/Commands/DecryptDatabase.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Console/Commands/DecryptDatabase.php b/app/Console/Commands/DecryptDatabase.php index 672dbe7db0..5885712bc2 100644 --- a/app/Console/Commands/DecryptDatabase.php +++ b/app/Console/Commands/DecryptDatabase.php @@ -26,6 +26,8 @@ namespace FireflyIII\Console\Commands; use Crypt; use DB; +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Models\Preference; use FireflyIII\Support\Facades\FireflyConfig; use Illuminate\Console\Command; use Illuminate\Contracts\Encryption\DecryptException; @@ -86,6 +88,22 @@ class DecryptDatabase extends Command } $id = $row->id; $value = $this->tryDecrypt($original); + + // A separate routine for preferences: + if ('preferences' === $table) { + // try to json_decrypt the value. + $value = json_decode($value, true) ?? $value; + Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, print_r($value, true), $table, $id)); + + /** @var Preference $object */ + $object = Preference::find((int)$id); + if (null !== $object) { + $object->data = $value; + $object->save(); + } + continue; + } + if ($value !== $original) { Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, $value, $table, $id)); DB::table($table)->where('id', $id)->update([$field => $value]); @@ -130,6 +148,9 @@ class DecryptDatabase extends Command try { $value = Crypt::decrypt($value); } catch (DecryptException $e) { + if ('The MAC is invalid.' === $e->getMessage()) { + throw new FireflyException($e->getMessage()); + } Log::debug(sprintf('Could not decrypt. %s', $e->getMessage())); }