This fixes possible null errors.

This commit is contained in:
James Cole 2017-04-08 18:00:45 +02:00
parent db46d450bf
commit 6b9c9458fa
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -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
));
}
)
);
}
}
}