mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Update validators so they can handle one field at a time.
This commit is contained in:
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\AccountMetaFactory;
|
||||
@@ -234,7 +233,15 @@ trait AccountServiceTrait
|
||||
return null;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$amount = app('steam')->positive($amount);
|
||||
$amount = app('steam')->positive($amount);
|
||||
if (!array_key_exists('currency_id', $data)) {
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('default')->getDefaultCurrencyByUser($account->user);
|
||||
}
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
|
||||
$submission = [
|
||||
'group_title' => null,
|
||||
'user' => $account->user_id,
|
||||
@@ -354,6 +361,16 @@ trait AccountServiceTrait
|
||||
if (null === $obGroup) {
|
||||
return $this->createOBGroup($account, $data);
|
||||
}
|
||||
|
||||
// $data['currency_id'] is empty so creating a new journal may break.
|
||||
if (!array_key_exists('currency_id', $data)) {
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('default')->getDefaultCurrencyByUser($account->user);
|
||||
}
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $obGroup->transactionJournals()->first();
|
||||
$journal->date = $data['opening_balance_date'] ?? $journal->date;
|
||||
|
@@ -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;
|
||||
|
@@ -118,7 +118,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
];
|
||||
$client = new Client;
|
||||
try {
|
||||
$res = $client->request('POST', $this->message->webhook->url . 'x', $options);
|
||||
$res = $client->request('POST', $this->message->webhook->url, $options);
|
||||
$this->message->sent = true;
|
||||
} catch (ClientException | Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
|
Reference in New Issue
Block a user