mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update event.
This commit is contained in:
parent
dddb8cdbc0
commit
19e34b460f
25
app/Events/JournalSaved.php
Normal file
25
app/Events/JournalSaved.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php namespace FireflyIII\Events;
|
||||
|
||||
use FireflyIII\Events\Event;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class JournalSaved extends Event {
|
||||
|
||||
use SerializesModels;
|
||||
|
||||
public $journal;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(TransactionJournal $journal)
|
||||
{
|
||||
//
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
}
|
53
app/Handlers/Events/RescanJournal.php
Normal file
53
app/Handlers/Events/RescanJournal.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
use Log;
|
||||
use App;
|
||||
|
||||
/**
|
||||
* Class RescanJournal
|
||||
*
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class RescanJournal
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param JournalSaved $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(JournalSaved $event)
|
||||
{
|
||||
$journal = $event->journal;
|
||||
|
||||
Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
|
||||
|
||||
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
||||
$repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||
$list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
|
||||
|
||||
Log::debug('Found ' . $list->count() . ' bills to check.');
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($list as $bill) {
|
||||
Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
|
||||
$repository->scan($bill, $journal);
|
||||
}
|
||||
|
||||
Log::debug('Done!');
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Events\JournalSaved;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -264,6 +265,8 @@ class TransactionController extends Controller
|
||||
|
||||
$journal = $repository->store($journalData);
|
||||
|
||||
event(new JournalSaved($journal));
|
||||
|
||||
Session::flash('success', 'New transaction "' . $journal->description . '" stored!');
|
||||
|
||||
return Redirect::route('transactions.index', $request->input('what'));
|
||||
@ -298,6 +301,9 @@ class TransactionController extends Controller
|
||||
];
|
||||
|
||||
$repository->update($journal, $journalData);
|
||||
|
||||
event(new JournalSaved($journal));
|
||||
|
||||
Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.');
|
||||
|
||||
return Redirect::route('transactions.index', $journalData['what']);
|
||||
|
@ -30,11 +30,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $listen
|
||||
= [
|
||||
'event.name' => [
|
||||
'EventListener',
|
||||
],
|
||||
'App\Events\JournalDeleted' => [
|
||||
'App\Handlers\Events\JournalDeletedHandler@handle',
|
||||
'FireflyIII\Events\JournalSaved' => [
|
||||
'FireflyIII\Handlers\Events\RescanJournal',
|
||||
],
|
||||
];
|
||||
|
||||
@ -59,26 +56,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
}
|
||||
);
|
||||
|
||||
// TransactionJournal::saved(
|
||||
// function (TransactionJournal $journal) {
|
||||
//
|
||||
// Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
|
||||
//
|
||||
// /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
||||
// $repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||
// $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
|
||||
//
|
||||
// Log::debug('Found ' . $list->count() . ' bills to check.');
|
||||
//
|
||||
// /** @var Bill $bill */
|
||||
// foreach ($list as $bill) {
|
||||
// Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
|
||||
// $repository->scan($bill, $journal);
|
||||
// }
|
||||
//
|
||||
// Log::debug('Done!');
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
Account::deleted(
|
||||
|
Loading…
Reference in New Issue
Block a user