mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Add button to remove unused accounts.
This commit is contained in:
@@ -45,12 +45,15 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
|||||||
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
||||||
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DestroyController
|
* Class DestroyController
|
||||||
*/
|
*/
|
||||||
class DestroyController extends Controller
|
class DestroyController extends Controller
|
||||||
{
|
{
|
||||||
|
private bool $unused;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/#/data/destroyData
|
* https://api-docs.firefly-iii.org/#/data/destroyData
|
||||||
@@ -62,8 +65,8 @@ class DestroyController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function destroy(DestroyRequest $request): JsonResponse
|
public function destroy(DestroyRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$objects = $request->getObjects();
|
$objects = $request->getObjects();
|
||||||
|
$this->unused = $request->boolean('unused', false);
|
||||||
switch ($objects) {
|
switch ($objects) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException(sprintf('This endpoint can\'t handle object "%s"', $objects));
|
throw new FireflyException(sprintf('This endpoint can\'t handle object "%s"', $objects));
|
||||||
@@ -260,9 +263,19 @@ class DestroyController extends Controller
|
|||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$collection = $repository->getAccountsByType($types);
|
$collection = $repository->getAccountsByType($types);
|
||||||
$service = app(AccountDestroyService::class);
|
$service = app(AccountDestroyService::class);
|
||||||
|
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($collection as $account) {
|
foreach ($collection as $account) {
|
||||||
$service->destroy($account, null);
|
$count = $account->transactions()->count();
|
||||||
|
if (true === $this->unused && 0 === $count) {
|
||||||
|
Log::info(sprintf('Deleted unused account #%d "%s"', $account->id, $account->name));
|
||||||
|
$service->destroy($account, null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (false === $this->unused) {
|
||||||
|
Log::info(sprintf('Deleting account #%d "%s"', $account->id, $account->name));
|
||||||
|
$service->destroy($account, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,6 +56,7 @@ class DestroyRequest extends FormRequest
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'objects' => sprintf('required|min:1|string|in:%s', $valid),
|
'objects' => sprintf('required|min:1|string|in:%s', $valid),
|
||||||
|
'unused' => 'in:true,false',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ use FireflyIII\Support\CacheProperties;
|
|||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -1344,6 +1344,9 @@ return [
|
|||||||
'delete_data_title' => 'Delete data from Firefly III',
|
'delete_data_title' => 'Delete data from Firefly III',
|
||||||
'permanent_delete_stuff' => 'You can delete stuff from Firefly III. Using the buttons below means that your items will be removed from view and hidden. There is no undo-button for this, but the items may remain in the database where you can salvage them if necessary.',
|
'permanent_delete_stuff' => 'You can delete stuff from Firefly III. Using the buttons below means that your items will be removed from view and hidden. There is no undo-button for this, but the items may remain in the database where you can salvage them if necessary.',
|
||||||
'other_sessions_logged_out' => 'All your other sessions have been logged out.',
|
'other_sessions_logged_out' => 'All your other sessions have been logged out.',
|
||||||
|
'delete_unused_accounts' => 'Deleting unused accounts will clean your auto-complete lists.',
|
||||||
|
'delete_all_unused_accounts' => 'Delete unused accounts',
|
||||||
|
'deleted_all_unused_accounts' => 'All unused accounts are deleted',
|
||||||
'delete_all_budgets' => 'Delete ALL your budgets',
|
'delete_all_budgets' => 'Delete ALL your budgets',
|
||||||
'delete_all_categories' => 'Delete ALL your categories',
|
'delete_all_categories' => 'Delete ALL your categories',
|
||||||
'delete_all_tags' => 'Delete ALL your tags',
|
'delete_all_tags' => 'Delete ALL your tags',
|
||||||
|
@@ -257,6 +257,21 @@
|
|||||||
data-type="liabilities" class="confirm btn btn-warning btn-sm"><span
|
data-type="liabilities" class="confirm btn btn-warning btn-sm"><span
|
||||||
class="fa fa-ticket"></span> {{ 'delete_all_liabilities'|_ }}</button>
|
class="fa fa-ticket"></span> {{ 'delete_all_liabilities'|_ }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
<h4>{{ 'accounts'|_ }}</h4>
|
||||||
|
<p>
|
||||||
|
<em class="text-info">
|
||||||
|
{{ 'delete_unused_accounts'|_ }}
|
||||||
|
</em>
|
||||||
|
</p>
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button"
|
||||||
|
data-success="{{ trans('firefly.deleted_all_unused_accounts')|escape('html') }}"
|
||||||
|
data-type="unused_accounts" class="confirm btn btn-warning btn-sm"><span
|
||||||
|
class="fa fa-credit-card"></span> {{ 'delete_all_unused_accounts'|_ }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h4>{{ 'transactions'|_ }}</h4>
|
<h4>{{ 'transactions'|_ }}</h4>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
@@ -301,9 +316,12 @@
|
|||||||
var classes = link.find('i').attr('class');
|
var classes = link.find('i').attr('class');
|
||||||
var url = deleteAPIRoute + '?objects=' + link.data('type');
|
var url = deleteAPIRoute + '?objects=' + link.data('type');
|
||||||
// different URL for purge route:
|
// different URL for purge route:
|
||||||
if(link.data('type') === 'purge') {
|
if (link.data('type') === 'purge') {
|
||||||
url = '{{ route('api.v1.data.purge') }}';
|
url = '{{ route('api.v1.data.purge') }}';
|
||||||
}
|
}
|
||||||
|
if (link.data('type') === 'unused_accounts') {
|
||||||
|
url = deleteAPIRoute + '?objects=accounts&unused=true';
|
||||||
|
}
|
||||||
|
|
||||||
// replace icon with loading thing
|
// replace icon with loading thing
|
||||||
link.prop('disabled', true);
|
link.prop('disabled', true);
|
||||||
|
Reference in New Issue
Block a user