Skip to content

Firefly III: a personal finances manager

Removed duplicate code.

James Cole170ffbae047c
diff --git a/app/Handlers/Events/RescanJournal.php b/app/Handlers/Events/RescanJournal.php
deleted file mode 100644
index d8717803a6..0000000000
--- a/app/Handlers/Events/RescanJournal.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php namespace FireflyIII\Handlers\Events;
-
-use FireflyIII\Events\TransactionJournalUpdated;
-use Log;
-
-/**
- * Class RescanJournal
- *
- * @codeCoverageIgnore
- * @package FireflyIII\Handlers\Events
- */
-class RescanJournal
-{
-
- /**
- * Create the event handler.
- *
- */
- public function __construct()
- {
- //
- }
-
- /**
- * Handle the event.
- *
- * @param TransactionJournalUpdated $event
- *
- * @return void
- */
- public function handle(TransactionJournalUpdated $event)
- {
- $journal = $event->journal;
-
- Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
-
- /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
- $repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
- $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
-
- Log::debug('Found ' . $list->count() . ' bills to check.');
-
- /** @var \FireflyIII\Models\Bill $bill */
- foreach ($list as $bill) {
- Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
- $repository->scan($bill, $journal);
- }
-
- Log::debug('Done!');
- }
-
-}
diff --git a/app/Handlers/Events/ScanForBillsAfterStore.php b/app/Handlers/Events/ScanForBillsAfterStore.php
index 26f807fac1..81fa3f870f 100644
--- a/app/Handlers/Events/ScanForBillsAfterStore.php
+++ b/app/Handlers/Events/ScanForBillsAfterStore.php
@@ -10,6 +10,7 @@
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\TransactionJournalStored;
+use FireflyIII\Support\Events\BillScanner;
use Log;
/**
@@ -40,22 +41,7 @@ class ScanForBillsAfterStore
public function handle(TransactionJournalStored $event)
{
$journal = $event->journal;
-
- Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
-
- /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
- $repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
- $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
-
- Log::debug('Found ' . $list->count() . ' bills to check.');
-
- /** @var \FireflyIII\Models\Bill $bill */
- foreach ($list as $bill) {
- Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
- $repository->scan($bill, $journal);
- }
-
- Log::debug('Done!');
+ BillScanner::scan($journal);
}
}
diff --git a/app/Handlers/Events/ScanForBillsAfterUpdate.php b/app/Handlers/Events/ScanForBillsAfterUpdate.php
index 424e1c0e84..c17a79360a 100644
--- a/app/Handlers/Events/ScanForBillsAfterUpdate.php
+++ b/app/Handlers/Events/ScanForBillsAfterUpdate.php
@@ -10,6 +10,7 @@
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\TransactionJournalUpdated;
+use FireflyIII\Support\Events\BillScanner;
use Log;
/**
@@ -40,22 +41,7 @@ class ScanForBillsAfterUpdate
public function handle(TransactionJournalUpdated $event)
{
$journal = $event->journal;
-
- Log::debug('Triggered saved event for journal #' . $journal->id . ' (' . $journal->description . ')');
-
- /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
- $repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
- $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
-
- Log::debug('Found ' . $list->count() . ' bills to check.');
-
- /** @var \FireflyIII\Models\Bill $bill */
- foreach ($list as $bill) {
- Log::debug('Now calling bill #' . $bill->id . ' (' . $bill->name . ')');
- $repository->scan($bill, $journal);
- }
-
- Log::debug('Done!');
+ BillScanner::scan($journal);
}
}
diff --git a/app/Support/Events/BillScanner.php b/app/Support/Events/BillScanner.php
new file mode 100644
index 0000000000..729ce5a783
--- /dev/null
+++ b/app/Support/Events/BillScanner.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * BillScanner.php
+ * Copyright (C) 2016 Sander Dorigo
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ */
+
+namespace FireflyIII\Support\Events;
+
+
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class BillScanner
+ *
+ * @package FireflyIII\Support\Events
+ */
+class BillScanner
+{
+ /**
+ * @param TransactionJournal $journal
+ */
+ static function scan(TransactionJournal $journal)
+ {
+ /** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
+ $repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
+ $list = $journal->user->bills()->where('active', 1)->where('automatch', 1)->get();
+
+ /** @var \FireflyIII\Models\Bill $bill */
+ foreach ($list as $bill) {
+ $repository->scan($bill, $journal);
+ }
+ }
+
+}
\ No newline at end of file