mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #1996
This commit is contained in:
parent
ba778d4c60
commit
7f91ff4b0c
@ -37,6 +37,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@ -185,11 +186,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Budget $budget): bool
|
public function destroy(Budget $budget): bool
|
||||||
{
|
{
|
||||||
try {
|
/** @var BudgetDestroyService $service */
|
||||||
$budget->delete();
|
$service = app(BudgetDestroyService::class);
|
||||||
} catch (Exception $e) {
|
$service->destroy($budget);
|
||||||
Log::error(sprintf('Could not delete budget: %s', $e->getMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
63
app/Services/Internal/Destroy/BudgetDestroyService.php
Normal file
63
app/Services/Internal/Destroy/BudgetDestroyService.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* BudgetDestroyService.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Services\Internal\Destroy;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
use Exception;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BudgetDestroyService
|
||||||
|
*/
|
||||||
|
class BudgetDestroyService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if ('testing' === config('app.env')) {
|
||||||
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Budget $budget
|
||||||
|
*/
|
||||||
|
public function destroy(Budget $budget): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$budget->delete();
|
||||||
|
} catch (Exception $e) { // @codeCoverageIgnore
|
||||||
|
Log::error(sprintf('Could not delete budget: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
// also delete all relations between categories and transaction journals:
|
||||||
|
DB::table('budget_transaction_journal')->where('budget_id', (int)$budget->id)->delete();
|
||||||
|
|
||||||
|
// also delete all relations between categories and transactions:
|
||||||
|
DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete();
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Services\Internal\Destroy;
|
namespace FireflyIII\Services\Internal\Destroy;
|
||||||
|
|
||||||
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use Log;
|
use Log;
|
||||||
@ -52,5 +53,11 @@ class CategoryDestroyService
|
|||||||
} catch (Exception $e) { // @codeCoverageIgnore
|
} catch (Exception $e) { // @codeCoverageIgnore
|
||||||
Log::error(sprintf('Could not delete category: %s', $e->getMessage())); // @codeCoverageIgnore
|
Log::error(sprintf('Could not delete category: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also delete all relations between categories and transaction journals:
|
||||||
|
DB::table('category_transaction_journal')->where('category_id', (int)$category->id)->delete();
|
||||||
|
|
||||||
|
// also delete all relations between categories and transactions:
|
||||||
|
DB::table('category_transaction')->where('category_id', (int)$category->id)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user