Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix #3118
James Cole529cb3d38708
diff --git a/app/Api/V1/Controllers/CurrencyController.php b/app/Api/V1/Controllers/CurrencyController.phpindex d85b2abaab..3a41ac79a4 100644--- a/app/Api/V1/Controllers/CurrencyController.php+++ b/app/Api/V1/Controllers/CurrencyController.php@@ -318,6 +318,10 @@ class CurrencyController extends Controllerif ($this->repository->currencyInUse($currency)) {throw new FireflyException('200006: Currency in use.'); // @codeCoverageIgnore}+ if ($this->repository->isFallbackCurrency($currency)) {+ throw new FireflyException('200026: Currency is fallback.'); // @codeCoverageIgnore+ }+$this->repository->destroy($currency);return response()->json([], 204);diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.phpindex 163cbc051e..5f909449a0 100644--- a/app/Http/Controllers/CurrencyController.php+++ b/app/Http/Controllers/CurrencyController.php@@ -183,6 +183,14 @@ class CurrencyController extends Controllerreturn redirect(route('currencies.index'));}++ if ($this->repository->isFallbackCurrency($currency)) {+ $request->session()->flash('error', (string)trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)]));+ Log::channel('audit')->info(sprintf('Tried to delete currency %s but is FALLBACK.', $currency->code));++ return redirect(route('currencies.index'));+ }+Log::channel('audit')->info(sprintf('Deleted currency %s.', $currency->code));$this->repository->destroy($currency);diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.phpindex 44d621a6bf..1cdd92e448 100644--- a/app/Repositories/Currency/CurrencyRepository.php+++ b/app/Repositories/Currency/CurrencyRepository.php@@ -537,4 +537,12 @@ class CurrencyRepository implements CurrencyRepositoryInterfacereturn $service->update($currency, $data);}++ /**+ * @inheritDoc+ */+ public function isFallbackCurrency(TransactionCurrency $currency): bool+ {+ return $currency->code === config('firefly.default_currency', 'EUR');+ }}diff --git a/app/Repositories/Currency/CurrencyRepositoryInterface.php b/app/Repositories/Currency/CurrencyRepositoryInterface.phpindex f1727f7380..603be5d4f8 100644--- a/app/Repositories/Currency/CurrencyRepositoryInterface.php+++ b/app/Repositories/Currency/CurrencyRepositoryInterface.php@@ -35,6 +35,14 @@ use Illuminate\Support\Collection;*/interface CurrencyRepositoryInterface{++ /**+ * @param TransactionCurrency $currency+ *+ * @return bool+ */+ public function isFallbackCurrency(TransactionCurrency $currency): bool;+/*** @param TransactionCurrency $currency*