Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Merge branch 'develop' into 5.8-dev
James Cole416fe0c147f6
diff --cc app/Handlers/Events/APIEventHandler.phpindex bbfdd150bd,b3fdd0222c..400c0fdca1--- a/app/Handlers/Events/APIEventHandler.php+++ b/app/Handlers/Events/APIEventHandler.php@@@ -26,7 -26,7 +26,10 @@@ namespace FireflyIII\Handlers\Eventsuse Exception;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Mail\AccessTokenCreatedMail;++use FireflyIII\Notifications\Admin\TestNotification;++use FireflyIII\Notifications\User\NewAccessToken;use FireflyIII\Repositories\User\UserRepositoryInterface;++use Illuminate\Support\Facades\Notification;use Laravel\Passport\Events\AccessTokenCreated;use Log;use Mail;@@@ -42,45 -42,44 +45,18 @@@ class APIEventHandle** @param AccessTokenCreated $event*-- * @return bool* @throws FireflyException- * @deprecated*/-- public function accessTokenCreated(AccessTokenCreated $event): bool++ public function accessTokenCreated(AccessTokenCreated $event): void{++ Log::debug(__METHOD__);/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);$user = $repository->find((int) $event->userId);-- if (null !== $user) {-- $email = $user->email;---- // if user is demo user, send to owner:-- if ($user->hasRole('demo')) {-- $email = config('firefly.site_owner');-- }---- // see if user has alternative email address:-- $pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');-- if (null !== $pref) {-- $email = (string) (is_array($pref->data) ? $email : $pref->data);-- }---- Log::debug(sprintf('Now in APIEventHandler::accessTokenCreated. Email is %s', $email));-- try {-- Log::debug('Trying to send message...');-- Mail::to($email)->send(new AccessTokenCreatedMail);-- } catch (Exception $e) { // @phpstan-ignore-line-- Log::debug('Send message failed! :(');-- Log::error($e->getMessage());-- Log::error($e->getTraceAsString());-- Session::flash('error', 'Possible email error: ' . $e->getMessage());-- }---- Log::debug('If no error above this line, message was sent.');++ if (null !== $user) {++ Notification::send($user, new NewAccessToken);}---- return true;}}diff --cc app/Handlers/Events/AdminEventHandler.phpindex f158b96f4d,d35ab1c2c4..ffa5094deb--- a/app/Handlers/Events/AdminEventHandler.php+++ b/app/Handlers/Events/AdminEventHandler.php@@@ -44,18 -42,44 +44,16 @@@ class AdminEventHandle* @param AdminRequestedTestMessage $event** @return bool- * @throws FireflyException*/-- public function sendTestMessage(AdminRequestedTestMessage $event): bool++ public function sendTestMessage(AdminRequestedTestMessage $event): void{/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);- // do some validation.+- // is user even admin?- if ($repository->hasRole($event->user, 'owner')) {- $email = $event->user->email;-- // if user is demo user, send to owner:- if ($event->user->hasRole('demo')) {- $email = config('firefly.site_owner');- }-- // see if user has alternative email address:- $pref = app('preferences')->getForUser($event->user, 'remote_guard_alt_email');- if (null !== $pref) {- $email = $pref->data;- }-- Log::debug(sprintf('Now in sendTestMessage event handler. Email is %s', $email));- try {- Log::debug('Trying to send message...');- Mail::to($email)->send(new AdminTestMail($email));-- // Laravel cannot pretend this process failed during testing.- } catch (Exception $e) { // @phpstan-ignore-line- Log::debug('Send message failed! :(');- Log::error($e->getMessage());- Log::error($e->getTraceAsString());- Session::flash('error', 'Possible email error: ' . $e->getMessage());- }-- Log::debug('If no error above this line, message was sent.');+ if (!$repository->hasRole($event->user, 'owner')) {- return true;++ return;}- return true;+ Notification::send($event->user, new TestNotification($event->user->email));-- return true;}}diff --cc app/Handlers/Events/AutomationHandler.phpindex 4ec1d9725f,cd72404822..4b048c126c--- a/app/Handlers/Events/AutomationHandler.php+++ b/app/Handlers/Events/AutomationHandler.php@@@ -27,7 -27,7 +27,12 @@@ use Exceptionuse FireflyIII\Events\RequestedReportOnJournals;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Mail\ReportNewJournalsMail;++use FireflyIII\Models\TransactionGroup;++use FireflyIII\Notifications\User\NewAccessToken;++use FireflyIII\Notifications\User\TransactionCreation;use FireflyIII\Repositories\User\UserRepositoryInterface;++use FireflyIII\Transformers\TransactionGroupTransformer;++use Illuminate\Support\Facades\Notification;use Log;use Mail;@@@ -41,36 -41,35 +46,31 @@@ class AutomationHandle* Respond to the creation of X journals.** @param RequestedReportOnJournals $event-- *-- * @return bool- * @deprecated*/-- public function reportJournals(RequestedReportOnJournals $event): bool++ public function reportJournals(RequestedReportOnJournals $event): void{++ Log::debug('In reportJournals.');$sendReport = config('firefly.send_report_journals');--if (false === $sendReport) {-- return true;++ return;}-- Log::debug('In reportJournals.');/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);$user = $repository->find($event->userId);-- if (null !== $user && 0 !== $event->groups->count()) {-- try {-- Log::debug('Trying to mail...');-- Mail::to($user->email)->send(new ReportNewJournalsMail($event->groups));---- } catch (Exception $e) { // @phpstan-ignore-line-- Log::debug('Send message failed! :(');-- Log::error($e->getMessage());-- Log::error($e->getTraceAsString());-- }++ if (null === $user || 0 === $event->groups->count()) {++ return;++ }-- Log::debug('Done!');++ // transform groups into array:++ /** @var TransactionGroupTransformer $transformer */++ $transformer = app(TransactionGroupTransformer::class);++ $groups = [];++ /** @var TransactionGroup $group */++ foreach ($event->groups as $group) {++ $groups[] = $transformer->transformObject($group);}-- return true;++ Notification::send($user, new TransactionCreation($groups));}}diff --cc app/Handlers/Events/BillEventHandler.phpindex 8c275137c7,21b04d7cce..d13bce080e--- a/app/Handlers/Events/BillEventHandler.php+++ b/app/Handlers/Events/BillEventHandler.php@@@ -39,8 -37,7 +39,6 @@@ class BillEventHandle/*** @param WarnUserAboutBill $event* @return void-- * @throws \FireflyIII\Exceptions\FireflyException- * @deprecated*/public function warnAboutBill(WarnUserAboutBill $event): void{diff --cc app/Handlers/Events/UserEventHandler.phpindex aea2e8a5c1,2d8c2ca22d..96d5fab0ff--- a/app/Handlers/Events/UserEventHandler.php+++ b/app/Handlers/Events/UserEventHandler.php@@@ -33,16 -32,16 +33,18 @@@ use FireflyIII\Events\RequestedNewPasswuse FireflyIII\Events\UserChangedEmail;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Mail\ConfirmEmailChangeMail;--use FireflyIII\Mail\NewIPAddressWarningMail;use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;use FireflyIII\Mail\UndoEmailChangeMail;use FireflyIII\Models\GroupMembership;use FireflyIII\Models\UserGroup;use FireflyIII\Models\UserRole;++use FireflyIII\Notifications\User\UserLogin;++use FireflyIII\Notifications\User\UserNewPassword;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\User;use Illuminate\Auth\Events\Login;++use Illuminate\Support\Facades\Notification;use Log;use Mail;@@@ -62,7 -61,7 +64,7 @@@ class UserEventHandle** @return bool*/-- public function attachUserRole(RegisteredUser $event): bool++ public function attachUserRole(RegisteredUser $event): void{/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);@@@ -72,19 -71,8 +74,16 @@@Log::debug('User count is one, attach role.');$repository->attachRole($event->user, 'owner');}-- return true;+ }- return true;+ /**+ * @param RegisteredUser $event+ * @return bool+ */- public function createExchangeRates(RegisteredUser $event): bool {++ public function createExchangeRates(RegisteredUser $event): void++ {+ $seeder = new ExchangeRateSeeder;+ $seeder->run();-- return true;}/**@@@ -94,7 -82,7 +93,7 @@@** @return bool*/-- public function checkSingleUserIsAdmin(Login $event): bool++ public function checkSingleUserIsAdmin(Login $event): void{/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);@@@ -117,8 -105,8 +116,6 @@@// give user the role$repository->attachRole($user, 'owner');}---- return true;}/**@@@ -127,7 -115,7 +124,7 @@@* @return bool* @throws FireflyException*/-- public function createGroupMembership(RegisteredUser $event): bool++ public function createGroupMembership(RegisteredUser $event): void{$user = $event->user;$groupExists = true;@@@ -160,8 -148,8 +157,6 @@@);$user->user_group_id = $group->id;$user->save();---- return true;}/**@@@ -172,7 -160,7 +167,7 @@@* @return bool* @throws FireflyException*/-- public function demoUserBackToEnglish(Login $event): bool++ public function demoUserBackToEnglish(Login $event): void{/** @var UserRepositoryInterface $repository */$repository = app(UserRepositoryInterface::class);@@@ -185,8 -173,8 +180,6 @@@app('preferences')->setForUser($user, 'locale', 'equal');app('preferences')->mark();}---- return true;}/**@@@ -207,21 -194,21 +199,10 @@@$list = app('preferences')->getForUser($user, 'login_ip_history', [])->data;-- // see if user has alternative email address:-- $pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');-- if (null !== $pref) {-- $email = $pref->data;-- }--/** @var array $entry */foreach ($list as $index => $entry) {if (false === $entry['notified']) {-- try {-- Mail::to($email)->send(new NewIPAddressWarningMail($ipAddress));---- } catch (Exception $e) { // @phpstan-ignore-line-- Log::error($e->getMessage());-- }++ Notification::send($user, new UserLogin($ipAddress));}$list[$index]['notified'] = true;}@@@ -230,41 -217,39 +211,38 @@@}/**-- * Send email to confirm email change.++ * Send email to confirm email change. Will not be made into a notification, because++ * this requires some custom fields from the user and not just the "user" object.** @param UserChangedEmail $event*-- * @return bool* @throws FireflyException- * @deprecated*/-- public function sendEmailChangeConfirmMail(UserChangedEmail $event): bool++ public function sendEmailChangeConfirmMail(UserChangedEmail $event): void{$newEmail = $event->newEmail;$oldEmail = $event->oldEmail;$user = $event->user;$token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid');$url = route('profile.confirm-email-change', [$token->data]);++try {Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url));} catch (Exception $e) { // @phpstan-ignore-lineLog::error($e->getMessage());}---- return true;}/**-- * Send email to be able to undo email change.++ * Send email to be able to undo email change. Will not be made into a notification, because++ * this requires some custom fields from the user and not just the "user" object.** @param UserChangedEmail $event*-- * @return bool* @throws FireflyException- * @deprecated*/-- public function sendEmailChangeUndoMail(UserChangedEmail $event): bool++ public function sendEmailChangeUndoMail(UserChangedEmail $event): void{$newEmail = $event->newEmail;$oldEmail = $event->oldEmail;@@@ -278,53 -263,52 +256,36 @@@} catch (Exception $e) { // @phpstan-ignore-lineLog::error($e->getMessage());}---- return true;}/*** Send a new password to the user.- * @deprecated- ** @param RequestedNewPassword $event-- *-- * @return bool*/-- public function sendNewPassword(RequestedNewPassword $event): bool++ public function sendNewPassword(RequestedNewPassword $event): void{-- $email = $event->user->email;-- $ipAddress = $event->ipAddress;-- $token = $event->token;---- $url = route('password.reset', [$token]);---- // send email.-- try {-- Mail::to($email)->send(new RequestedNewPasswordMail($url, $ipAddress));---- } catch (Exception $e) { // @phpstan-ignore-line-- Log::error($e->getMessage());-- }---- return true;++ Notification::send($event->user, new UserNewPassword(route('password.reset', [$event->token])));}/*** This method will send the user a registration mail, welcoming him or her to Firefly III.* This message is only sent when the configuration of Firefly III says so.*++ * TODO this is an admin setting not a variable. Fix that first.++ ** @param RegisteredUser $event** @return bool- * @deprecated* @throws FireflyException++ * @deprecated*/-- public function sendRegistrationMail(RegisteredUser $event): bool++ public function sendRegistrationMail(RegisteredUser $event): void{$sendMail = config('firefly.send_registration_mail');if ($sendMail) {// get the email address-- $email = $event->user->email;-- $url = route('index');++ $email = $event->user->email;++ $url = route('index');// see if user has alternative email address:$pref = app('preferences')->getForUser($event->user, 'remote_guard_alt_email');@@@ -341,8 -325,8 +302,6 @@@}}---- return true;}/**@@@ -355,7 -339,7 +314,7 @@@$user = $event->user;/** @var array $preference */-- if($user->hasRole('demo')) {++ if ($user->hasRole('demo')) {Log::debug('Do not log demo user logins');return;}diff --cc app/Jobs/CreateRecurringTransactions.phpindex f9ea125eab,f9ea125eab..3078879c27--- a/app/Jobs/CreateRecurringTransactions.php+++ b/app/Jobs/CreateRecurringTransactions.php@@@ -380,13 -380,13 +380,19 @@@ class CreateRecurringTransactions imple// create transaction array and send to factory.$groupTitle = null;-- if ($recurrence->recurrenceTransactions->count() > 1) {++ $count = $recurrence->recurrenceTransactions->count();++ if ($count > 1) {/** @var RecurrenceTransaction $first */$first = $recurrence->recurrenceTransactions()->first();$groupTitle = $first->description;}++ if(0 === $count) {++ Log::error('No transactions to be created in this recurrence. Cannot continue.');++++ return null;++ }$array = ['user' => $recurrence->user_id,diff --cc app/Notifications/User/NewAccessToken.phpindex fe0969443b,0000000000..30ead2627fmode 100644,000000..100644--- a/app/Notifications/User/NewAccessToken.php+++ b/app/Notifications/User/NewAccessToken.php@@@ -1,81 -1,0 +1,78 @@@+<?php+declare(strict_types=1);+/*+ * NewAccessToken.php+ * Copyright (c) 2022 [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\User;++use Illuminate\Bus\Queueable;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;++class NewAccessToken extends Notification+{+ use Queueable;+- private string $address;-+ /**+ * Create a new notification instance.+ *+ * @return void+ */- public function __construct(string $address)++ public function __construct()+ {- $this->address = $address;+ }++ /**+ * Get the notification's delivery channels.+ *+ * @param mixed $notifiable+ * @return array+ */+ public function via($notifiable)+ {+ return ['mail'];+ }++ /**+ * Get the mail representation of the notification.+ *+ * @param mixed $notifiable+ * @return \Illuminate\Notifications\Messages\MailMessage+ */+ public function toMail($notifiable)+ {+ return (new MailMessage)- ->markdown('emails.admin-test', ['email' => $this->address])- ->subject((string) trans('email.admin_test_subject'));++ ->markdown('emails.token-created')++ ->subject((string) trans('email.access_token_created_subject'));+ }++ /**+ * Get the array representation of the notification.+ *+ * @param mixed $notifiable+ * @return array+ */+ public function toArray($notifiable)+ {+ return [+ //+ ];+ }+}diff --cc app/Notifications/User/TransactionCreation.phpindex a276ab1397,0000000000..d197b674e8mode 100644,000000..100644--- a/app/Notifications/User/TransactionCreation.php+++ b/app/Notifications/User/TransactionCreation.php@@@ -1,28 -1,0 +1,82 @@@+<?php+declare(strict_types=1);+/*+ * TransactionCreation.php+ * Copyright (c) 2022 [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\User;+- class TransactionCreation++use Illuminate\Bus\Queueable;++use Illuminate\Notifications\Messages\MailMessage;++use Illuminate\Notifications\Notification;++use Illuminate\Support\Collection;++++class TransactionCreation extends Notification+{++ use Queueable;++++ private array $collection;++++ /**++ * Create a new notification instance.++ *++ * @return void++ */++ public function __construct(array $collection)++ {++ $this->collection = $collection;++ }++++ /**++ * Get the notification's delivery channels.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function via($notifiable)++ {++ return ['mail'];++ }++++ /**++ * Get the mail representation of the notification.++ *++ * @param mixed $notifiable++ * @return \Illuminate\Notifications\Messages\MailMessage++ */++ public function toMail($notifiable)++ {++ return (new MailMessage)++ ->markdown('emails.report-new-journals', ['transformed' => $this->collection])++ ->subject((string) trans_choice('email.new_journals_subject', count($this->collection)));++ }+++ /**++ * Get the array representation of the notification.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function toArray($notifiable)++ {++ return [++ //++ ];++ }+}diff --cc app/Notifications/User/UserLogin.phpindex 2ef8758af0,0000000000..382c02cff5mode 100644,000000..100644--- a/app/Notifications/User/UserLogin.php+++ b/app/Notifications/User/UserLogin.php@@@ -1,28 -1,0 +1,94 @@@+<?php+declare(strict_types=1);+/*+ * UserLogin.php+ * Copyright (c) 2022 [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\User;+- class UserLogin++use Exception;++use Illuminate\Bus\Queueable;++use Illuminate\Notifications\Messages\MailMessage;++use Illuminate\Notifications\Notification;++++class UserLogin extends Notification+{++ use Queueable;++++ private string $ip;++++ /**++ * Create a new notification instance.++ *++ * @return void++ */++ public function __construct(string $ip)++ {++ $this->ip = $ip;++ }++++ /**++ * Get the notification's delivery channels.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function via($notifiable)++ {++ return ['mail'];++ }+++ /**++ * Get the mail representation of the notification.++ *++ * @param mixed $notifiable++ * @return \Illuminate\Notifications\Messages\MailMessage++ */++ public function toMail($notifiable)++ {++ $time = now(config('app.timezone'))->isoFormat((string) trans('config.date_time_js'));++ $host = '';++ try {++ $hostName = gethostbyaddr($this->ip);++ } catch (Exception $e) {++ $hostName = $this->ip;++ }++ if ($hostName !== $this->ip) {++ $host = $hostName;++ }++++ return (new MailMessage)++ ->markdown('emails.new-ip', ['time' => $time, 'ipAddress' => $this->ip, 'host' => $host])++ ->subject((string) trans('email.login_from_new_ip'));++ }++++ /**++ * Get the array representation of the notification.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function toArray($notifiable)++ {++ return [++ //++ ];++ }+}++diff --cc app/Notifications/User/UserNewPassword.phpindex 1322e112d3,0000000000..831669176cmode 100644,000000..100644--- a/app/Notifications/User/UserNewPassword.php+++ b/app/Notifications/User/UserNewPassword.php@@@ -1,28 -1,0 +1,81 @@@+<?php+declare(strict_types=1);+/*+ * UserNewPassword.php+ * Copyright (c) 2022 [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\User;+- class UserNewPassword++use Illuminate\Bus\Queueable;++use Illuminate\Notifications\Messages\MailMessage;++use Illuminate\Notifications\Notification;++++class UserNewPassword extends Notification+{++ use Queueable;++++ private string $url;++++ /**++ * Create a new notification instance.++ *++ * @return void++ */++ public function __construct(string $url)++ {++ $this->url = $url;++ }++++ /**++ * Get the notification's delivery channels.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function via($notifiable)++ {++ return ['mail'];++ }++++ /**++ * Get the mail representation of the notification.++ *++ * @param mixed $notifiable++ * @return \Illuminate\Notifications\Messages\MailMessage++ */++ public function toMail($notifiable)++ {++ return (new MailMessage)++ ->markdown('emails.password', ['url' => $this->url])++ ->subject((string) trans('email.reset_pw_subject'));++ }+++ /**++ * Get the array representation of the notification.++ *++ * @param mixed $notifiable++ * @return array++ */++ public function toArray($notifiable)++ {++ return [++ //++ ];++ }+}diff --cc app/Providers/EventServiceProvider.phpindex 7930b77611,c8f9302154..1b9e3c2f33--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@@ -159,60 -152,11 +159,57 @@@ class EventServiceProvider extends Serv}/**-- *++ * TODO needs a dedicated method.+ */+ protected function registerBudgetEvents(): void+ {+ $func = static function (BudgetLimit $limit) {+ Log::debug('Trigger budget limit event.');+ // find available budget with same period and same currency or create it.+ // then set it or add money:+ $user = $limit->budget->user;+ $availableBudget = $user+ ->availableBudgets()+ ->where('start_date', $limit->start_date->format('Y-m-d'))+ ->where('end_date', $limit->end_date->format('Y-m-d'))+ ->where('transaction_currency_id', $limit->transaction_currency_id)+ ->first();+ // update!+ if (null !== $availableBudget) {++ $repository = app(BudgetLimitRepositoryInterface::class);+ $repository->setUser($user);+ $set = $repository->getAllBudgetLimitsByCurrency($limit->transactionCurrency, $limit->start_date, $limit->end_date);+ $sum = (string) $set->sum('amount');+++ Log::debug(sprintf('Because budget limit #%d had its amount changed to %s, available budget limit #%d will be updated.', $limit->id, $limit->amount, $availableBudget->id));+ $availableBudget->amount = $sum;+ $availableBudget->save();+ return;+ }+ Log::debug('Does not exist, create it.');+ // create it.+ $data = [+ 'amount' => $limit->amount,+ 'start' => $limit->start_date,+ 'end' => $limit->end_date,+ 'currency_id' => $limit->transaction_currency_id,+ ];+ $repository = app(AvailableBudgetRepositoryInterface::class);+ $repository->setUser($user);+ $repository->store($data);+ };++ BudgetLimit::created($func);+ BudgetLimit::updated($func);+ }++ /**- *++ * TODO needs a dedicated (static) method.*/protected function registerCreateEvents(): void{---- // in case of repeated piggy banks and/or other problems.PiggyBank::created(static function (PiggyBank $piggyBank) {$repetition = new PiggyBankRepetition;@@@ -223,40 -167,38 +220,6 @@@$repetition->save();});-- Client::created(-- static function (Client $oauthClient) {-- /** @var UserRepositoryInterface $repository */-- $repository = app(UserRepositoryInterface::class);-- $user = $repository->find((int) $oauthClient->user_id);-- if (null === $user) {-- Log::info('OAuth client generated but no user associated.');---- return;-- }- // HERE WE ARE- Notification::send($event->user, new TestNotification($event->user->email));---- $email = $user->email;---- // see if user has alternative email address:-- $pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');-- if (null !== $pref) {-- $email = $pref->data;-- }---- Log::debug(sprintf('Now in EventServiceProvider::registerCreateEvents. Email is %s', $email));-- try {-- Log::debug('Trying to send message...');-- Mail::to($email)->send(new OAuthTokenCreatedMail($oauthClient));-- } catch (TypeError|Exception $e) { // @phpstan-ignore-line-- Log::debug('Send message failed! :(');-- Log::error($e->getMessage());-- Log::error($e->getTraceAsString());-- Session::flash('error', 'Possible email error: ' . $e->getMessage());-- }-- Log::debug('If no error above this line, message was sent.');-- }-- );}}diff --cc app/User.phpindex 71655a408d,5c0da04984..bc8d2034be--- a/app/User.php+++ b/app/User.php@@@ -547,31 -545,5 +547,35 @@@ class User extends Authenticatabl{return $this->hasMany(Webhook::class);}- // end LDAP related code++ /**+ * Get the notification routing information for the given driver.+ *+ * @param string $driver+ * @param Notification|null $notification+ * @return mixed+ */+ public function routeNotificationFor($driver, $notification = null)+ {+ if (method_exists($this, $method = 'routeNotificationFor' . Str::studly($driver))) {+ return $this->{$method}($notification);+ }+ $email = $this->email;+ // see if user has alternative email address:+ $pref = app('preferences')->getForUser($this, 'remote_guard_alt_email');+ if (null !== $pref) {+ $email = $pref->data;+ }++ // if user is demo user, send to owner:++ if ($this->hasRole('demo')) {++ $email = config('firefly.site_owner');++ }++ return match ($driver) {+ 'database' => $this->notifications(),+ 'mail' => $email,+ default => null,+ };+ }+}