Add some event handlers.

This commit is contained in:
James Cole
2026-02-03 18:58:24 +01:00
parent 304fae439a
commit ebb6a186cc
3 changed files with 42 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* GenericDestroyService.php
* Copyright (c) 2026 james@firefly-iii.org
*
* 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();
}
}