2016-01-08 09:00:07 -06:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-08 09:00:07 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Providers;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-14 07:25:29 -06:00
|
|
|
use FireflyIII\Models\Account;
|
2015-02-22 02:46:21 -06:00
|
|
|
use FireflyIII\Models\BudgetLimit;
|
2016-01-09 01:20:55 -06:00
|
|
|
use FireflyIII\Models\LimitRepetition;
|
2015-02-25 12:32:33 -06:00
|
|
|
use FireflyIII\Models\PiggyBank;
|
|
|
|
use FireflyIII\Models\PiggyBankRepetition;
|
2015-03-01 01:15:24 -06:00
|
|
|
use FireflyIII\Models\Transaction;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
2015-02-22 02:46:21 -06:00
|
|
|
use Illuminate\Database\QueryException;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
2015-03-01 01:25:12 -06:00
|
|
|
use Log;
|
2016-01-08 09:00:07 -06:00
|
|
|
use Navigation;
|
2015-04-07 11:26:14 -05:00
|
|
|
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
|
|
|
* Class EventServiceProvider
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Providers
|
|
|
|
*/
|
2015-02-11 00:35:10 -06:00
|
|
|
class EventServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
2016-01-08 09:00:07 -06:00
|
|
|
* The event listener mappings for the application.
|
2015-02-11 00:35:10 -06:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $listen
|
|
|
|
= [
|
2016-01-15 16:12:52 -06:00
|
|
|
'FireflyIII\Events\TransactionJournalUpdated' => [
|
2016-01-13 00:16:29 -06:00
|
|
|
'FireflyIII\Handlers\Events\ScanForBillsAfterUpdate',
|
2015-03-02 13:05:28 -06:00
|
|
|
'FireflyIII\Handlers\Events\UpdateJournalConnection',
|
2016-01-12 14:41:19 -06:00
|
|
|
'FireflyIII\Handlers\Events\FireRulesForUpdate',
|
2015-03-02 13:05:28 -06:00
|
|
|
|
2015-02-14 07:25:29 -06:00
|
|
|
],
|
2016-04-28 03:59:36 -05:00
|
|
|
'FireflyIII\Events\BudgetLimitStored' => [
|
|
|
|
'FireflyIII\Handlers\Events\BudgetLimitEventHandler@store',
|
|
|
|
],
|
|
|
|
'FireflyIII\Events\BudgetLimitUpdated' => [
|
|
|
|
'FireflyIII\Handlers\Events\BudgetLimitEventHandler@update',
|
|
|
|
],
|
2016-01-15 16:12:52 -06:00
|
|
|
'FireflyIII\Events\TransactionJournalStored' => [
|
2016-01-13 00:16:29 -06:00
|
|
|
'FireflyIII\Handlers\Events\ScanForBillsAfterStore',
|
2015-03-02 13:05:28 -06:00
|
|
|
'FireflyIII\Handlers\Events\ConnectJournalToPiggyBank',
|
2016-01-12 14:41:19 -06:00
|
|
|
'FireflyIII\Handlers\Events\FireRulesForStore',
|
2016-01-15 16:12:52 -06:00
|
|
|
],
|
2016-03-19 10:24:47 -05:00
|
|
|
'Illuminate\Auth\Events\Logout' => [
|
|
|
|
'FireflyIII\Handlers\Events\UserEventListener@onUserLogout',
|
|
|
|
],
|
2016-03-28 12:50:24 -05:00
|
|
|
'FireflyIII\Events\UserRegistration' => [
|
|
|
|
'FireflyIII\Handlers\Events\SendRegistrationMail',
|
|
|
|
'FireflyIII\Handlers\Events\AttachUserRole',
|
2016-03-29 04:55:25 -05:00
|
|
|
'FireflyIII\Handlers\Events\UserConfirmation@sendConfirmation',
|
|
|
|
],
|
|
|
|
'FireflyIII\Events\ResendConfirmation' => [
|
|
|
|
'FireflyIII\Handlers\Events\UserConfirmation@resendConfirmation',
|
2016-03-28 12:50:24 -05:00
|
|
|
],
|
2015-02-11 00:35:10 -06:00
|
|
|
];
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Register any other events for your application.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot(DispatcherContract $events)
|
|
|
|
{
|
|
|
|
parent::boot($events);
|
2015-05-17 03:30:18 -05:00
|
|
|
$this->registerDeleteEvents();
|
|
|
|
$this->registerCreateEvents();
|
|
|
|
}
|
|
|
|
|
2016-03-19 10:24:47 -05: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);
|
|
|
|
$repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate;
|
|
|
|
$repetition->targetdate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate;
|
|
|
|
$repetition->currentamount = 0;
|
|
|
|
$repetition->save();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-17 03:30:18 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function registerDeleteEvents()
|
|
|
|
{
|
2015-02-14 07:25:29 -06:00
|
|
|
Account::deleted(
|
2015-06-06 16:09:12 -05:00
|
|
|
function (Account $account) {
|
2015-02-14 07:25:29 -06:00
|
|
|
|
|
|
|
/** @var Transaction $transaction */
|
|
|
|
foreach ($account->transactions()->get() as $transaction) {
|
|
|
|
$journal = $transaction->transactionJournal()->first();
|
|
|
|
$journal->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-05-17 03:30:18 -05:00
|
|
|
}
|
|
|
|
|
2015-02-05 21:39:52 -06:00
|
|
|
}
|