mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Update command.
This commit is contained in:
@@ -57,9 +57,9 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
$this->deleteOrphanedJournals();
|
||||||
$this->deleteOrphanedTransactions();
|
$this->deleteOrphanedTransactions();
|
||||||
$this->deleteFromOrphanedAccounts();
|
$this->deleteFromOrphanedAccounts();
|
||||||
$this->deleteOrphanedJournals();
|
|
||||||
$end = round(microtime(true) - $start, 2);
|
$end = round(microtime(true) - $start, 2);
|
||||||
$this->info(sprintf('Verified orphans in %s seconds', $end));
|
$this->info(sprintf('Verified orphans in %s seconds', $end));
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
/** @var stdClass $entry */
|
/** @var stdClass $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$transaction = Transaction::find((int) $entry->transaction_id);
|
$transaction = Transaction::find((int) $entry->transaction_id);
|
||||||
|
if (null !== $transaction) {
|
||||||
$transaction->delete();
|
$transaction->delete();
|
||||||
$this->info(
|
$this->info(
|
||||||
sprintf(
|
sprintf(
|
||||||
@@ -96,6 +97,7 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
);
|
);
|
||||||
++$count;
|
++$count;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (0 === $count) {
|
if (0 === $count) {
|
||||||
$this->info('No orphaned transactions.');
|
$this->info('No orphaned transactions.');
|
||||||
}
|
}
|
||||||
@@ -146,18 +148,26 @@ class DeleteOrphanedTransactions extends Command
|
|||||||
::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||||
->whereNotNull('transaction_groups.deleted_at')
|
->whereNotNull('transaction_groups.deleted_at')
|
||||||
->whereNull('transaction_journals.deleted_at')
|
->whereNull('transaction_journals.deleted_at')
|
||||||
->get(['transaction_journals.id']);
|
->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']);
|
||||||
$count = $set->count();
|
$count = $set->count();
|
||||||
if (0 === $count) {
|
if (0 === $count) {
|
||||||
$this->info('No orphaned journals.');
|
$this->info('No orphaned journals.');
|
||||||
}
|
}
|
||||||
if ($count > 0) {
|
if ($count > 0) {
|
||||||
$this->info(sprintf('Found %d orphaned journal(s).', $count));
|
$this->info(sprintf('Found %d orphaned journal(s).', $count));
|
||||||
TransactionJournal
|
foreach ($set as $entry) {
|
||||||
::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
$journal = TransactionJournal::withTrashed()->find((int) $entry->id);
|
||||||
->whereNotNull('transaction_groups.deleted_at')
|
if (null !== $journal) {
|
||||||
->whereNull('transaction_journals.deleted_at')
|
$journal->delete();
|
||||||
->update(['transaction_journals.deleted_at', now()]);
|
$this->info(
|
||||||
|
sprintf(
|
||||||
|
'Journal #%d (part of deleted transaction group #%d) has been deleted as well.',
|
||||||
|
$entry->id,
|
||||||
|
$entry->transaction_group_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user