2014-12-06 05:12:55 -06:00
|
|
|
<?php
|
|
|
|
namespace FireflyIII\Event;
|
|
|
|
|
|
|
|
use Illuminate\Events\Dispatcher;
|
|
|
|
|
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* Class Event
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Event
|
|
|
|
*/
|
2014-12-06 05:12:55 -06:00
|
|
|
class Event
|
|
|
|
{
|
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* @param \Account $account
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2014-12-06 05:12:55 -06:00
|
|
|
public function deleteAccount(\Account $account)
|
|
|
|
{
|
|
|
|
// get piggy banks
|
2014-12-24 13:55:42 -06:00
|
|
|
$piggies = $account->piggyBanks()->get();
|
2014-12-06 05:12:55 -06:00
|
|
|
|
|
|
|
// get reminders for each
|
2014-12-24 13:55:42 -06:00
|
|
|
/** @var \PiggyBank $piggyBank */
|
2014-12-06 05:12:55 -06:00
|
|
|
foreach ($piggies as $piggyBank) {
|
|
|
|
$reminders = $piggyBank->reminders()->get();
|
|
|
|
/** @var \Reminder $reminder */
|
|
|
|
foreach ($reminders as $reminder) {
|
|
|
|
$reminder->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Dispatcher $events
|
|
|
|
*/
|
|
|
|
public function subscribe(Dispatcher $events)
|
|
|
|
{
|
|
|
|
// triggers when others are updated.
|
|
|
|
$events->listen('account.destroy', 'FireflyIII\Event\Event@deleteAccount');
|
|
|
|
}
|
|
|
|
}
|