mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-27 05:51:56 +00:00
Remove account from preferences when set inactive, #3974
This commit is contained in:
@@ -77,7 +77,7 @@ class AccountUpdateService
|
|||||||
|
|
||||||
// find currency, or use default currency instead.
|
// find currency, or use default currency instead.
|
||||||
if (isset($data['currency_id']) && (null !== $data['currency_id'] || null !== $data['currency_code'])) {
|
if (isset($data['currency_id']) && (null !== $data['currency_id'] || null !== $data['currency_code'])) {
|
||||||
$currency = $this->getCurrency((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null));
|
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||||
unset($data['currency_code']);
|
unset($data['currency_code']);
|
||||||
$data['currency_id'] = $currency->id;
|
$data['currency_id'] = $currency->id;
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,9 @@ class AccountUpdateService
|
|||||||
$this->updateNote($account, (string)$data['notes']);
|
$this->updateNote($account, (string)$data['notes']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update preferences if inactive:
|
||||||
|
$this->updatePreferences($account, $data);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,8 +180,8 @@ class AccountUpdateService
|
|||||||
|
|
||||||
// if account type is a liability, the liability type (account type)
|
// if account type is a liability, the liability type (account type)
|
||||||
// can be updated to another one.
|
// can be updated to another one.
|
||||||
if ($this->isLiability($account) && $this->isLiabilityTypeId((int) ($data['account_type_id'] ?? 0))) {
|
if ($this->isLiability($account) && $this->isLiabilityTypeId((int)($data['account_type_id'] ?? 0))) {
|
||||||
$account->account_type_id = (int) $data['account_type_id'];
|
$account->account_type_id = (int)$data['account_type_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// update virtual balance (could be set to zero if empty string).
|
// update virtual balance (could be set to zero if empty string).
|
||||||
@@ -190,4 +193,25 @@ class AccountUpdateService
|
|||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
private function updatePreferences(Account $account, array $data): void
|
||||||
|
{
|
||||||
|
if (array_key_exists('active', $data) && false === $data['active']) {
|
||||||
|
$preference = app('preferences')->getForUser($account->user, 'frontpageAccounts');
|
||||||
|
if (null !== $preference) {
|
||||||
|
$removeAccountId = (int)$account->id;
|
||||||
|
$array = $preference->data;
|
||||||
|
$filtered = array_filter(
|
||||||
|
$array, function ($accountId) use ($removeAccountId) {
|
||||||
|
return (int)$accountId !== $removeAccountId;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
app('preferences')->setForUser($account->user, 'frontpageAccounts', array_values($filtered));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user