mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Code cleanup.
This commit is contained in:
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Correction;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -43,8 +42,6 @@ class DeleteEmptyJournals extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -60,9 +57,11 @@ class DeleteEmptyJournals extends Command
|
||||
private function deleteUnevenJournals(): void
|
||||
{
|
||||
$set = Transaction::whereNull('deleted_at')
|
||||
->groupBy('transactions.transaction_journal_id')
|
||||
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); // @phpstan-ignore-line
|
||||
->groupBy('transactions.transaction_journal_id')
|
||||
->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line
|
||||
;
|
||||
$total = 0;
|
||||
|
||||
/** @var Transaction $row */
|
||||
foreach ($set as $row) {
|
||||
$count = (int)$row->the_count;
|
||||
@@ -75,12 +74,11 @@ class DeleteEmptyJournals extends Command
|
||||
app('log')->error($e->getTraceAsString());
|
||||
}
|
||||
|
||||
|
||||
Transaction::where('transaction_journal_id', $row->transaction_journal_id)->delete();
|
||||
$this->friendlyWarning(
|
||||
sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id)
|
||||
);
|
||||
$total++;
|
||||
++$total;
|
||||
}
|
||||
}
|
||||
if (0 === $total) {
|
||||
@@ -88,16 +86,14 @@ class DeleteEmptyJournals extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function deleteEmptyJournals(): void
|
||||
{
|
||||
$count = 0;
|
||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->whereNull('transactions.transaction_journal_id')
|
||||
->get(['transaction_journals.id']);
|
||||
->groupBy('transaction_journals.id')
|
||||
->whereNull('transactions.transaction_journal_id')
|
||||
->get(['transaction_journals.id'])
|
||||
;
|
||||
|
||||
foreach ($set as $entry) {
|
||||
try {
|
||||
@@ -107,7 +103,6 @@ class DeleteEmptyJournals extends Command
|
||||
app('log')->error($e->getTraceAsString());
|
||||
}
|
||||
|
||||
|
||||
$this->friendlyInfo(sprintf('Deleted empty transaction journal #%d', $entry->id));
|
||||
++$count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user