This commit is contained in:
James Cole
2025-12-06 07:32:43 +01:00
parent a93f2d66af
commit 5b395d870b

View File

@@ -40,7 +40,7 @@ class RemovesLinksToDeletedObjects extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'correction:remove-links-to-deleted-objects'; protected $signature = 'correction:remove-links-to-deleted-objects';
/** /**
* The console command description. * The console command description.
@@ -86,17 +86,27 @@ class RemovesLinksToDeletedObjects extends Command
private function cleanupJournals(array $journals): void private function cleanupJournals(array $journals): void
{ {
$count = DB::table('tag_transaction_journal')->whereIn('transaction_journal_id', $journals)->delete(); $countTags = 0;
if ($count > 0) { $countBudgets= 0;
$this->friendlyInfo(sprintf('Removed %d old relationship(s) between tags and transactions.', $count)); $countCategories = 0;
// #11333
foreach (array_chunk($journals, 1337) as $set) {
$countTags += DB::table('tag_transaction_journal')->whereIn('transaction_journal_id', $set)->delete();
$countBudgets += DB::table('budget_transaction_journal')->whereIn('transaction_journal_id', $set)->delete();
$countCategories += DB::table('category_transaction_journal')->whereIn('transaction_journal_id', $set)->delete();
} }
$count = DB::table('budget_transaction_journal')->whereIn('transaction_journal_id', $journals)->delete();
if ($count > 0) {
$this->friendlyInfo(sprintf('Removed %d old relationship(s) between budgets and transactions.', $count));
if ($countTags > 0) {
$this->friendlyInfo(sprintf('Removed %d old relationship(s) between tags and transactions.', $countTags));
} }
$count = DB::table('category_transaction_journal')->whereIn('transaction_journal_id', $journals)->delete();
if ($count > 0) { if ($countBudgets > 0) {
$this->friendlyInfo(sprintf('Removed %d old relationship(s) categories and transactions.', $count)); $this->friendlyInfo(sprintf('Removed %d old relationship(s) between budgets and transactions.', $countBudgets));
}
if ($countCategories > 0) {
$this->friendlyInfo(sprintf('Removed %d old relationship(s) categories and transactions.', $countCategories));
} }
} }