Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Updated accounts so actions will trigger cache flush.
James Cole935276af88f8
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.phpindex 68f81e7a32..88e8b75145 100644--- a/app/controllers/AccountController.php+++ b/app/controllers/AccountController.php@@ -94,7 +94,7 @@ class AccountController extends BaseController*/foreach ($journals as $id) {$journal = $jrnls->find($id);- $journal->delete();+ $jrnls->destroy($journal);}/*@@ -243,9 +243,9 @@ class AccountController extends BaseController$acct = App::make('FireflyIII\Database\Account');if (Input::get('showAll') == 'true') {- $journals = $acct->getAllTransactionJournals($account, 10);+ $journals = $acct->getAllTransactionJournals($account, 50);} else {- $journals = $acct->getTransactionJournals($account, 10);+ $journals = $acct->getTransactionJournals($account, 50);}@@ -321,6 +321,7 @@ class AccountController extends BaseControllerthrow new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"');break;case 'Default account':+ case 'Asset account':$data['what'] = 'asset';break;case 'Expense account':diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.phpindex 9706c7160a..d02e9ca6ce 100644--- a/app/controllers/TransactionController.php+++ b/app/controllers/TransactionController.php@@ -103,19 +103,6 @@ class TransactionController extends BaseController{$type = $transactionJournal->transactionType->type;- /*- * Trigger creation of new piggy bank event- */- Event::fire('transactionJournal.destroy', [$transactionJournal]); // new and used.- /*- * Since this event will also destroy both transactions, trigger on those as- * well because we might want to update some caches and what-not.- */- /** @var Transaction $transaction */- foreach ($transactionJournal->transactions as $transaction) {- Event::fire('transaction.destroy', [$transaction]);- }-/** @var \FireflyIII\Database\TransactionJournal $repository */$repository = App::make('FireflyIII\Database\TransactionJournal');$repository->destroy($transactionJournal);diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.phpindex 0bca22a5e4..4e372be977 100644--- a/app/lib/FireflyIII/Database/Account.php+++ b/app/lib/FireflyIII/Database/Account.php@@ -206,7 +206,6 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterfaceexit;}- return false;}/**@@ -216,6 +215,10 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface*/public function destroy(Ardent $model){+ /*+ * Trigger deletion:+ */+ \Event::fire('account.destroy', [$model]);$model->delete();return true;@@ -256,6 +259,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface/* Tell transaction journal to store a new one.*/+ \Event::fire('account.store', [$account]);return $account;@@ -274,7 +278,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface$model->active = isset($data['active']) ? intval($data['active']) : 0;$model->save();- if (isset($data['openingbalance']) && isset($data['openingbalancedate'])) {+ if (isset($data['openingbalance']) && isset($data['openingbalancedate']) && strlen($data['openingbalancedate']) > 0) {$openingBalance = $this->openingBalanceTransaction($model);$openingBalance->date = new Carbon($data['openingbalancedate']);@@ -290,7 +294,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface$transaction->save();}}-+ \Event::fire('account.update', [$model]);return true;}diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.phpindex 4ed70fc961..f772e56ee9 100644--- a/app/lib/FireflyIII/Database/TransactionJournal.php+++ b/app/lib/FireflyIII/Database/TransactionJournal.php@@ -37,6 +37,19 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData*/public function destroy(Ardent $model){+ /*+ * Trigger deletion.+ */+ \Event::fire('transactionJournal.destroy', [$model]); // new and used.+ /*+ * Since this event will also destroy both transactions, trigger on those as+ * well because we might want to update some caches and what-not.+ */+ /** @var Transaction $transaction */+ foreach ($model->transactions as $transaction) {+ \Event::fire('transaction.destroy', [$transaction]);+ }+$model->delete();return true;diff --git a/app/lib/FireflyIII/Event/Account.php b/app/lib/FireflyIII/Event/Account.phpnew file mode 100644index 0000000000..7b265b9816--- /dev/null+++ b/app/lib/FireflyIII/Event/Account.php@@ -0,0 +1,39 @@+<?php++namespace FireflyIII\Event;+++use Illuminate\Events\Dispatcher;++class Account+{+ public function destroy(\Account $account)+ {+ \Cache::forget('account.' . $account->id . '.latestBalance');+ \Cache::forget('account.' . $account->id . '.lastActivityDate');+ }++ public function store(\Account $account)+ {++ \Cache::forget('account.' . $account->id . '.latestBalance');+ \Cache::forget('account.' . $account->id . '.lastActivityDate');+ }++ /**+ * @param Dispatcher $events+ */+ public function subscribe(Dispatcher $events)+ {+ // triggers when others are updated.+ $events->listen('account.store', 'FireflyIII\Event\Account@store');+ $events->listen('account.update', 'FireflyIII\Event\Account@update');+ $events->listen('account.destroy', 'FireflyIII\Event\Account@destroy');+ }++ public function update(\Account $account)+ {+ \Cache::forget('account.' . $account->id . '.latestBalance');+ \Cache::forget('account.' . $account->id . '.lastActivityDate');+ }+}\ No newline at end of filediff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.phpindex ca7c1dd86d..dad1b61fcc 100644--- a/app/views/accounts/show.blade.php+++ b/app/views/accounts/show.blade.php@@ -20,6 +20,7 @@</div><div class="panel-body"><p>+ <!-- TODO clean up these methods and everything associated with them. -->@if(Input::get('showAll') == 'true')<a href="{{route('accounts.show',$account->id)}}" class="btn btn-default">Stick to date-range</a>@elsediff --git a/bootstrap/start.php b/bootstrap/start.phpindex cb529a7664..479b986f35 100644--- a/bootstrap/start.php+++ b/bootstrap/start.php@@ -92,6 +92,7 @@ Event::subscribe('FireflyIII\Event\Piggybank');Event::subscribe('FireflyIII\Event\Budget');Event::subscribe('FireflyIII\Event\TransactionJournal');Event::subscribe('FireflyIII\Event\Transaction');+Event::subscribe('FireflyIII\Event\Account');// event that creates a relationship between transaction journals and recurring events when created.// event that updates the relationship between transaction journals and recurring events when edited.