Skip to content

Firefly III: a personal finances manager

Clean up events for groups.

James Cole97c9937571b7
diff --git a/app/Api/V1/Controllers/System/BatchController.php b/app/Api/V1/Controllers/System/BatchController.php
index 774c33e2fd..e0a693e726 100644
--- a/app/Api/V1/Controllers/System/BatchController.php
+++ b/app/Api/V1/Controllers/System/BatchController.php
@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\System;
use FireflyIII\Api\V1\Controllers\Controller;
-use FireflyIII\Events\Model\TransactionGroup\CreatedSingleTransactionGroup;
use FireflyIII\Events\Model\TransactionGroup\TransactionGroupEventFlags;
use FireflyIII\Events\Model\TransactionGroup\UserRequestedBatchProcessing;
use FireflyIII\Models\TransactionJournal;
@@ -53,14 +52,14 @@ class BatchController extends Controller
public function finishBatch(Request $request): JsonResponse
{
- $journals = $this->repository->getUncompletedJournals();
+ $journals = $this->repository->getUncompletedJournals();
if (0 === count($journals)) {
return response()->json([], 204);
}
/** @var TransactionJournal $first */
- $first = $journals->first();
- $group = $first?->transactionGroup;
+ $first = $journals->first();
+ $group = $first?->transactionGroup;
if (null === $group) {
return response()->json([], 204);
}
diff --git a/app/Events/Model/TransactionGroup/DestroyedSingleTransactionGroup.php b/app/Events/Model/TransactionGroup/DestroyedSingleTransactionGroup.php
new file mode 100644
index 0000000000..6ee5c7143d
--- /dev/null
+++ b/app/Events/Model/TransactionGroup/DestroyedSingleTransactionGroup.php
@@ -0,0 +1,37 @@
+<?php
+/*
+ * DestroyedSingleTransactionGroup.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\Events\Model\TransactionGroup;
+
+use FireflyIII\Events\Event;
+use FireflyIII\Models\TransactionGroup;
+use Illuminate\Queue\SerializesModels;
+
+class DestroyedSingleTransactionGroup extends Event
+{
+ use SerializesModels;
+
+ /**
+ * Create a new event instance.
+ */
+ public function __construct(public TransactionGroup $transactionGroup) {}
+}
+
diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php
index c8fcc2d560..1fd18acace 100644
--- a/app/Factory/TransactionJournalFactory.php
+++ b/app/Factory/TransactionJournalFactory.php
@@ -183,7 +183,6 @@ class TransactionJournalFactory
$carbon->setTimezone(config('app.timezone'));
// 2024-11-19, overrule timezone with UTC and store it as UTC.
-
if (true === FireflyConfig::get('utc', false)->data) {
$carbon->setTimezone('UTC');
}
diff --git a/app/Handlers/Events/PreferencesEventHandler.php b/app/Handlers/Events/PreferencesEventHandler.php
deleted file mode 100644
index 136f484fca..0000000000
--- a/app/Handlers/Events/PreferencesEventHandler.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-/*
- * PreferencesEventHandler.php
- * Copyright (c) 2024 [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/.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Handlers\Events;
-
-use FireflyIII\Events\Preferences\UserGroupChangedPrimaryCurrency;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\PiggyBank;
-use FireflyIII\Models\UserGroup;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
-use FireflyIII\Support\Facades\Amount;
-use Illuminate\Database\Query\Builder;
-use Illuminate\Support\Facades\Artisan;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
-
-class PreferencesEventHandler
-{
-
-
-
-
-
-}
diff --git a/app/Handlers/Events/UpdatedGroupEventHandler.php b/app/Handlers/Events/UpdatedGroupEventHandler.php
deleted file mode 100644
index a5ee0ff189..0000000000
--- a/app/Handlers/Events/UpdatedGroupEventHandler.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-
-/**
- * UpdatedGroupEventHandler.php
- * Copyright (c) 2019 [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/>.
- */
-declare(strict_types=1);
-
-namespace FireflyIII\Handlers\Events;
-
-use FireflyIII\Enums\WebhookTrigger;
-use FireflyIII\Events\Model\Webhook\WebhookMessagesRequestSending;
-use FireflyIII\Events\UpdatedTransactionGroup;
-use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
-use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Repositories\PeriodStatistic\PeriodStatisticRepositoryInterface;
-use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
-use FireflyIII\Services\Internal\Support\CreditRecalculateService;
-use FireflyIII\Support\Facades\FireflyConfig;
-use FireflyIII\Support\Models\AccountBalanceCalculator;
-use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
-use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Log;
-
-/**
- * Class UpdatedGroupEventHandler
- */
-class UpdatedGroupEventHandler
-{
- /**
- * TODO duplicate
- */
- private function removePeriodStatistics(UpdatedTransactionGroup $event): void
- {
- /** @var PeriodStatisticRepositoryInterface $repository */
- $repository = app(PeriodStatisticRepositoryInterface::class);
-
- /** @var TransactionJournal $journal */
- foreach ($event->transactionGroup->transactionJournals as $journal) {
- $source = $journal->transactions()->where('amount', '<', '0')->first();
- $dest = $journal->transactions()->where('amount', '>', '0')->first();
- if (null !== $source) {
- $repository->deleteStatisticsForModel($source->account, $journal->date);
- }
- if (null !== $dest) {
- $repository->deleteStatisticsForModel($dest->account, $journal->date);
- }
-
- $categories = $journal->categories;
- $tags = $journal->tags;
- $budgets = $journal->budgets;
-
- foreach ($categories as $category) {
- $repository->deleteStatisticsForModel($category, $journal->date);
- }
- foreach ($tags as $tag) {
- $repository->deleteStatisticsForModel($tag, $journal->date);
- }
- foreach ($budgets as $budget) {
- $repository->deleteStatisticsForModel($budget, $journal->date);
- }
- if (0 === $categories->count()) {
- $repository->deleteStatisticsForPrefix($journal->userGroup, 'no_category', $journal->date);
- }
- if (0 === $budgets->count()) {
- $repository->deleteStatisticsForPrefix($journal->userGroup, 'no_budget', $journal->date);
- }
- }
- }
-
-
-
-}
diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php
index f9ad0f36eb..8b25c96953 100644
--- a/app/Http/Controllers/Transaction/CreateController.php
+++ b/app/Http/Controllers/Transaction/CreateController.php
@@ -79,7 +79,6 @@ class CreateController extends Controller
// event!
$flags = new TransactionGroupEventFlags();
event(new CreatedSingleTransactionGroup($group, $flags));
- // event(new StoredTransactionGroup($newGroup, true, true));
Preferences::mark();
diff --git a/app/Handlers/Events/DestroyedGroupEventHandler.php b/app/Listeners/Model/TransactionGroup/ProcessesDestroyedTransactionGroup.php
similarity index 75%
rename from app/Handlers/Events/DestroyedGroupEventHandler.php
rename to app/Listeners/Model/TransactionGroup/ProcessesDestroyedTransactionGroup.php
index 2e6804256e..7dd11431b8 100644
--- a/app/Handlers/Events/DestroyedGroupEventHandler.php
+++ b/app/Listeners/Model/TransactionGroup/ProcessesDestroyedTransactionGroup.php
@@ -1,8 +1,7 @@
<?php
-
/*
- * DestroyedGroupEventHandler.php
- * Copyright (c) 2021 [email protected]
+ * ProcessesDestroyedTransactionGroup.php
+ * Copyright (c) 2026 [email protected]
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -20,35 +19,31 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-declare(strict_types=1);
-
-namespace FireflyIII\Handlers\Events;
+namespace FireflyIII\Listeners\Model\TransactionGroup;
use FireflyIII\Enums\WebhookTrigger;
-use FireflyIII\Events\DestroyedTransactionGroup;
+use FireflyIII\Events\Model\TransactionGroup\DestroyedSingleTransactionGroup;
use FireflyIII\Events\Model\Webhook\WebhookMessagesRequestSending;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
use FireflyIII\Support\Facades\FireflyConfig;
use FireflyIII\Support\Models\AccountBalanceCalculator;
+use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
-/**
- * Class DestroyedGroupEventHandler
- */
-class DestroyedGroupEventHandler
+class ProcessesDestroyedTransactionGroup implements ShouldQueue
{
- public function runAllHandlers(DestroyedTransactionGroup $event): void
+ public function handle(DestroyedSingleTransactionGroup $event): void
{
$this->triggerWebhooks($event);
$this->updateRunningBalance($event);
}
- private function triggerWebhooks(DestroyedTransactionGroup $destroyedGroupEvent): void
+ private function triggerWebhooks(DestroyedSingleTransactionGroup $destroyedGroupEvent): void
{
Log::debug('DestroyedTransactionGroup:triggerWebhooks');
- $group = $destroyedGroupEvent->transactionGroup;
- $user = $group->user;
+ $group = $destroyedGroupEvent->transactionGroup;
+ $user = $group->user;
/** @var MessageGeneratorInterface $engine */
$engine = app(MessageGeneratorInterface::class);
@@ -60,7 +55,7 @@ class DestroyedGroupEventHandler
event(new WebhookMessagesRequestSending());
}
- private function updateRunningBalance(DestroyedTransactionGroup $event): void
+ private function updateRunningBalance(DestroyedSingleTransactionGroup $event): void
{
if (false === FireflyConfig::get('use_running_balance', config('firefly.feature_flags.running_balance_column'))->data) {
return;
diff --git a/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php b/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
index c8b3a095d2..28dabd8ae7 100644
--- a/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
+++ b/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
@@ -94,7 +94,7 @@ class ProcessesNewTransactionGroup implements ShouldQueue
$this->fireWebhooks($set);
}
// always remove old relevant statistics.
- $this->removePeriodStatistics($set);
+ self::removePeriodStatistics($set);
// recalculate running balance if necessary.
if (true === FireflyConfig::get('use_running_balance', config('firefly.feature_flags.running_balance_column'))->data) {
diff --git a/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php b/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
index 541975cf62..30b671e550 100644
--- a/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
+++ b/app/Listeners/Model/TransactionGroup/ProcessesUpdatedTransactionGroup.php
@@ -25,7 +25,6 @@ use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Events\Model\TransactionGroup\UpdatedSingleTransactionGroup;
use FireflyIII\Events\Model\Webhook\WebhookMessagesRequestSending;
-use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Generator\Webhook\MessageGeneratorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
@@ -47,10 +46,8 @@ class ProcessesUpdatedTransactionGroup
$this->processRules($event);
$this->recalculateCredit($event);
$this->triggerWebhooks($event);
- $this->removePeriodStatistics($event);
- if ($event->flags->recalculateCredit) {
- $this->updateRunningBalance($event);
- }
+ ProcessesNewTransactionGroup::removePeriodStatistics($event->transactionGroup->transactionJournals);
+ $this->updateRunningBalance($event);
Log::debug('Done with handle() for UpdatedSingleTransactionGroup');
}
@@ -156,7 +153,7 @@ class ProcessesUpdatedTransactionGroup
}
- private function triggerWebhooks(UpdatedTransactionGroup $updatedGroupEvent): void
+ private function triggerWebhooks(UpdatedSingleTransactionGroup $updatedGroupEvent): void
{
Log::debug('Now in triggerWebhooks()');
$group = $updatedGroupEvent->transactionGroup;
@@ -179,7 +176,7 @@ class ProcessesUpdatedTransactionGroup
Log::debug('End of triggerWebhooks()');
}
- private function updateRunningBalance(UpdatedTransactionGroup $event): void
+ private function updateRunningBalance(UpdatedSingleTransactionGroup $event): void
{
Log::debug('Now in updateRunningBalance()');
if (false === FireflyConfig::get('use_running_balance', config('firefly.feature_flags.running_balance_column'))->data) {
diff --git a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
index a0928237da..73490f8741 100644
--- a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
+++ b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use FireflyIII\Events\DestroyedTransactionGroup;
+use FireflyIII\Events\Model\TransactionGroup\DestroyedSingleTransactionGroup;
use FireflyIII\Models\TransactionGroup;
use Illuminate\Support\Facades\Log;
@@ -44,6 +45,6 @@ class TransactionGroupDestroyService
}
$transactionGroup->delete();
// trigger just after destruction
- event(new DestroyedTransactionGroup($transactionGroup));
+ event(new DestroyedSingleTransactionGroup($transactionGroup));
}
}