diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index bb96f18643..dcaebf9050 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -102,18 +102,25 @@ class UpgradeDatabase extends Command /** @var PiggyBankEvent $event */ foreach ($set as $event) { - if (!is_null($event->transaction_journal_id)) { - $type = $event->transactionJournal->transactionType->type; - if ($type !== TransactionType::TRANSFER) { - $event->transaction_journal_id = null; - $event->save(); - $this->line( - sprintf('Piggy bank #%d ("%s") was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id, + if (is_null($event->transaction_journal_id)) { + continue; + } + /** @var TransactionJournal $journal */ + $journal = $event->transactionJournal()->first(); + if (is_null($journal)) { + continue; + } + + $type = $journal->transactionType->type; + if ($type !== TransactionType::TRANSFER) { + $event->transaction_journal_id = null; + $event->save(); + $this->line( + sprintf( + 'Piggy bank #%d ("%s") was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id, $event->piggyBank->name - )); - } - - + ) + ); } } }