| 
									
										
										
										
											2016-01-08 16:00:07 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * EventServiceProvider.php | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III 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 General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with Firefly III.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-01-08 16:00:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Providers; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-05 20:50:04 +01:00
										 |  |  | use FireflyIII\Events\RegisteredUser; | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  | use FireflyIII\Models\Account; | 
					
						
							| 
									
										
										
										
											2015-02-25 19:32:33 +01:00
										 |  |  | use FireflyIII\Models\PiggyBank; | 
					
						
							|  |  |  | use FireflyIII\Models\PiggyBankRepetition; | 
					
						
							| 
									
										
										
										
											2015-03-01 08:15:24 +01:00
										 |  |  | use FireflyIII\Models\Transaction; | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2016-11-25 16:55:04 +01:00
										 |  |  | use FireflyIII\Models\TransactionJournalMeta; | 
					
						
							| 
									
										
										
										
											2017-12-05 20:50:04 +01:00
										 |  |  | use Illuminate\Auth\Events\Login; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  | use Log; | 
					
						
							| 
									
										
										
										
											2015-04-07 18:26:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-09 08:20:55 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class EventServiceProvider. | 
					
						
							| 
									
										
										
										
											2016-01-09 08:20:55 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  | class EventServiceProvider extends ServiceProvider | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-01-08 16:00:07 +01:00
										 |  |  |      * The event listener mappings for the application. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $listen | 
					
						
							|  |  |  |         = [ | 
					
						
							| 
									
										
										
										
											2017-09-26 08:52:16 +02:00
										 |  |  |             // is a User related event.
 | 
					
						
							| 
									
										
										
										
											2017-12-05 20:50:04 +01:00
										 |  |  |             RegisteredUser::class                         => [ | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail', | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole', | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-12-05 20:50:04 +01:00
										 |  |  |             // is a User related event.
 | 
					
						
							|  |  |  |             Login::class                                  => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@checkSingleUserIsAdmin', | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-26 08:52:16 +02:00
										 |  |  |             // is a User related event.
 | 
					
						
							|  |  |  |             'FireflyIII\Events\RequestedNewPassword'      => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@sendNewPassword', | 
					
						
							| 
									
										
										
										
											2016-11-22 21:21:11 +01:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-09-26 08:52:16 +02:00
										 |  |  |             // is a User related event.
 | 
					
						
							|  |  |  |             'FireflyIII\Events\UserChangedEmail'          => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@sendEmailChangeConfirmMail', | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UserEventHandler@sendEmailChangeUndoMail', | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-09-27 15:45:55 +02:00
										 |  |  |             // admin related
 | 
					
						
							|  |  |  |             'FireflyIII\Events\AdminRequestedTestMessage' => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\AdminEventHandler@sendTestMessage', | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-09-26 08:52:16 +02:00
										 |  |  |             // is a Transaction Journal related event.
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |             'FireflyIII\Events\StoredTransactionJournal'  => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\StoredJournalEventHandler@scanBills', | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\StoredJournalEventHandler@connectToPiggyBank', | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\StoredJournalEventHandler@processRules', | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2017-09-26 08:52:16 +02:00
										 |  |  |             // is a Transaction Journal related event.
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |             'FireflyIII\Events\UpdatedTransactionJournal' => [ | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@scanBills', | 
					
						
							|  |  |  |                 'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@processRules', | 
					
						
							|  |  |  |             ], | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-09-16 07:05:34 +02:00
										 |  |  |      * Register any events for your application. | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-09-16 07:05:34 +02:00
										 |  |  |     public function boot() | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-16 07:05:34 +02:00
										 |  |  |         parent::boot(); | 
					
						
							| 
									
										
										
										
											2015-05-17 10:30:18 +02:00
										 |  |  |         $this->registerDeleteEvents(); | 
					
						
							|  |  |  |         $this->registerCreateEvents(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 16:24:47 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function registerCreateEvents() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // move this routine to a filter
 | 
					
						
							|  |  |  |         // in case of repeated piggy banks and/or other problems.
 | 
					
						
							|  |  |  |         PiggyBank::created( | 
					
						
							|  |  |  |             function (PiggyBank $piggyBank) { | 
					
						
							|  |  |  |                 $repetition = new PiggyBankRepetition; | 
					
						
							|  |  |  |                 $repetition->piggyBank()->associate($piggyBank); | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |                 $repetition->startdate     = null === $piggyBank->startdate ? null : $piggyBank->startdate; | 
					
						
							|  |  |  |                 $repetition->targetdate    = null === $piggyBank->targetdate ? null : $piggyBank->targetdate; | 
					
						
							| 
									
										
										
										
											2016-03-19 16:24:47 +01:00
										 |  |  |                 $repetition->currentamount = 0; | 
					
						
							|  |  |  |                 $repetition->save(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 10:30:18 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function registerDeleteEvents() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  |         Account::deleted( | 
					
						
							| 
									
										
										
										
											2015-06-06 23:09:12 +02:00
										 |  |  |             function (Account $account) { | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  |                 Log::debug('Now trigger account delete response #' . $account->id); | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  |                 /** @var Transaction $transaction */ | 
					
						
							|  |  |  |                 foreach ($account->transactions()->get() as $transaction) { | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  |                     Log::debug('Now at transaction #' . $transaction->id); | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  |                     $journal = $transaction->transactionJournal()->first(); | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |                     if (null !== $journal) { | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  |                         Log::debug('Call for deletion of journal #' . $journal->id); | 
					
						
							|  |  |  |                         $journal->delete(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         TransactionJournal::deleted( | 
					
						
							|  |  |  |             function (TransactionJournal $journal) { | 
					
						
							| 
									
										
										
										
											2016-11-25 16:55:04 +01:00
										 |  |  |                 Log::debug(sprintf('Now triggered journal delete response #%d', $journal->id)); | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 /** @var Transaction $transaction */ | 
					
						
							|  |  |  |                 foreach ($journal->transactions()->get() as $transaction) { | 
					
						
							| 
									
										
										
										
											2016-11-25 16:55:04 +01:00
										 |  |  |                     Log::debug(sprintf('Will now delete transaction #%d', $transaction->id)); | 
					
						
							| 
									
										
										
										
											2016-06-23 12:07:31 +02:00
										 |  |  |                     $transaction->delete(); | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-11-25 16:55:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // also delete journal_meta entries.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 /** @var TransactionJournalMeta $meta */ | 
					
						
							|  |  |  |                 foreach ($journal->transactionJournalMeta()->get() as $meta) { | 
					
						
							|  |  |  |                     Log::debug(sprintf('Will now delete meta-entry #%d', $meta->id)); | 
					
						
							|  |  |  |                     $meta->delete(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-02-14 14:25:29 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-05-17 10:30:18 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-06 04:39:52 +01:00
										 |  |  | } |