firefly-iii/app/Handlers/Events/RescanJournal.php

53 lines
1.2 KiB
PHP
Raw Normal View History

2015-03-01 01:34:59 -06:00
<?php namespace FireflyIII\Handlers\Events;
2016-01-12 14:38:05 -06:00
use FireflyIII\Events\TransactionJournalUpdated;
2015-03-01 01:34:59 -06:00
use Log;
/**
* Class RescanJournal
*
2015-05-12 13:51:03 -05:00
* @codeCoverageIgnore
2015-03-01 01:34:59 -06:00
* @package FireflyIII\Handlers\Events
*/
class RescanJournal
{
/**
* Create the event handler.
*
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
2016-01-12 14:38:05 -06:00
* @param TransactionJournalUpdated $event
2015-03-01 01:34:59 -06:00
*
* @return void
*/
2016-01-12 14:38:05 -06:00
public function handle(TransactionJournalUpdated $event)
2015-03-01 01:34:59 -06:00
{
$journal = $event->journal;
Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
2015-07-07 12:09:45 -05:00
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
2015-03-01 01:34:59 -06:00
$list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
Log::debug('Found ' . $list->count() . ' bills to check.');
2015-05-05 03:23:01 -05:00
/** @var \FireflyIII\Models\Bill $bill */
2015-03-01 01:34:59 -06:00
foreach ($list as $bill) {
Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
$repository->scan($bill, $journal);
}
Log::debug('Done!');
}
}