Skip to content

Firefly III: a personal finances manager

Add some event handlers.

James Coleebb6a186cc88
diff --git a/app/Console/Commands/Correction/CorrectsAmounts.php b/app/Console/Commands/Correction/CorrectsAmounts.php
index b2dcb794a5..021a466cbe 100644
--- a/app/Console/Commands/Correction/CorrectsAmounts.php
+++ b/app/Console/Commands/Correction/CorrectsAmounts.php
@@ -38,6 +38,8 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use FireflyIII\Services\Internal\Destroy\GenericDestroyService;
+use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
use Illuminate\Console\Command;
@@ -51,9 +53,13 @@ class CorrectsAmounts extends Command
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
protected $signature = 'correction:amounts';
+ private JournalDestroyService $service;
+ private GenericDestroyService $genericService;
public function handle(): int
{
+ $this->service = new JournalDestroyService();
+ $this->genericService = new GenericDestroyService();
// transfers must not have foreign currency info if both accounts have the same currency.
$this->correctTransfers();
// auto budgets must be positive
@@ -177,8 +183,7 @@ class CorrectsAmounts extends Command
private function deleteJournal(TransactionJournal $journal): void
{
- $journal->transactionGroup?->delete();
- $journal->delete();
+ $this->service->destroy($journal);
}
private function fixAutoBudgets(): void
@@ -282,7 +287,7 @@ class CorrectsAmounts extends Command
));
$item->rule->active = false;
$item->rule->save();
- $item->forceDelete();
+ $this->genericService->deleteRuleTrigger($item);
return false;
}
diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.php
index 537c3cd9a2..c338d05663 100644
--- a/app/Handlers/Observer/TransactionObserver.php
+++ b/app/Handlers/Observer/TransactionObserver.php
@@ -37,6 +37,7 @@ class TransactionObserver
public function created(Transaction $transaction): void
{
+ Log::debug(sprintf('Observed creation of Transaction #%d.', $transaction->id));
$this->updatePrimaryCurrencyAmount($transaction);
}
diff --git a/app/Services/Internal/Destroy/GenericDestroyService.php b/app/Services/Internal/Destroy/GenericDestroyService.php
new file mode 100644
index 0000000000..e9a4c2a732
--- /dev/null
+++ b/app/Services/Internal/Destroy/GenericDestroyService.php
@@ -0,0 +1,33 @@
+<?php
+/*
+ * GenericDestroyService.php
+ * Copyright (c) 2026 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Services\Internal\Destroy;
+
+use FireflyIII\Models\RuleTrigger;
+
+class GenericDestroyService
+{
+ public function deleteRuleTrigger(RuleTrigger $ruleTrigger): void
+ {
+ $ruleTrigger->forceDelete();
+ }
+
+}