mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
New feature: option to delete all meta data from your account.
This commit is contained in:
89
app/Http/Controllers/Profile/DataController.php
Normal file
89
app/Http/Controllers/Profile/DataController.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* DataController.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Profile;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
/**
|
||||
* Class DataController
|
||||
*/
|
||||
class DataController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function deleteBudgets(): RedirectResponse
|
||||
{
|
||||
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
||||
$abRepository = app(AvailableBudgetRepositoryInterface::class);
|
||||
$abRepository->destroyAll();
|
||||
|
||||
/** @var BudgetLimitRepositoryInterface $blRepository */
|
||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||
$blRepository->destroyAll();
|
||||
|
||||
/** @var BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
$budgetRepository->destroyAll();
|
||||
|
||||
session()->flash('success', trans('firefly.deleted_all_budgets'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function deleteCategories(): RedirectResponse
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $categoryRepos */
|
||||
$categoryRepos = app(CategoryRepositoryInterface::class);
|
||||
$categoryRepos->destroyAll();
|
||||
|
||||
session()->flash('success', trans('firefly.deleted_all_categories'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function deleteTags(): RedirectResponse
|
||||
{
|
||||
/** @var TagRepositoryInterface $tagRepository */
|
||||
$tagRepository = app(TagRepositoryInterface::class);
|
||||
$tagRepository->destroyAll();
|
||||
|
||||
session()->flash('success', trans('firefly.deleted_all_tags'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
}
|
@@ -282,4 +282,12 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
return $availableBudget;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all available budgets.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$this->user->availableBudgets()->delete();
|
||||
}
|
||||
}
|
@@ -34,6 +34,12 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface AvailableBudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Delete all available budgets.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
*/
|
||||
|
@@ -447,4 +447,16 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all budget limits.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$budgets = $this->user->budgets()->get();
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$budget->budgetlimits()->delete();
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,6 +35,12 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface BudgetLimitRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Destroy all budget limits.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* Tells you which amount has been budgeted (for the given budgets)
|
||||
* in the selected query. Returns a positive amount as a string.
|
||||
|
@@ -23,9 +23,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\RuleTrigger;
|
||||
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
|
||||
@@ -341,4 +343,20 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all budgets.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$budgets = $this->getBudgets();
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
|
||||
DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', $budget->id)->delete();
|
||||
RuleAction::where('action_type', 'set_budget')->where('action_value', $budget->id)->delete();
|
||||
$budget->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,12 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Destroy all budgets.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -23,8 +23,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Services\Internal\Destroy\CategoryDestroyService;
|
||||
use FireflyIII\Services\Internal\Update\CategoryUpdateService;
|
||||
use FireflyIII\User;
|
||||
@@ -347,4 +350,19 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
DB::table('category_transaction')->where('category_id', $category->id)->delete();
|
||||
DB::table('category_transaction_journal')->where('category_id', $category->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'category_id')->where('value', $category->id)->delete();
|
||||
RuleAction::where('action_type', 'set_category')->where('action_value', $category->name)->delete();
|
||||
$category->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,10 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
|
@@ -486,4 +486,17 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $tagQuery->get(['tags.id', 'tags.tag','tags.created_at', DB::raw('SUM(transactions.amount) as amount_sum')]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all tags.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$tags = $this->get();
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
DB::table('tag_transaction_journal')->where('tag_id', $tag->id)->delete();
|
||||
$tag->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,11 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface TagRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Destroy all tags.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
Reference in New Issue
Block a user