diff --git a/app/Events/UserIsDeleted.php b/app/Events/ConfirmedUser.php similarity index 90% rename from app/Events/UserIsDeleted.php rename to app/Events/ConfirmedUser.php index 4312cc0178..c932675ec5 100644 --- a/app/Events/UserIsDeleted.php +++ b/app/Events/ConfirmedUser.php @@ -1,6 +1,6 @@ user = $user; - $this->ipAddress = $ipAddress; - } -} diff --git a/app/Events/UserRegistration.php b/app/Events/ResentConfirmation.php similarity index 88% rename from app/Events/UserRegistration.php rename to app/Events/ResentConfirmation.php index 0af1bc833e..74a6f92c1b 100644 --- a/app/Events/UserRegistration.php +++ b/app/Events/ResentConfirmation.php @@ -1,6 +1,6 @@ transaction = $transaction; - } - -} diff --git a/app/Events/BudgetLimitUpdated.php b/app/Events/UpdatedBudgetLimit.php similarity index 91% rename from app/Events/BudgetLimitUpdated.php rename to app/Events/UpdatedBudgetLimit.php index 596c59c8b2..3642531e75 100644 --- a/app/Events/BudgetLimitUpdated.php +++ b/app/Events/UpdatedBudgetLimit.php @@ -1,6 +1,6 @@ count() == 1) { - $repository->attachRole($event->user, 'owner'); - } - } - -} diff --git a/app/Handlers/Events/BudgetLimitEventHandler.php b/app/Handlers/Events/BudgetEventHandler.php similarity index 79% rename from app/Handlers/Events/BudgetLimitEventHandler.php rename to app/Handlers/Events/BudgetEventHandler.php index a05a752cd2..cd02a373ef 100644 --- a/app/Handlers/Events/BudgetLimitEventHandler.php +++ b/app/Handlers/Events/BudgetEventHandler.php @@ -1,6 +1,6 @@ budgetLimit; $end = $event->end; @@ -71,12 +65,18 @@ class BudgetLimitEventHandler } + return true; } + /** - * @param BudgetLimitUpdated $event + * Updates, if present the budget limit repetition part of a budget limit. + * + * @param UpdatedBudgetLimit $event + * + * @return bool */ - public function update(BudgetLimitUpdated $event) + public function update(UpdatedBudgetLimit $event): bool { $budgetLimit = $event->budgetLimit; $end = $event->end; @@ -104,6 +104,7 @@ class BudgetLimitEventHandler $repetition->save(); } - } -} + return true; + } +} \ No newline at end of file diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php deleted file mode 100644 index 1d7d75d28c..0000000000 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ /dev/null @@ -1,72 +0,0 @@ -journal; - $piggyBankId = $event->piggyBankId; - - /** @var PiggyBank $piggyBank */ - $piggyBank = auth()->user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); - - if (is_null($piggyBank)) { - return true; - } - // update piggy bank rep for date of transaction journal. - $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); - if (is_null($repetition)) { - return true; - } - - $amount = TransactionJournal::amountPositive($journal); - // if piggy account matches source account, the amount is positive - $sources = TransactionJournal::sourceAccountList($journal)->pluck('id')->toArray(); - if (in_array($piggyBank->account_id, $sources)) { - $amount = bcmul($amount, '-1'); - } - - - $repetition->currentamount = bcadd($repetition->currentamount, $amount); - $repetition->save(); - - PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]); - - return true; - - } - - -} diff --git a/app/Handlers/Events/ConnectTransactionToPiggyBank.php b/app/Handlers/Events/ConnectTransactionToPiggyBank.php deleted file mode 100644 index 8e56987a0d..0000000000 --- a/app/Handlers/Events/ConnectTransactionToPiggyBank.php +++ /dev/null @@ -1,70 +0,0 @@ -transaction; - - $piggyBank = $repository->find($transaction['piggy_bank_id']); - - // valid piggy: - if (is_null($piggyBank->id)) { - return true; - } - $amount = strval($transaction['amount']); - // piggy bank account something with amount: - if ($transaction['source_account_id'] == $piggyBank->account_id) { - // if the source of this transaction is the same as the piggy bank, - // the money is being removed from the piggy bank. So the - // amount must be negative: - $amount = bcmul($amount, '-1'); - } - - $repetition = $piggyBank->currentRelevantRep(); - // add or remove the money from the piggy bank: - $newAmount = bcadd(strval($repetition->currentamount), $amount); - $repetition->currentamount = $newAmount; - $repetition->save(); - - // now generate a piggy bank event: - PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'date' => $transaction['date'], 'amount' => $newAmount]); - - return true; - } - - -} diff --git a/app/Handlers/Events/FireRulesForStore.php b/app/Handlers/Events/FireRulesForStore.php deleted file mode 100644 index 65cc16d67a..0000000000 --- a/app/Handlers/Events/FireRulesForStore.php +++ /dev/null @@ -1,68 +0,0 @@ -user(); - $groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); - // - /** @var RuleGroup $group */ - foreach ($groups as $group) { - $rules = $group->rules() - ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') - ->where('rule_triggers.trigger_type', 'user_action') - ->where('rule_triggers.trigger_value', 'store-journal') - ->where('rules.active', 1) - ->get(['rules.*']); - /** @var Rule $rule */ - foreach ($rules as $rule) { - - $processor = Processor::make($rule); - $processor->handleTransactionJournal($event->journal); - - if ($rule->stop_processing) { - return true; - } - - } - } - - return true; - } -} diff --git a/app/Handlers/Events/FireRulesForUpdate.php b/app/Handlers/Events/FireRulesForUpdate.php deleted file mode 100644 index 889d1e3156..0000000000 --- a/app/Handlers/Events/FireRulesForUpdate.php +++ /dev/null @@ -1,65 +0,0 @@ -user(); - $groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); - // - /** @var RuleGroup $group */ - foreach ($groups as $group) { - $rules = $group->rules() - ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') - ->where('rule_triggers.trigger_type', 'user_action') - ->where('rule_triggers.trigger_value', 'update-journal') - ->where('rules.active', 1) - ->get(['rules.*']); - /** @var Rule $rule */ - foreach ($rules as $rule) { - $processor = Processor::make($rule); - $processor->handleTransactionJournal($event->journal); - - if ($rule->stop_processing) { - break; - } - - } - } - - return true; - } -} diff --git a/app/Handlers/Events/ScanForBillsAfterStore.php b/app/Handlers/Events/ScanForBillsAfterStore.php deleted file mode 100644 index 499370eab9..0000000000 --- a/app/Handlers/Events/ScanForBillsAfterStore.php +++ /dev/null @@ -1,42 +0,0 @@ -journal; - BillScanner::scan($journal); - - return true; - } - -} diff --git a/app/Handlers/Events/ScanForBillsAfterUpdate.php b/app/Handlers/Events/ScanForBillsAfterUpdate.php deleted file mode 100644 index 11ddfee6aa..0000000000 --- a/app/Handlers/Events/ScanForBillsAfterUpdate.php +++ /dev/null @@ -1,41 +0,0 @@ -journal; - BillScanner::scan($journal); - - return true; - } - -} diff --git a/app/Handlers/Events/SendRegistrationMail.php b/app/Handlers/Events/SendRegistrationMail.php deleted file mode 100644 index aabb3714af..0000000000 --- a/app/Handlers/Events/SendRegistrationMail.php +++ /dev/null @@ -1,69 +0,0 @@ -user->email; - $address = route('index'); - $ipAddress = $event->ipAddress; - // send email. - try { - Mail::send( - ['emails.registered-html', 'emails.registered'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) { - $message->to($email, $email)->subject('Welcome to Firefly III! '); - } - ); - } catch (Swift_TransportException $e) { - Log::error($e->getMessage()); - } - - return true; - } -} diff --git a/app/Handlers/Events/StoredJournalEventHandler.php b/app/Handlers/Events/StoredJournalEventHandler.php new file mode 100644 index 0000000000..1410147625 --- /dev/null +++ b/app/Handlers/Events/StoredJournalEventHandler.php @@ -0,0 +1,124 @@ +journal; + $piggyBankId = $event->piggyBankId; + + /** @var PiggyBank $piggyBank */ + $piggyBank = $journal->user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); + + if (is_null($piggyBank)) { + return true; + } + // update piggy bank rep for date of transaction journal. + $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); + if (is_null($repetition)) { + return true; + } + + $amount = TransactionJournal::amountPositive($journal); + // if piggy account matches source account, the amount is positive + $sources = TransactionJournal::sourceAccountList($journal)->pluck('id')->toArray(); + if (in_array($piggyBank->account_id, $sources)) { + $amount = bcmul($amount, '-1'); + } + + + $repetition->currentamount = bcadd($repetition->currentamount, $amount); + $repetition->save(); + + PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]); + + return true; + } + + /** + * This method grabs all the users rules and processes them. + * + * @param StoredTransactionJournal $event + * + * @return bool + */ + public function processRules(StoredTransactionJournal $event): bool + { + // get all the user's rule groups, with the rules, order by 'order'. + $journal = $event->journal; + $groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); + // + /** @var RuleGroup $group */ + foreach ($groups as $group) { + $rules = $group->rules() + ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') + ->where('rule_triggers.trigger_type', 'user_action') + ->where('rule_triggers.trigger_value', 'store-journal') + ->where('rules.active', 1) + ->get(['rules.*']); + /** @var Rule $rule */ + foreach ($rules as $rule) { + + $processor = Processor::make($rule); + $processor->handleTransactionJournal($journal); + + if ($rule->stop_processing) { + return true; + } + + } + } + + return true; + } + + /** + * This method calls a special bill scanner that will check if the stored journal is part of a bill. + * + * @param StoredTransactionJournal $event + * + * @return bool + */ + public function scanBills(StoredTransactionJournal $event): bool + { + $journal = $event->journal; + BillScanner::scan($journal); + + return true; + } +} \ No newline at end of file diff --git a/app/Handlers/Events/UpdateJournalConnection.php b/app/Handlers/Events/UpdateJournalConnection.php deleted file mode 100644 index a30f63923a..0000000000 --- a/app/Handlers/Events/UpdateJournalConnection.php +++ /dev/null @@ -1,74 +0,0 @@ -journal; - - if (!$journal->isTransfer()) { - return true; - } - - // get the event connected to this journal: - /** @var PiggyBankEvent $event */ - $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); - if (is_null($event)) { - return false; - } - $piggyBank = $event->piggyBank()->first(); - $repetition = null; - if (!is_null($piggyBank)) { - /** @var PiggyBankRepetition $repetition */ - $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); - } - - if (is_null($repetition)) { - return false; - } - - $amount = TransactionJournal::amount($journal); - $diff = bcsub($amount, $event->amount); // update current repetition - - $repetition->currentamount = bcadd($repetition->currentamount, $diff); - $repetition->save(); - - - $event->amount = $amount; - $event->save(); - - return true; - } - -} diff --git a/app/Handlers/Events/UpdatedJournalEventHandler.php b/app/Handlers/Events/UpdatedJournalEventHandler.php new file mode 100644 index 0000000000..9626120ae1 --- /dev/null +++ b/app/Handlers/Events/UpdatedJournalEventHandler.php @@ -0,0 +1,128 @@ +journal; + + if (!$journal->isTransfer()) { + return true; + } + + // get the event connected to this journal: + /** @var PiggyBankEvent $event */ + $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); + if (is_null($event)) { + return false; + } + $piggyBank = $event->piggyBank()->first(); + $repetition = null; + if (!is_null($piggyBank)) { + /** @var PiggyBankRepetition $repetition */ + $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); + } + + if (is_null($repetition)) { + return false; + } + + $amount = TransactionJournal::amount($journal); + $diff = bcsub($amount, $event->amount); // update current repetition + + $repetition->currentamount = bcadd($repetition->currentamount, $diff); + $repetition->save(); + + + $event->amount = $amount; + $event->save(); + + return true; + } + + /** + * This method will check all the rules when a journal is updated. + * + * @param UpdatedTransactionJournal $event + * + * @return bool + */ + public function processRules(UpdatedTransactionJournal $event):bool + { + // get all the user's rule groups, with the rules, order by 'order'. + $journal = $event->journal; + $groups = $journal->user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); + // + /** @var RuleGroup $group */ + foreach ($groups as $group) { + $rules = $group->rules() + ->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id') + ->where('rule_triggers.trigger_type', 'user_action') + ->where('rule_triggers.trigger_value', 'update-journal') + ->where('rules.active', 1) + ->get(['rules.*']); + /** @var Rule $rule */ + foreach ($rules as $rule) { + $processor = Processor::make($rule); + $processor->handleTransactionJournal($journal); + + if ($rule->stop_processing) { + break; + } + + } + } + + return true; + } + + /** + * This method calls a special bill scanner that will check if the updated journal is part of a bill. + * + * @param UpdatedTransactionJournal $event + * + * @return bool + */ + public function scanBills(UpdatedTransactionJournal $event): bool + { + $journal = $event->journal; + BillScanner::scan($journal); + + return true; + } +} \ No newline at end of file diff --git a/app/Handlers/Events/UserConfirmation.php b/app/Handlers/Events/UserConfirmation.php deleted file mode 100644 index 439db35e75..0000000000 --- a/app/Handlers/Events/UserConfirmation.php +++ /dev/null @@ -1,109 +0,0 @@ -user; - $ipAddress = $event->ipAddress; - $this->doConfirm($user, $ipAddress); - - return true; - } - - /** - * Handle the event. - * - * @param UserRegistration $event - * - * @return bool - */ - public function sendConfirmation(UserRegistration $event): bool - { - $user = $event->user; - $ipAddress = $event->ipAddress; - $this->doConfirm($user, $ipAddress); - - return true; - } - - /** - * @param User $user - * @param string $ipAddress - */ - private function doConfirm(User $user, string $ipAddress) - { - $confirmAccount = env('MUST_CONFIRM_ACCOUNT', false); - if ($confirmAccount === false) { - Preferences::setForUser($user, 'user_confirmed', true); - Preferences::setForUser($user, 'user_confirmed_last_mail', 0); - Preferences::mark(); - - return; - } - $email = $user->email; - $code = str_random(16); - $route = route('do_confirm_account', [$code]); - Preferences::setForUser($user, 'user_confirmed', false); - Preferences::setForUser($user, 'user_confirmed_last_mail', time()); - Preferences::setForUser($user, 'user_confirmed_code', $code); - try { - Mail::send( - ['emails.confirm-account-html', 'emails.confirm-account'], ['route' => $route, 'ip' => $ipAddress], - function (Message $message) use ($email) { - $message->to($email, $email)->subject('Please confirm your Firefly III account'); - } - ); - } catch (Swift_TransportException $e) { - Log::error($e->getMessage()); - } catch (Exception $e) { - Log::error($e->getMessage()); - } - - return; - } - -} diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php new file mode 100644 index 0000000000..2d8523e3c9 --- /dev/null +++ b/app/Handlers/Events/UserEventHandler.php @@ -0,0 +1,225 @@ +count() === 1) { + $repository->attachRole($event->user, 'owner'); + } + + return true; + } + + /** + * Handle user logout events. + * + * @return bool + */ + public function onUserLogout(): bool + { + // dump stuff from the session: + Session::forget('twofactor-authenticated'); + Session::forget('twofactor-authenticated-date'); + + return true; + } + + /** + * This method will send a newly registered user a confirmation message, urging him or her to activate their account. + * + * @param RegisteredUser $event + * + * @return bool + */ + public function sendConfirmationMessage(RegisteredUser $event): bool + { + $user = $event->user; + $ipAddress = $event->ipAddress; + $confirmAccount = env('MUST_CONFIRM_ACCOUNT', false); + if ($confirmAccount === false) { + Preferences::setForUser($user, 'user_confirmed', true); + Preferences::setForUser($user, 'user_confirmed_last_mail', 0); + Preferences::mark(); + + return true; + } + $email = $user->email; + $code = str_random(16); + $route = route('do_confirm_account', [$code]); + Preferences::setForUser($user, 'user_confirmed', false); + Preferences::setForUser($user, 'user_confirmed_last_mail', time()); + Preferences::setForUser($user, 'user_confirmed_code', $code); + try { + Mail::send( + ['emails.confirm-account-html', 'emails.confirm-account'], ['route' => $route, 'ip' => $ipAddress], + function (Message $message) use ($email) { + $message->to($email, $email)->subject('Please confirm your Firefly III account'); + } + ); + } catch (Swift_TransportException $e) { + Log::error($e->getMessage()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } + + return true; + } + + /** + * If the user has somehow lost his or her confirmation message, this event will send it to the user again. + * + * At the moment, this method is exactly the same as the ::sendConfirmationMessage method, but that will change. + * + * @param ResentConfirmation $event + * + * @return bool + */ + function sendConfirmationMessageAgain(ResentConfirmation $event): bool + { + $user = $event->user; + $ipAddress = $event->ipAddress; + $confirmAccount = env('MUST_CONFIRM_ACCOUNT', false); + if ($confirmAccount === false) { + Preferences::setForUser($user, 'user_confirmed', true); + Preferences::setForUser($user, 'user_confirmed_last_mail', 0); + Preferences::mark(); + + return true; + } + $email = $user->email; + $code = str_random(16); + $route = route('do_confirm_account', [$code]); + Preferences::setForUser($user, 'user_confirmed', false); + Preferences::setForUser($user, 'user_confirmed_last_mail', time()); + Preferences::setForUser($user, 'user_confirmed_code', $code); + try { + Mail::send( + ['emails.confirm-account-html', 'emails.confirm-account'], ['route' => $route, 'ip' => $ipAddress], + function (Message $message) use ($email) { + $message->to($email, $email)->subject('Please confirm your Firefly III account'); + } + ); + } catch (Swift_TransportException $e) { + Log::error($e->getMessage()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } + + return true; + + } + + /** + * 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. + * + * @param RegisteredUser $event + * + * @return bool + */ + public function sendRegistrationMail(RegisteredUser $event) + { + + $sendMail = env('SEND_REGISTRATION_MAIL', true); + if (!$sendMail) { + return true; + } + // get the email address + $email = $event->user->email; + $address = route('index'); + $ipAddress = $event->ipAddress; + // send email. + try { + Mail::send( + ['emails.registered-html', 'emails.registered'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) { + $message->to($email, $email)->subject('Welcome to Firefly III! '); + } + ); + } catch (Swift_TransportException $e) { + Log::error($e->getMessage()); + } + + return true; + } + + /** + * When the user is confirmed, this method stores the IP address of the user + * as a preference. Since this preference cannot be edited, it is effectively hidden + * from the user yet stored conveniently. + * + * @param ConfirmedUser $event + * + * @return bool + */ + public function storeConfirmationIpAddress(ConfirmedUser $event): bool + { + Preferences::setForUser($event->user, 'confirmation_ip_address', $event->ipAddress); + + return true; + } + + /** + * This message stores the users IP address on registration, in much the same + * fashion as the previous method. + * + * @param RegisteredUser $event + * + * @return bool + */ + public function storeRegistrationIpAddress(RegisteredUser $event): bool + { + Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress); + + return true; + + } + +} \ No newline at end of file diff --git a/app/Handlers/Events/UserEventListener.php b/app/Handlers/Events/UserEventListener.php deleted file mode 100644 index f81303d084..0000000000 --- a/app/Handlers/Events/UserEventListener.php +++ /dev/null @@ -1,38 +0,0 @@ -user, 'confirmation_ip_address', $event->ipAddress); - - return true; - } - - /** - * Handle the event. - * - * @param UserRegistration $event - * - * @return bool - */ - public function saveFromRegistration(UserRegistration $event): bool - { - Preferences::setForUser($event->user, 'registration_ip_address', $event->ipAddress); - - return true; - } -} diff --git a/app/Http/Controllers/Auth/ConfirmationController.php b/app/Http/Controllers/Auth/ConfirmationController.php index 4e34c7dcb8..d99662973f 100644 --- a/app/Http/Controllers/Auth/ConfirmationController.php +++ b/app/Http/Controllers/Auth/ConfirmationController.php @@ -13,8 +13,8 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers\Auth; -use FireflyIII\Events\ResendConfirmation; -use FireflyIII\Events\UserIsConfirmed; +use FireflyIII\Events\ResentConfirmation; +use FireflyIII\Events\ConfirmedUser; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -56,7 +56,7 @@ class ConfirmationController extends Controller if ($database === $code && ($now - $time <= $maxDiff)) { // trigger user registration event: - event(new UserIsConfirmed(auth()->user(), $request->ip())); + event(new ConfirmedUser(auth()->user(), $request->ip())); Preferences::setForUser(auth()->user(), 'user_confirmed', true); Preferences::setForUser(auth()->user(), 'user_confirmed_confirmed', time()); @@ -80,7 +80,7 @@ class ConfirmationController extends Controller $owner = env('SITE_OWNER', 'mail@example.com'); $view = 'auth.confirmation.no-resent'; if ($now - $time > $maxDiff) { - event(new ResendConfirmation(auth()->user(), $request->ip())); + event(new ResentConfirmation(auth()->user(), $request->ip())); $view = 'auth.confirmation.resent'; } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index bb87bd81e3..e7d6dc6692 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -14,7 +14,7 @@ namespace FireflyIII\Http\Controllers\Auth; use Auth; use Config; -use FireflyIII\Events\UserRegistration; +use FireflyIII\Events\RegisteredUser; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Facades\FireflyConfig; use FireflyIII\User; @@ -102,7 +102,7 @@ class RegisterController extends Controller $user = $this->create($request->all()); // trigger user registration event: - event(new UserRegistration($user, $request->ip())); + event(new RegisteredUser($user, $request->ip())); Auth::login($user); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index b03420b592..5d368c09f5 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -13,7 +13,7 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use FireflyIII\Events\UserIsDeleted; +use FireflyIII\Events\DeletedUser; use FireflyIII\Http\Requests\DeleteAccountFormRequest; use FireflyIII\Http\Requests\ProfileFormRequest; use FireflyIII\User; @@ -116,9 +116,6 @@ class ProfileController extends Controller return redirect(route('profile.delete-account')); } - // respond to deletion: - event(new UserIsDeleted(auth()->user(), $request->ip())); - // store some stuff for the future: $registration = Preferences::get('registration_ip_address')->data; $confirmation = Preferences::get('confirmation_ip_address')->data; diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php index 23861d9ff4..e7efcd63e4 100644 --- a/app/Http/Controllers/Transaction/SingleController.php +++ b/app/Http/Controllers/Transaction/SingleController.php @@ -15,8 +15,8 @@ namespace FireflyIII\Http\Controllers\Transaction; use ExpandedForm; -use FireflyIII\Events\TransactionJournalStored; -use FireflyIII\Events\TransactionJournalUpdated; +use FireflyIII\Events\StoredTransactionJournal; +use FireflyIII\Events\UpdatedTransactionJournal; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\JournalFormRequest; @@ -260,7 +260,7 @@ class SingleController extends Controller Session::flash('info', $this->attachments->getMessages()->get('attachments')); } - event(new TransactionJournalStored($journal, $data['piggy_bank_id'])); + event(new StoredTransactionJournal($journal, $data['piggy_bank_id'])); Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)]))); Preferences::mark(); @@ -304,7 +304,7 @@ class SingleController extends Controller Session::flash('info', $this->attachments->getMessages()->get('attachments')); } - event(new TransactionJournalUpdated($journal)); + event(new UpdatedTransactionJournal($journal)); // update, get events by date and sort DESC $type = strtolower(TransactionJournal::transactionTypeStr($journal)); diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php index 6fe08cb008..b849f810ef 100644 --- a/app/Http/Controllers/Transaction/SplitController.php +++ b/app/Http/Controllers/Transaction/SplitController.php @@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers\Transaction; use ExpandedForm; -use FireflyIII\Events\TransactionJournalUpdated; +use FireflyIII\Events\UpdatedTransactionJournal; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\AccountType; @@ -132,7 +132,7 @@ class SplitController extends Controller // save attachments: $this->attachments->saveAttachmentsForModel($journal); - event(new TransactionJournalUpdated($journal)); + event(new UpdatedTransactionJournal($journal)); // update, get events by date and sort DESC // flash messages diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index d8373a2be6..6cfb886b4c 100755 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -35,42 +35,50 @@ class EventServiceProvider extends ServiceProvider */ protected $listen = [ - 'FireflyIII\Events\TransactionJournalUpdated' => [ - 'FireflyIII\Handlers\Events\ScanForBillsAfterUpdate', - 'FireflyIII\Handlers\Events\UpdateJournalConnection', - 'FireflyIII\Handlers\Events\FireRulesForUpdate', + // new event handlers: + 'FireflyIII\Events\ConfirmedUser' => // is a User related event. + [ + 'FireflyIII\Handlers\Events\UserEventHandler@storeConfirmationIpAddress', + ], + 'FireflyIII\Events\RegisteredUser' => // is a User related event. + [ + 'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail', + 'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole', + 'FireflyIII\Handlers\Events\UserEventHandler@sendConfirmationMessage', + 'FireflyIII\Handlers\Events\UserEventHandler@storeRegistrationIpAddress', + ], + 'FireflyIII\Events\ResentConfirmation' => // is a User related event. + [ + 'FireflyIII\Handlers\Events\UserEventHandler@sendConfirmationMessageAgain', + ], + 'FireflyIII\Events\StoredBudgetLimit' => // is a Budget related event. + [ + 'FireflyIII\Handlers\Events\BudgetEventHandler@storeRepetition', + ], - ], + 'FireflyIII\Events\UpdatedBudgetLimit' => // is a Budget related event. + [ + 'FireflyIII\Handlers\Events\BudgetEventHandler@updateRepetition', + ], - 'FireflyIII\Events\BudgetLimitStored' => [ - 'FireflyIII\Handlers\Events\BudgetLimitEventHandler@store', - ], - 'FireflyIII\Events\BudgetLimitUpdated' => [ - 'FireflyIII\Handlers\Events\BudgetLimitEventHandler@update', - ], - 'FireflyIII\Events\TransactionStored' => [ - 'FireflyIII\Handlers\Events\ConnectTransactionToPiggyBank', - ], - 'FireflyIII\Events\TransactionJournalStored' => [ - 'FireflyIII\Handlers\Events\ScanForBillsAfterStore', - 'FireflyIII\Handlers\Events\ConnectJournalToPiggyBank', - 'FireflyIII\Handlers\Events\FireRulesForStore', - ], - 'Illuminate\Auth\Events\Logout' => [ - 'FireflyIII\Handlers\Events\UserEventListener@onUserLogout', - ], - 'FireflyIII\Events\UserRegistration' => [ - 'FireflyIII\Handlers\Events\SendRegistrationMail', - 'FireflyIII\Handlers\Events\AttachUserRole', - 'FireflyIII\Handlers\Events\UserConfirmation@sendConfirmation', - 'FireflyIII\Handlers\Events\UserSaveIpAddress@saveFromRegistration', - ], - 'FireflyIII\Events\UserIsConfirmed' => [ - 'FireflyIII\Handlers\Events\UserSaveIpAddress@saveFromConfirmation', - ], - 'FireflyIII\Events\ResendConfirmation' => [ - 'FireflyIII\Handlers\Events\UserConfirmation@resendConfirmation', - ], + 'FireflyIII\Events\StoredTransactionJournal' => // is a Transaction Journal related event. + [ + 'FireflyIII\Handlers\Events\StoredJournalEventHandler@scanBills', + 'FireflyIII\Handlers\Events\StoredJournalEventHandler@connectToPiggyBank', + 'FireflyIII\Handlers\Events\StoredJournalEventHandler@processRules', + ], + 'FireflyIII\Events\UpdatedTransactionJournal' => // is a Transaction Journal related event. + [ + 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@scanBills', + 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@connectToPiggyBank', + 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@processRules', + ], + + // LARAVEL EVENTS: + 'Illuminate\Auth\Events\Logout' => + [ + 'FireflyIII\Handlers\Events\UserEventHandler@logoutUser', + ], ]; /** @@ -83,9 +91,6 @@ class EventServiceProvider extends ServiceProvider parent::boot(); $this->registerDeleteEvents(); $this->registerCreateEvents(); - - - // } /** diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 7d7e24dc52..b2a3440295 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -14,8 +14,8 @@ declare(strict_types = 1); namespace FireflyIII\Repositories\Budget; use Carbon\Carbon; -use FireflyIII\Events\BudgetLimitStored; -use FireflyIII\Events\BudgetLimitUpdated; +use FireflyIII\Events\StoredBudgetLimit; +use FireflyIII\Events\UpdatedBudgetLimit; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\LimitRepetition; @@ -555,7 +555,7 @@ class BudgetRepository implements BudgetRepositoryInterface $limit->save(); // fire event to create or update LimitRepetition. - event(new BudgetLimitUpdated($limit, $end)); + event(new UpdatedBudgetLimit($limit, $end)); return $limit; } @@ -568,7 +568,7 @@ class BudgetRepository implements BudgetRepositoryInterface $limit->repeat_freq = $repeatFreq; $limit->repeats = 0; $limit->save(); - event(new BudgetLimitStored($limit, $end)); + event(new StoredBudgetLimit($limit, $end)); // likewise, there should be a limit repetition to match the end date diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 855e253211..a43f55186a 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -14,7 +14,6 @@ declare(strict_types = 1); namespace FireflyIII\Repositories\Journal; use DB; -use FireflyIII\Events\TransactionStored; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType;