mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 04:19:12 +00:00
Updated accounts so actions will trigger cache flush.
This commit is contained in:
@@ -206,7 +206,6 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
exit;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
39
app/lib/FireflyIII/Event/Account.php
Normal file
39
app/lib/FireflyIII/Event/Account.php
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user