Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Replace lengthy notification calls, simplifies code.
James Cole4387876203c8
diff --git a/app/Handlers/Events/APIEventHandler.php b/app/Handlers/Events/APIEventHandler.phpindex cef3151394..756801f969 100644--- a/app/Handlers/Events/APIEventHandler.php+++ b/app/Handlers/Events/APIEventHandler.php@@ -25,6 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Handlers\Events;use Exception;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\NewAccessToken;use FireflyIII\Repositories\User\UserRepositoryInterface;use Illuminate\Support\Facades\Log;@@ -48,23 +49,7 @@ class APIEventHandler$user = $repository->find((int) $event->userId);if (null !== $user) {- try {- Notification::send($user, new NewAccessToken());- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new NewAccessToken());}}}diff --git a/app/Listeners/Model/Rule/NotifiesUserAboutFailedRuleAction.php b/app/Listeners/Model/Rule/NotifiesUserAboutFailedRuleAction.phpindex ad01387162..18d1c42f5a 100644--- a/app/Listeners/Model/Rule/NotifiesUserAboutFailedRuleAction.php+++ b/app/Listeners/Model/Rule/NotifiesUserAboutFailedRuleAction.php@@ -26,43 +26,37 @@ namespace FireflyIII\Listeners\Model\Rule;use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;use FireflyIII\Events\Model\Rule\RuleActionFailedOnObject;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\RuleActionFailed;use FireflyIII\Support\Facades\Preferences;-use GuzzleHttp\Exception\ClientException;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutFailedRuleAction implements ShouldQueue{- public function handle(RuleActionFailedOnArray|RuleActionFailedOnObject $event): void+ public function handle(RuleActionFailedOnArray | RuleActionFailedOnObject $event): void{- $ruleAction = $event->ruleAction;- $rule = $ruleAction->rule;+ $ruleAction = $event->ruleAction;+ $rule = $ruleAction->rule;/** @var bool $preference */- $preference = Preferences::getForUser($rule->user, 'notification_rule_action_failures', true)->data;+ $preference = Preferences::getForUser($rule->user, 'notification_rule_action_failures', true)->data;if (false === $preference) {return;}Log::debug('Now in ruleActionFailedOnArray');- $journal = $event->journal;- $error = $event->error;- $user = $ruleAction->rule->user;+ $journal = $event->journal;+ $error = $event->error;+ $user = $ruleAction->rule->user;- $groupId = is_array($journal) ? $journal['transaction_group_id'] : $journal->transaction_group_id;- $groupTitle = is_array($journal) ? $journal['description'] ?? '' : $journal->description ?? '';+ $groupId = is_array($journal) ? $journal['transaction_group_id'] : $journal->transaction_group_id;+ $groupTitle = is_array($journal) ? $journal['description'] ?? '' : $journal->description ?? '';- $mainMessage = trans('rules.main_message', ['rule' => $rule->title, 'action' => $ruleAction->action_type, 'group' => $groupId, 'error' => $error]);+ $mainMessage = trans('rules.main_message', ['rule' => $rule->title, 'action' => $ruleAction->action_type, 'group' => $groupId, 'error' => $error]);$groupLink = route('transactions.show', [$groupId]);$ruleTitle = $rule->title;$ruleLink = route('rules.edit', [$rule->id]);$params = [$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink];-- try {- Notification::send($user, new RuleActionFailed($params));- } catch (ClientException $e) {- Log::error(sprintf('[a] Error sending notification that the rule action failed: %s', $e->getMessage()));- }+ NotificationSender::send($user, new RuleActionFailed($params));}}diff --git a/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php b/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.phpindex 83e47b250d..48cbcf20a4 100644--- a/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php+++ b/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php@@ -24,13 +24,12 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Model\Subscription;-use Exception;use FireflyIII\Events\Model\Subscription\SubscriptionNeedsExtensionOrRenewal;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\BillReminder;use FireflyIII\Support\Facades\Preferences;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesAboutExtensionOrRenewal implements ShouldQueue{@@ -40,29 +39,11 @@ class NotifiesAboutExtensionOrRenewal implements ShouldQueue$subscription = $event->subscription;/** @var bool $preference */- $preference = Preferences::getForUser($subscription->user, 'notification_bill_reminder', true)->data;+ $preference = Preferences::getForUser($subscription->user, 'notification_bill_reminder', true)->data;if (true === $preference) {Log::debug('Subscription reminder is true!');-- try {- Notification::send($subscription->user, new BillReminder($subscription, $event->field, $event->diff));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }-+ NotificationSender::send($subscription->user, new BillReminder($subscription, $event->field, $event->diff));return;}Log::debug('User has disabled subscription reminders.');diff --git a/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php b/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.phpindex dff98da630..f58c35b43b 100644--- a/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php+++ b/app/Listeners/Model/Subscription/NotifiesAboutOverdueSubscriptions.php@@ -24,14 +24,13 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Model\Subscription;-use Exception;use FireflyIII\Events\Model\Subscription\SubscriptionsAreOverdueForPayment;use FireflyIII\Models\Bill;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\SubscriptionsOverdueReminder;use FireflyIII\Support\Facades\Preferences;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesAboutOverdueSubscriptions implements ShouldQueue{@@ -39,15 +38,15 @@ class NotifiesAboutOverdueSubscriptions implements ShouldQueue{Log::debug(sprintf('Now in %s', __METHOD__));// make sure user does not get the warning twice.- $overdue = $event->overdue;- $user = $event->user;- $toBeWarned = [];+ $overdue = $event->overdue;+ $user = $event->user;+ $toBeWarned = [];Log::debug(sprintf('%d subscriptions to warn about.', count($overdue)));foreach ($overdue as $item) {/** @var Bill $bill */- $bill = $item['bill'];- $key = sprintf('bill_overdue_%s_%s', $bill->id, substr(hash('sha256', json_encode($item['dates']['pay_dates'], JSON_THROW_ON_ERROR)), 0, 10));- $pref = Preferences::getForUser($bill->user, $key, false);+ $bill = $item['bill'];+ $key = sprintf('bill_overdue_%s_%s', $bill->id, substr(hash('sha256', json_encode($item['dates']['pay_dates'], JSON_THROW_ON_ERROR)), 0, 10));+ $pref = Preferences::getForUser($bill->user, $key, false);if (true === $pref->data) {Log::debug(sprintf('User #%d has already been warned about overdue subscription #%d.', $bill->user->id, $bill->id));@@ -78,23 +77,6 @@ class NotifiesAboutOverdueSubscriptions implements ShouldQueuePreferences::setForUser($bill->user, $key, true);}Log::warning('should hit this ONCE');-- try {- Notification::send($user, new SubscriptionsOverdueReminder($toBeWarned));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new SubscriptionsOverdueReminder($toBeWarned));}}diff --git a/app/Listeners/Model/TransactionGroup/MailsNewTransactionsReport.php b/app/Listeners/Model/TransactionGroup/MailsNewTransactionsReport.phpindex 76db071b43..711b0ebc08 100644--- a/app/Listeners/Model/TransactionGroup/MailsNewTransactionsReport.php+++ b/app/Listeners/Model/TransactionGroup/MailsNewTransactionsReport.php@@ -24,16 +24,15 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Model\TransactionGroup;-use Exception;use FireflyIII\Events\Model\TransactionGroup\TransactionGroupsRequestedReporting;use FireflyIII\Models\TransactionGroup;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\TransactionCreation;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\Support\Facades\Preferences;use FireflyIII\Transformers\TransactionGroupTransformer;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class MailsNewTransactionsReport implements ShouldQueue{@@ -42,11 +41,11 @@ class MailsNewTransactionsReport implements ShouldQueueLog::debug('In MailsNewTransactionsReport.');/** @var UserRepositoryInterface $repository */- $repository = app(UserRepositoryInterface::class);- $user = $repository->find($event->userId);+ $repository = app(UserRepositoryInterface::class);+ $user = $repository->find($event->userId);/** @var bool $sendReport */- $sendReport = Preferences::getForUser($user, 'notification_transaction_creation', false)->data;+ $sendReport = Preferences::getForUser($user, 'notification_transaction_creation', false)->data;if (false === $sendReport) {Log::debug('Not sending report, because config says so.');@@ -71,23 +70,7 @@ class MailsNewTransactionsReport implements ShouldQueue$groups[] = $transformer->transformObject($group);}- try {- Notification::send($user, new TransactionCreation($groups));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new TransactionCreation($groups));Log::debug('If there is no error above this line, message was sent.');}}diff --git a/app/Listeners/Security/System/HandlesNewUserRegistration.php b/app/Listeners/Security/System/HandlesNewUserRegistration.phpindex 1cd9406958..12196df639 100644--- a/app/Listeners/Security/System/HandlesNewUserRegistration.php+++ b/app/Listeners/Security/System/HandlesNewUserRegistration.php@@ -25,7 +25,6 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\System;use Database\Seeders\ExchangeRateSeeder;-use Exception;use FireflyIII\Enums\UserRoleEnum;use FireflyIII\Events\Security\System\NewUserRegistered;use FireflyIII\Exceptions\FireflyException;@@ -34,6 +33,7 @@ use FireflyIII\Models\UserGroup;use FireflyIII\Models\UserRole;use FireflyIII\Notifications\Admin\UserRegistration as AdminRegistrationNotification;use FireflyIII\Notifications\Notifiables\OwnerNotifiable;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\User\UserRegistration as UserRegistrationNotification;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\Support\Facades\FireflyConfig;@@ -70,12 +70,12 @@ class HandlesNewUserRegistration implements ShouldQueue*/private function createGroupMembership(User $user): void{- $groupExists = true;- $groupTitle = $user->email;- $index = 1;+ $groupExists = true;+ $groupTitle = $user->email;+ $index = 1;/** @var null|UserGroup $group */- $group = null;+ $group = null;// create a new group.while ($groupExists) { // @phpstan-ignore-line@@ -85,7 +85,7 @@ class HandlesNewUserRegistration implements ShouldQueuebreak;}- $groupTitle = sprintf('%s-%d', $user->email, $index);+ $groupTitle = sprintf('%s-%d', $user->email, $index);++$index;if ($index > 99) {throw new FireflyException('Email address can no longer be used for registrations.');@@ -93,11 +93,11 @@ class HandlesNewUserRegistration implements ShouldQueue}/** @var null|UserRole $role */- $role = UserRole::where('title', UserRoleEnum::OWNER->value)->first();+ $role = UserRole::where('title', UserRoleEnum::OWNER->value)->first();if (null === $role) {throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');}- GroupMembership::create(['user_id' => $user->id, 'user_group_id' => $group->id, 'user_role_id' => $role->id]);+ GroupMembership::create(['user_id' => $user->id, 'user_group_id' => $group->id, 'user_role_id' => $role->id]);$user->user_group_id = $group->id;$user->save();}@@ -113,53 +113,20 @@ class HandlesNewUserRegistration implements ShouldQueueprivate function sendAdminRegistrationNotification(User $user, OwnerNotifiable $owner): void{- $sendMail = (bool) FireflyConfig::get('notification_admin_new_reg', true)->data;+ $sendMail = (bool)FireflyConfig::get('notification_admin_new_reg', true)->data;if (!$sendMail) {return;}-- try {- Notification::send($owner, new AdminRegistrationNotification($user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($owner, new AdminRegistrationNotification($user));}private function sendRegistrationMail(User $user): void{- $sendMail = (bool) FireflyConfig::get('notification_user_new_reg', true)->data;+ $sendMail = (bool)FireflyConfig::get('notification_user_new_reg', true)->data;if (!$sendMail) {return;}- try {- Notification::send($user, new UserRegistrationNotification());- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new UserRegistrationNotification());}}diff --git a/app/Listeners/Security/System/NotifiesAboutNewInvitation.php b/app/Listeners/Security/System/NotifiesAboutNewInvitation.phpindex 6236dff522..b6e5a02054 100644--- a/app/Listeners/Security/System/NotifiesAboutNewInvitation.php+++ b/app/Listeners/Security/System/NotifiesAboutNewInvitation.php@@ -31,6 +31,7 @@ use FireflyIII\Mail\InvitationMail;use FireflyIII\Models\InvitedUser;use FireflyIII\Notifications\Admin\UserInvitation;use FireflyIII\Notifications\Notifiables\OwnerNotifiable;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Support\Facades\FireflyConfig;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;@@ -68,22 +69,6 @@ class NotifiesAboutNewInvitation implements ShouldQueuereturn;}- try {- Notification::send(new OwnerNotifiable(), new UserInvitation($invitee));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send(new OwnerNotifiable(), new UserInvitation($invitee));}}diff --git a/app/Listeners/Security/System/NotifiesOwnerAboutNewVersion.php b/app/Listeners/Security/System/NotifiesOwnerAboutNewVersion.phpindex d2c5d18f2d..b5552011e2 100644--- a/app/Listeners/Security/System/NotifiesOwnerAboutNewVersion.php+++ b/app/Listeners/Security/System/NotifiesOwnerAboutNewVersion.php@@ -24,13 +24,12 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\System;-use Exception;use FireflyIII\Events\Security\System\SystemFoundNewVersionOnline;use FireflyIII\Notifications\Admin\VersionCheckResult;use FireflyIII\Notifications\Notifiables\OwnerNotifiable;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Support\Facades\FireflyConfig;use Illuminate\Contracts\Queue\ShouldQueue;-use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Notification;class NotifiesOwnerAboutNewVersion implements ShouldQueue@@ -42,23 +41,7 @@ class NotifiesOwnerAboutNewVersion implements ShouldQueuereturn;}- try {- $owner = new OwnerNotifiable();- Notification::send($owner, new VersionCheckResult($event->message));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ $owner = new OwnerNotifiable();+ NotificationSender ::send($owner, new VersionCheckResult($event->message));}}diff --git a/app/Listeners/Security/System/NotifiesOwnerAboutUnknownUser.php b/app/Listeners/Security/System/NotifiesOwnerAboutUnknownUser.phpindex 3274c54dab..341a1ecf26 100644--- a/app/Listeners/Security/System/NotifiesOwnerAboutUnknownUser.php+++ b/app/Listeners/Security/System/NotifiesOwnerAboutUnknownUser.php@@ -24,35 +24,17 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\System;-use Exception;use FireflyIII\Events\Security\System\UnknownUserTriedLogin;use FireflyIII\Notifications\Admin\UnknownUserLoginAttempt;use FireflyIII\Notifications\Notifiables\OwnerNotifiable;+use FireflyIII\Notifications\NotificationSender;use Illuminate\Contracts\Queue\ShouldQueue;-use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesOwnerAboutUnknownUser implements ShouldQueue{public function handle(UnknownUserTriedLogin $event): void{- try {- $owner = new OwnerNotifiable();- Notification::send($owner, new UnknownUserLoginAttempt($event->address));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ $owner = new OwnerNotifiable();+ NotificationSender::send($owner, new UnknownUserLoginAttempt($event->address));}}diff --git a/app/Listeners/Security/User/NotifiesUserAboutDisabledMFA.php b/app/Listeners/Security/User/NotifiesUserAboutDisabledMFA.phpindex b15722d29c..ccabc9fd8b 100644--- a/app/Listeners/Security/User/NotifiesUserAboutDisabledMFA.php+++ b/app/Listeners/Security/User/NotifiesUserAboutDisabledMFA.php@@ -24,37 +24,17 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\User;-use Exception;use FireflyIII\Events\Security\User\UserHasDisabledMFA;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\Security\DisabledMFANotification;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutDisabledMFA implements ShouldQueue{public function handle(UserHasDisabledMFA $event): void{Log::debug(sprintf('Now in %s', __METHOD__));-- $user = $event->user;-- try {- Notification::send($user, new DisabledMFANotification($user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($event->user, new DisabledMFANotification($event->user));}}diff --git a/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.php b/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.phpindex 77514feb58..f47d21e730 100644--- a/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.php+++ b/app/Listeners/Security/User/NotifiesUserAboutEnabledMFA.php@@ -24,12 +24,11 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\User;-use Exception;use FireflyIII\Events\Security\User\UserHasEnabledMFA;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\Security\EnabledMFANotification;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutEnabledMFA implements ShouldQueue{@@ -38,23 +37,6 @@ class NotifiesUserAboutEnabledMFA implements ShouldQueueLog::debug(sprintf('Now in %s', __METHOD__));$user = $event->user;-- try {- Notification::send($user, new EnabledMFANotification($user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new EnabledMFANotification($user));}}diff --git a/app/Listeners/Security/User/NotifiesUserAboutFailedLogin.php b/app/Listeners/Security/User/NotifiesUserAboutFailedLogin.phpindex 31fb468c04..3885f9ba0c 100644--- a/app/Listeners/Security/User/NotifiesUserAboutFailedLogin.php+++ b/app/Listeners/Security/User/NotifiesUserAboutFailedLogin.php@@ -24,32 +24,15 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\User;-use Exception;use FireflyIII\Events\Security\User\UserFailedLoginAttempt;+use FireflyIII\Notifications\NotificationSender;+use FireflyIII\Notifications\Security\UserFailedLoginAttempt as NotificationFailedLoginAttempt;use Illuminate\Contracts\Queue\ShouldQueue;-use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutFailedLogin implements ShouldQueue{public function handle(UserFailedLoginAttempt $event): void{- try {- Notification::send($event->user, new \FireflyIII\Notifications\Security\UserFailedLoginAttempt($event->user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($event->user, new NotificationFailedLoginAttempt($event->user));}}diff --git a/app/Listeners/Security/User/NotifiesUserAboutFewCodesLeft.php b/app/Listeners/Security/User/NotifiesUserAboutFewCodesLeft.phpindex 877532922e..281bb52b91 100644--- a/app/Listeners/Security/User/NotifiesUserAboutFewCodesLeft.php+++ b/app/Listeners/Security/User/NotifiesUserAboutFewCodesLeft.php@@ -24,12 +24,11 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\User;-use Exception;use FireflyIII\Events\Security\User\UserHasFewMFABackupCodesLeft;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\Security\MFABackupFewLeftNotification;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutFewCodesLeft implements ShouldQueue{@@ -39,23 +38,6 @@ class NotifiesUserAboutFewCodesLeft implements ShouldQueue$user = $event->user;$count = $event->count;-- try {- Notification::send($user, new MFABackupFewLeftNotification($user, $count));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new MFABackupFewLeftNotification($user, $count));}}diff --git a/app/Listeners/Security/User/NotifiesUserAboutNewBackupCodes.php b/app/Listeners/Security/User/NotifiesUserAboutNewBackupCodes.phpindex 119ceb583c..7e39614b57 100644--- a/app/Listeners/Security/User/NotifiesUserAboutNewBackupCodes.php+++ b/app/Listeners/Security/User/NotifiesUserAboutNewBackupCodes.php@@ -24,37 +24,18 @@ declare(strict_types=1);namespace FireflyIII\Listeners\Security\User;-use Exception;use FireflyIII\Events\Security\User\UserHasGeneratedNewBackupCodes;+use FireflyIII\Notifications\NotificationSender;use FireflyIII\Notifications\Security\NewBackupCodesNotification;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Support\Facades\Log;-use Illuminate\Support\Facades\Notification;class NotifiesUserAboutNewBackupCodes implements ShouldQueue{public function handle(UserHasGeneratedNewBackupCodes $event): void{Log::debug(sprintf('Now in %s', __METHOD__));-$user = $event->user;-- try {- Notification::send($user, new NewBackupCodesNotification($user));- } catch (Exception $e) {- $message = $e->getMessage();- if (str_contains($message, 'Bcc')) {- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- if (str_contains($message, 'RFC 2822')) {- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');-- return;- }- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- }+ NotificationSender::send($user, new NewBackupCodesNotification($user));}}diff --git a/app/Notifications/NotificationSender.php b/app/Notifications/NotificationSender.phpnew file mode 100644index 0000000000..61b97d8b8c--- /dev/null+++ b/app/Notifications/NotificationSender.php@@ -0,0 +1,56 @@+<?php+/*+ * NotificationSender.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\Notifications;++use Exception;+use FireflyIII\Notifications\Notifiables\OwnerNotifiable;+use FireflyIII\User;+use GuzzleHttp\Exception\ClientException;+use Illuminate\Notifications\Notification;+use Illuminate\Support\Facades\Log;+use Illuminate\Support\Facades\Notification as NotificationFacade;++class NotificationSender+{+ public static function send(OwnerNotifiable|User $user, Notification $notification): void+ {+ try {+ NotificationFacade::send($user, $notification);+ } catch (ClientException $e) {+ Log::error(sprintf('[a] Error sending notification: %s', $e->getMessage()));+ } catch (Exception $e) {+ $message = $e->getMessage();+ if (str_contains($message, 'Bcc')) {+ Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');++ return;+ }+ if (str_contains($message, 'RFC 2822')) {+ Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');++ return;+ }+ Log::error($e->getMessage());+ Log::error($e->getTraceAsString());+ }+ }+}