mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-03 20:56:21 +00:00
Update validators so they can handle one field at a time.
This commit is contained in:
@@ -79,9 +79,9 @@ class AccountUpdateService
|
||||
$account = $this->updateAccountOrder($account, $data);
|
||||
|
||||
// find currency, or use default currency instead.
|
||||
if (isset($data['currency_id']) && (null !== $data['currency_id'] || null !== $data['currency_code'])) {
|
||||
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));
|
||||
unset($data['currency_code']);
|
||||
unset($data['currency_code'], $data['currency_id']);
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,14 +51,26 @@ class CurrencyUpdateService
|
||||
*/
|
||||
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
|
||||
{
|
||||
$data['code'] = '' === (string)$data['code'] ? $currency->code : $data['code'];
|
||||
$data['symbol'] = '' === (string)$data['symbol'] ? $currency->code : $data['symbol'];
|
||||
$data['name'] = '' === (string)$data['name'] ? $currency->code : $data['name'];
|
||||
$currency->code = $data['code'];
|
||||
$currency->symbol = $data['symbol'];
|
||||
$currency->name = $data['name'];
|
||||
$currency->enabled = $data['enabled'];
|
||||
$currency->decimal_places = $data['decimal_places'];
|
||||
if (array_key_exists('code', $data) && '' !== (string)$data['code']) {
|
||||
$currency->code = $data['code'];
|
||||
}
|
||||
|
||||
if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) {
|
||||
$currency->symbol = $data['symbol'];
|
||||
}
|
||||
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
$currency->name = $data['name'];
|
||||
}
|
||||
|
||||
if (array_key_exists('enabled', $data) && is_bool($data['enabled'])) {
|
||||
$currency->enabled = $data['enabled'];
|
||||
}
|
||||
|
||||
if (array_key_exists('decimal_places', $data) && is_int($data['decimal_places'])) {
|
||||
$currency->decimal_places = $data['decimal_places'];
|
||||
}
|
||||
|
||||
$currency->save();
|
||||
|
||||
return $currency;
|
||||
|
||||
@@ -56,6 +56,13 @@ class GroupUpdateService
|
||||
$transactionGroup->title = $data['group_title'];
|
||||
$transactionGroup->save();
|
||||
}
|
||||
|
||||
if (0 === count($transactions)) {
|
||||
Log::debug('No transactions submitted, do nothing.');
|
||||
|
||||
return $transactionGroup;
|
||||
}
|
||||
|
||||
if (1 === count($transactions) && 1 === $transactionGroup->transactionJournals()->count()) {
|
||||
/** @var TransactionJournal $first */
|
||||
$first = $transactionGroup->transactionJournals()->first();
|
||||
|
||||
@@ -54,28 +54,17 @@ class JournalUpdateService
|
||||
{
|
||||
use JournalServiceTrait;
|
||||
|
||||
/** @var BillRepositoryInterface */
|
||||
private $billRepository;
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $currencyRepository;
|
||||
/** @var array The data to update the journal with. */
|
||||
private $data;
|
||||
/** @var Account The destination account. */
|
||||
private $destinationAccount;
|
||||
/** @var Transaction */
|
||||
private $destinationTransaction;
|
||||
/** @var array All meta values that are dates. */
|
||||
private $metaDate;
|
||||
/** @var array All meta values that are strings. */
|
||||
private $metaString;
|
||||
/** @var Account Source account of the journal */
|
||||
private $sourceAccount;
|
||||
/** @var Transaction Source transaction of the journal. */
|
||||
private $sourceTransaction;
|
||||
/** @var TransactionGroup The parent group. */
|
||||
private $transactionGroup;
|
||||
/** @var TransactionJournal The journal to update. */
|
||||
private $transactionJournal;
|
||||
private BillRepositoryInterface $billRepository;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private array $data;
|
||||
private ?Account $destinationAccount;
|
||||
private ?Transaction $destinationTransaction;
|
||||
private array $metaDate;
|
||||
private array $metaString;
|
||||
private ?Account $sourceAccount;
|
||||
private ?Transaction $sourceTransaction;
|
||||
private TransactionGroup $transactionGroup;
|
||||
private TransactionJournal $transactionJournal;
|
||||
|
||||
/**
|
||||
* JournalUpdateService constructor.
|
||||
@@ -112,6 +101,10 @@ class JournalUpdateService
|
||||
$this->budgetRepository->setUser($transactionGroup->user);
|
||||
$this->tagFactory->setUser($transactionGroup->user);
|
||||
$this->accountRepository->setUser($transactionGroup->user);
|
||||
$this->destinationAccount = null;
|
||||
$this->destinationTransaction = null;
|
||||
$this->sourceAccount = null;
|
||||
$this->sourceTransaction = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +123,7 @@ class JournalUpdateService
|
||||
Log::debug(sprintf('Now in JournalUpdateService for journal #%d.', $this->transactionJournal->id));
|
||||
// can we update account data using the new type?
|
||||
if ($this->hasValidAccounts()) {
|
||||
Log::info('-- account info is valid, now update.');
|
||||
Log::info('Account info is valid, now update.');
|
||||
// update accounts:
|
||||
$this->updateAccounts();
|
||||
|
||||
@@ -202,7 +195,7 @@ class JournalUpdateService
|
||||
private function getOriginalDestinationAccount(): Account
|
||||
{
|
||||
if (null === $this->destinationAccount) {
|
||||
$destination = $this->getSourceTransaction();
|
||||
$destination = $this->getDestinationTransaction();
|
||||
$this->destinationAccount = $destination->account;
|
||||
}
|
||||
|
||||
@@ -338,6 +331,7 @@ class JournalUpdateService
|
||||
$destName = $this->data['destination_name'] ?? null;
|
||||
|
||||
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
||||
Log::debug('No destination info submitted, grab the original data.');
|
||||
$destination = $this->getOriginalDestinationAccount();
|
||||
$destId = $destination->id;
|
||||
$destName = $destination->name;
|
||||
|
||||
Reference in New Issue
Block a user