Skip to content

Firefly III: a personal finances manager

Add some debug for https://github.com/orgs/firefly-iii/discussions/12044

James Cole99912483de0f
diff --git a/app/Console/Commands/Correction/CorrectsGroupAccounts.php b/app/Console/Commands/Correction/CorrectsGroupAccounts.php
index b821b9c1cc..8d69249916 100644
--- a/app/Console/Commands/Correction/CorrectsGroupAccounts.php
+++ b/app/Console/Commands/Correction/CorrectsGroupAccounts.php
@@ -33,6 +33,7 @@ use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
class CorrectsGroupAccounts extends Command
{
@@ -46,6 +47,7 @@ class CorrectsGroupAccounts extends Command
*/
public function handle(): int
{
+ Log::debug('Start of correction:group-accounts');
$groups = [];
$res = TransactionJournal::groupBy('transaction_group_id')->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]);
@@ -64,9 +66,10 @@ class CorrectsGroupAccounts extends Command
$group = TransactionGroup::find($groupId);
$objects->appendFromTransactionGroup($group);
}
+ Log::debug(sprintf('Fire event for %d transaction group(s)', count($groups)));
event(new UpdatedSingleTransactionGroup($flags, $objects));
event(new WebhookMessagesRequestSending());
-
+ Log::debug('End of correction:group-accounts');
return 0;
}
}
diff --git a/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php b/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
index aeaa7eda21..46aa099edf 100644
--- a/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
+++ b/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
@@ -116,13 +116,25 @@ class ProcessesUpdatedTransactionGroup
$destAccount = $first->transactions()->where('amount', '>', '0')->first()->account;
$type = $first->transactionType->type;
+ $effect = 0;
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::WITHDRAWAL->value === $type) {
// set all source transactions to source account:
- Transaction::whereIn('transaction_journal_id', $all)->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id]);
+ $effect += Transaction::whereIn('transaction_journal_id', $all)
+ ->where('account_id', '!=', $sourceAccount->id)
+ ->where('amount', '<', 0)
+ ->update(['account_id' => $sourceAccount->id]);
}
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::DEPOSIT->value === $type) {
// set all destination transactions to destination account:
- Transaction::whereIn('transaction_journal_id', $all)->where('amount', '>', 0)->update(['account_id' => $destAccount->id]);
+ $effect += Transaction::whereIn('transaction_journal_id', $all)
+ ->where('account_id', '!=', $destAccount->id)
+ ->where('amount', '>', 0)
+ ->update(['account_id' => $destAccount->id]);
}
+ if(0 === $effect) {
+ Log::debug(sprintf('Had nothing to do in unifyAccounts(#%d)', $group->id));
+ return;
+ }
+ Log::debug(sprintf('Updated %d transaction(s) in unifyAccounts(#%d)', $effect, $group->id));
}
}