From d2b6829574010937550ffbd4f50ed38d762f6607 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 Jan 2025 19:05:24 +0100 Subject: [PATCH] First fixes for level 7. --- app/Console/Commands/Correction/CorrectsAccountTypes.php | 1 + app/Console/Commands/Correction/CorrectsNativeAmounts.php | 3 ++- app/Console/Commands/Correction/RemovesEmptyJournals.php | 4 +++- .../Commands/Correction/RemovesOrphanedTransactions.php | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/Correction/CorrectsAccountTypes.php b/app/Console/Commands/Correction/CorrectsAccountTypes.php index a57d54f233..dc3ae1927f 100644 --- a/app/Console/Commands/Correction/CorrectsAccountTypes.php +++ b/app/Console/Commands/Correction/CorrectsAccountTypes.php @@ -111,6 +111,7 @@ class CorrectsAccountTypes extends Command $this->friendlyLine(sprintf('Found %d journals that need to be fixed.', $resultSet->count())); foreach ($resultSet as $entry) { app('log')->debug(sprintf('Now fixing journal #%d', $entry->id)); + /** @var null|TransactionJournal $journal */ $journal = TransactionJournal::find($entry->id); if (null !== $journal) { $this->inspectJournal($journal); diff --git a/app/Console/Commands/Correction/CorrectsNativeAmounts.php b/app/Console/Commands/Correction/CorrectsNativeAmounts.php index 39d05a5bd3..12b9e96cfe 100644 --- a/app/Console/Commands/Correction/CorrectsNativeAmounts.php +++ b/app/Console/Commands/Correction/CorrectsNativeAmounts.php @@ -236,8 +236,9 @@ class CorrectsNativeAmounts extends Command TransactionObserver::$recalculate = false; foreach ($set as $item) { // here we are. + /** @var Transaction|null $transaction */ $transaction = Transaction::find($item->id); - $transaction->touch(); + $transaction?->touch(); } TransactionObserver::$recalculate = true; Log::debug(sprintf('Recalculated %d transactions.', $set->count())); diff --git a/app/Console/Commands/Correction/RemovesEmptyJournals.php b/app/Console/Commands/Correction/RemovesEmptyJournals.php index cbb6c6c3e7..229ab1c1d9 100644 --- a/app/Console/Commands/Correction/RemovesEmptyJournals.php +++ b/app/Console/Commands/Correction/RemovesEmptyJournals.php @@ -66,7 +66,9 @@ class RemovesEmptyJournals extends Command if (1 === $count % 2) { // uneven number, delete journal and transactions: try { - TransactionJournal::find($row->transaction_journal_id)->delete(); + /** @var TransactionJournal|null $journal */ + $journal = TransactionJournal::find($row->transaction_journal_id); + $journal?->delete(); } catch (QueryException $e) { app('log')->info(sprintf('Could not delete journal: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); diff --git a/app/Console/Commands/Correction/RemovesOrphanedTransactions.php b/app/Console/Commands/Correction/RemovesOrphanedTransactions.php index 700ca259cf..9a94395192 100644 --- a/app/Console/Commands/Correction/RemovesOrphanedTransactions.php +++ b/app/Console/Commands/Correction/RemovesOrphanedTransactions.php @@ -69,6 +69,7 @@ class RemovesOrphanedTransactions extends Command } $this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count)); foreach ($set as $entry) { + /** @var TransactionJournal|null $journal */ $journal = TransactionJournal::withTrashed()->find($entry->id); if (null !== $journal) { $journal->delete(); @@ -130,6 +131,7 @@ class RemovesOrphanedTransactions extends Command /** @var Transaction $transaction */ foreach ($set as $transaction) { // delete journals + /** @var TransactionJournal|null $journal */ $journal = TransactionJournal::find($transaction->transaction_journal_id); if (null !== $journal) { $journal->delete();