mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-07-27 16:07:45 -07:00
Clean up config.
This commit is contained in:
@@ -25,9 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Api\V1\Controllers\Models\Transaction;
|
||||
|
||||
use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Events\UpdatedAccount;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@@ -53,9 +50,9 @@ class DestroyController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
$admin = auth()->user();
|
||||
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
|
||||
$this->groupRepository = app(TransactionGroupRepository::class);
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* TriggeredAuditLog.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class TriggeredAuditLog
|
||||
*/
|
||||
class TriggeredAuditLog extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @SuppressWarnings("PHPMD.ExcessiveParameterList")
|
||||
*/
|
||||
public function __construct(
|
||||
public Model $changer,
|
||||
public Model $auditable,
|
||||
public string $field,
|
||||
public mixed $before,
|
||||
public mixed $after
|
||||
) {}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* UpdatedAccount.php
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class UpdatedAccount
|
||||
*/
|
||||
class UpdatedAccount extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Account $account
|
||||
) {}
|
||||
}
|
||||
@@ -39,18 +39,6 @@ class BillObserver
|
||||
$this->updatePrimaryCurrencyAmount($bill);
|
||||
}
|
||||
|
||||
public function deleting(Bill $bill): void
|
||||
{
|
||||
$repository = app(AttachmentRepositoryInterface::class);
|
||||
$repository->setUser($bill->user);
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($bill->attachments()->get() as $attachment) {
|
||||
$repository->destroy($attachment);
|
||||
}
|
||||
$bill->notes()->delete();
|
||||
}
|
||||
|
||||
public function updated(Bill $bill): void
|
||||
{
|
||||
// Log::debug('Observe "updated" of a bill.');
|
||||
|
||||
@@ -24,12 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use FireflyIII\Events\UpdatedAccount;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
@@ -56,7 +52,7 @@ class DeleteController extends Controller
|
||||
|
||||
// translations:
|
||||
$this->middleware(function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
|
||||
$this->repository = app(TransactionGroupRepositoryInterface::class);
|
||||
@@ -68,7 +64,7 @@ class DeleteController extends Controller
|
||||
/**
|
||||
* Shows the form that allows a user to delete a transaction journal.
|
||||
*/
|
||||
public function delete(TransactionGroup $group): Factory|Redirector|RedirectResponse|View
|
||||
public function delete(TransactionGroup $group): Factory | Redirector | RedirectResponse | View
|
||||
{
|
||||
if (!$this->isEditableGroup($group)) {
|
||||
return $this->redirectGroupToAccount($group);
|
||||
@@ -76,12 +72,12 @@ class DeleteController extends Controller
|
||||
|
||||
Log::debug(sprintf('Start of delete view for group #%d', $group->id));
|
||||
|
||||
$journal = $group->transactionJournals->first();
|
||||
$journal = $group->transactionJournals->first();
|
||||
if (null === $journal) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
$objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
$subTitle = (string) trans('firefly.delete_'.$objectType, ['description' => $group->title ?? $journal->description]);
|
||||
$subTitle = (string)trans('firefly.delete_' . $objectType, ['description' => $group->title ?? $journal->description]);
|
||||
$previous = Steam::getSafePreviousUrl();
|
||||
// put previous url in session
|
||||
Log::debug('Will try to remember previous URL');
|
||||
@@ -99,19 +95,19 @@ class DeleteController extends Controller
|
||||
/**
|
||||
* Actually destroys the journal.
|
||||
*/
|
||||
public function destroy(TransactionGroup $group): Redirector|RedirectResponse
|
||||
public function destroy(TransactionGroup $group): Redirector | RedirectResponse
|
||||
{
|
||||
Log::debug(sprintf('Now in %s(#%d).', __METHOD__, $group->id));
|
||||
if (!$this->isEditableGroup($group)) {
|
||||
return $this->redirectGroupToAccount($group);
|
||||
}
|
||||
|
||||
$journal = $group->transactionJournals->first();
|
||||
$journal = $group->transactionJournals->first();
|
||||
if (null === $journal) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
$objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
session()->flash('success', (string) trans('firefly.deleted_'.strtolower($objectType), ['description' => $group->title ?? $journal->description]));
|
||||
session()->flash('success', (string)trans('firefly.deleted_' . strtolower($objectType), ['description' => $group->title ?? $journal->description]));
|
||||
$this->repository->destroy($group);
|
||||
Preferences::mark();
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class UniqueAccountNumber implements ValidationRule
|
||||
private readonly ?Account $account,
|
||||
private ?string $expectedType
|
||||
) {
|
||||
app('log')->debug('Constructed UniqueAccountNumber');
|
||||
Log::debug('Constructed UniqueAccountNumber');
|
||||
// a very basic fix to make sure we get the correct account type:
|
||||
if ('expense' === $this->expectedType) {
|
||||
$this->expectedType = AccountTypeEnum::EXPENSE->value;
|
||||
|
||||
@@ -24,7 +24,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Destroy;
|
||||
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class BillDestroyService
|
||||
@@ -33,6 +35,16 @@ class BillDestroyService
|
||||
{
|
||||
public function destroy(Bill $bill): void
|
||||
{
|
||||
$repository = app(AttachmentRepositoryInterface::class);
|
||||
$repository->setUser($bill->user);
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($bill->attachments()->get() as $attachment) {
|
||||
$repository->destroy($attachment);
|
||||
}
|
||||
$bill->notes()->delete();
|
||||
|
||||
|
||||
$bill->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Events\Model\Account\UpdatedExistingAccount;
|
||||
use FireflyIII\Events\UpdatedAccount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -47,11 +46,11 @@ class AccountUpdateService
|
||||
use AccountServiceTrait;
|
||||
|
||||
protected AccountRepositoryInterface $accountRepository;
|
||||
protected array $validAssetFields;
|
||||
protected array $validCCFields;
|
||||
protected array $validFields;
|
||||
private array $canHaveOpeningBalance;
|
||||
private User $user;
|
||||
protected array $validAssetFields;
|
||||
protected array $validCCFields;
|
||||
protected array $validFields;
|
||||
private array $canHaveOpeningBalance;
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -80,7 +79,7 @@ class AccountUpdateService
|
||||
|
||||
// find currency, or use default currency instead.
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$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'], $data['currency_id']);
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
@@ -99,7 +98,7 @@ class AccountUpdateService
|
||||
|
||||
// update note:
|
||||
if (array_key_exists('notes', $data) && null !== $data['notes']) {
|
||||
$this->updateNote($account, (string) $data['notes']);
|
||||
$this->updateNote($account, (string)$data['notes']);
|
||||
}
|
||||
|
||||
// update preferences if inactive:
|
||||
@@ -125,7 +124,7 @@ class AccountUpdateService
|
||||
$account->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('iban', $data)) {
|
||||
$account->iban = Steam::filterSpaces((string) $data['iban']);
|
||||
$account->iban = Steam::filterSpaces((string)$data['iban']);
|
||||
}
|
||||
|
||||
// set liability, but account must already be a liability.
|
||||
@@ -137,7 +136,7 @@ class AccountUpdateService
|
||||
// set liability, alternative method used in v1 layout:
|
||||
|
||||
if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) {
|
||||
$type = AccountType::find((int) $data['account_type_id']);
|
||||
$type = AccountType::find((int)$data['account_type_id']);
|
||||
|
||||
if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) {
|
||||
$account->account_type_id = $type->id;
|
||||
@@ -175,7 +174,7 @@ class AccountUpdateService
|
||||
return $account;
|
||||
}
|
||||
// skip if not of orderable type.
|
||||
$type = $account->accountType->type;
|
||||
$type = $account->accountType->type;
|
||||
if (!in_array(
|
||||
$type,
|
||||
[AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value],
|
||||
@@ -186,10 +185,10 @@ class AccountUpdateService
|
||||
return $account;
|
||||
}
|
||||
// get account type ID's because a join and an update is hard:
|
||||
$oldOrder = $account->order;
|
||||
$newOrder = $data['order'];
|
||||
$oldOrder = $account->order;
|
||||
$newOrder = $data['order'];
|
||||
Log::debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
|
||||
$list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
|
||||
$list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
|
||||
if (AccountTypeEnum::ASSET->value === $type) {
|
||||
$list = $this->getTypeIds([AccountTypeEnum::ASSET->value]);
|
||||
}
|
||||
@@ -201,8 +200,7 @@ class AccountUpdateService
|
||||
->where('accounts.order', '>', $oldOrder)
|
||||
->where('accounts.id', '!=', $account->id)
|
||||
->whereIn('accounts.account_type_id', $list)
|
||||
->decrement('order')
|
||||
;
|
||||
->decrement('order');
|
||||
$account->order = $newOrder;
|
||||
Log::debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
$account->save();
|
||||
@@ -216,8 +214,7 @@ class AccountUpdateService
|
||||
->where('accounts.order', '<', $oldOrder)
|
||||
->where('accounts.id', '!=', $account->id)
|
||||
->whereIn('accounts.account_type_id', $list)
|
||||
->increment('order')
|
||||
;
|
||||
->increment('order');
|
||||
$account->order = $newOrder;
|
||||
Log::debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
$account->save();
|
||||
@@ -251,7 +248,7 @@ class AccountUpdateService
|
||||
|
||||
// otherwise, update or create.
|
||||
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
||||
$location = $this->accountRepository->getLocation($account);
|
||||
$location = $this->accountRepository->getLocation($account);
|
||||
if (!$location instanceof Location) {
|
||||
$location = new Location();
|
||||
$location->locatable()->associate($account);
|
||||
@@ -302,11 +299,11 @@ class AccountUpdateService
|
||||
if (true === $account->active) {
|
||||
return;
|
||||
}
|
||||
$preference = Preferences::getForUser($account->user, 'frontpageAccounts');
|
||||
$preference = Preferences::getForUser($account->user, 'frontpageAccounts');
|
||||
if (null === $preference) {
|
||||
return;
|
||||
}
|
||||
$array = $preference->data;
|
||||
$array = $preference->data;
|
||||
if (!is_array($array)) {
|
||||
$array = [$array];
|
||||
}
|
||||
@@ -315,9 +312,9 @@ class AccountUpdateService
|
||||
$removeAccountId = $account->id;
|
||||
$new = [];
|
||||
foreach ($array as $value) {
|
||||
if ((int) $value !== $removeAccountId) {
|
||||
if ((int)$value !== $removeAccountId) {
|
||||
Log::debug(sprintf('Will include: %d', $value));
|
||||
$new[] = (int) $value;
|
||||
$new[] = (int)$value;
|
||||
}
|
||||
}
|
||||
Log::debug('Final new array is', $new);
|
||||
|
||||
Reference in New Issue
Block a user