mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
fix: replace console messages with unified command.
This commit is contained in:
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Console\Commands\Correction;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -34,6 +35,8 @@ use stdClass;
|
||||
*/
|
||||
class DeleteOrphanedTransactions extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
@@ -80,7 +83,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
$journal->delete();
|
||||
}
|
||||
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
|
||||
$this->line(
|
||||
$this->friendlyWarning(
|
||||
sprintf(
|
||||
'Deleted transaction journal #%d because account #%d was already deleted.',
|
||||
$transaction->transaction_journal_id,
|
||||
@@ -90,7 +93,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
$count++;
|
||||
}
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: no orphaned accounts.');
|
||||
$this->friendlyPositive('No orphaned accounts.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,22 +105,21 @@ class DeleteOrphanedTransactions extends Command
|
||||
->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']);
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: no orphaned journals.');
|
||||
$this->friendlyPositive('No orphaned journals.');
|
||||
return;
|
||||
}
|
||||
if ($count > 0) {
|
||||
$this->info(sprintf('Found %d orphaned journal(s).', $count));
|
||||
foreach ($set as $entry) {
|
||||
$journal = TransactionJournal::withTrashed()->find((int)$entry->id);
|
||||
if (null !== $journal) {
|
||||
$journal->delete();
|
||||
$this->info(
|
||||
sprintf(
|
||||
'Journal #%d (part of deleted transaction group #%d) has been deleted as well.',
|
||||
$entry->id,
|
||||
$entry->transaction_group_id
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count));
|
||||
foreach ($set as $entry) {
|
||||
$journal = TransactionJournal::withTrashed()->find((int)$entry->id);
|
||||
if (null !== $journal) {
|
||||
$journal->delete();
|
||||
$this->friendlyWarning(
|
||||
sprintf(
|
||||
'Journal #%d (part of deleted transaction group #%d) has been deleted as well.',
|
||||
$entry->id,
|
||||
$entry->transaction_group_id
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +145,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
$transaction = Transaction::find((int)$entry->transaction_id);
|
||||
if (null !== $transaction) {
|
||||
$transaction->delete();
|
||||
$this->info(
|
||||
$this->friendlyWarning(
|
||||
sprintf(
|
||||
'Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.',
|
||||
$entry->transaction_id,
|
||||
@@ -154,7 +156,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
}
|
||||
}
|
||||
if (0 === $count) {
|
||||
$this->info('Correct: no orphaned transactions.');
|
||||
$this->friendlyPositive('No orphaned transactions.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user