mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Catch various errors.
This commit is contained in:
@@ -42,20 +42,27 @@ class RecurrenceDestroyService
|
||||
try {
|
||||
// delete all meta data
|
||||
$recurrence->recurrenceMeta()->delete();
|
||||
|
||||
// delete all transactions.
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
foreach($recurrence->recurrenceTransactions as $transaction) {
|
||||
$transaction->recurrenceTransactionMeta()->delete();
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
Log::info(sprintf('Could not delete recurrence meta: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||
}
|
||||
// delete all transactions.
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
foreach ($recurrence->recurrenceTransactions as $transaction) {
|
||||
$transaction->recurrenceTransactionMeta()->delete();
|
||||
try {
|
||||
$transaction->delete();
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
Log::info(sprintf('Could not delete recurrence transaction: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||
}
|
||||
// delete all repetitions
|
||||
$recurrence->recurrenceRepetitions()->delete();
|
||||
}
|
||||
// delete all repetitions
|
||||
$recurrence->recurrenceRepetitions()->delete();
|
||||
|
||||
// delete recurrence
|
||||
// delete recurrence
|
||||
try {
|
||||
$recurrence->delete();
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
Log::error(sprintf('Could not delete recurrence: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||
Log::info(sprintf('Could not delete recurrence: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Factory\AccountFactory;
|
||||
use FireflyIII\Factory\AccountMetaFactory;
|
||||
use FireflyIII\Factory\TransactionFactory;
|
||||
@@ -80,7 +81,7 @@ trait AccountServiceTrait
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function filterIban(?string $iban)
|
||||
public function filterIban(?string $iban): ?string
|
||||
{
|
||||
if (null === $iban) {
|
||||
return null;
|
||||
@@ -204,7 +205,9 @@ trait AccountServiceTrait
|
||||
'reconciled' => false,
|
||||
]
|
||||
);
|
||||
Log::notice(sprintf('Stored two transactions for new account, #%d and #%d', $one->id, $two->id));
|
||||
if (null !== $one && null !== $two) {
|
||||
Log::notice(sprintf('Stored two transactions for new account, #%d and #%d', $one->id, $two->id));
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
@@ -214,6 +217,7 @@ trait AccountServiceTrait
|
||||
* @param string $name
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function storeOpposingAccount(User $user, string $name): Account
|
||||
{
|
||||
@@ -231,6 +235,7 @@ trait AccountServiceTrait
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function updateIB(Account $account, array $data): bool
|
||||
{
|
||||
@@ -313,14 +318,14 @@ trait AccountServiceTrait
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*/
|
||||
public function updateMetaData(Account $account, array $data)
|
||||
public function updateMetaData(Account $account, array $data): void
|
||||
{
|
||||
$fields = $this->validFields;
|
||||
|
||||
if ($account->accountType->type === AccountType::ASSET) {
|
||||
$fields = $this->validAssetFields;
|
||||
}
|
||||
if ($account->accountType->type === AccountType::ASSET && $data['accountRole'] === 'ccAsset') {
|
||||
if ($account->accountType->type === AccountType::ASSET && 'ccAsset' === $data['accountRole']) {
|
||||
$fields = $this->validCCFields;
|
||||
}
|
||||
/** @var AccountMetaFactory $factory */
|
||||
@@ -346,8 +351,12 @@ trait AccountServiceTrait
|
||||
Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $data[$field], $account->id, $account->name));
|
||||
}
|
||||
}
|
||||
if (null !== $entry && isset($data[$field]) && \strlen((string)$data[$field]) === 0) {
|
||||
$entry->delete();
|
||||
if (null !== $entry && isset($data[$field]) && '' === (string)$data[$field]) {
|
||||
try {
|
||||
$entry->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete entry: %s', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,7 +369,7 @@ trait AccountServiceTrait
|
||||
*/
|
||||
public function updateNote(Account $account, string $note): bool
|
||||
{
|
||||
if (0 === \strlen($note)) {
|
||||
if ('' === $note) {
|
||||
$dbNote = $account->notes()->first();
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete();
|
||||
|
||||
@@ -67,7 +67,7 @@ trait BillServiceTrait
|
||||
*/
|
||||
public function updateNote(Bill $bill, string $note): bool
|
||||
{
|
||||
if (0 === \strlen($note)) {
|
||||
if ('' === $note) {
|
||||
$dbNote = $bill->notes()->first();
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete(); // @codeCoverageIgnore
|
||||
|
||||
@@ -52,8 +52,10 @@ trait JournalServiceTrait
|
||||
}
|
||||
foreach ($data['tags'] as $string) {
|
||||
if (\strlen($string) > 0) {
|
||||
$tag = $factory->findOrCreate($string);
|
||||
$set[] = $tag->id;
|
||||
$tag = $factory->findOrCreate($string);
|
||||
if (null !== $tag) {
|
||||
$set[] = $tag->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$journal->tags()->sync($set);
|
||||
|
||||
@@ -205,7 +205,7 @@ trait RecurringTransactionTrait
|
||||
$entry->value = implode(',', $tags);
|
||||
$entry->save();
|
||||
}
|
||||
if (\count($tags) === 0) {
|
||||
if (0 === \count($tags)) {
|
||||
// delete if present
|
||||
$recurrence->recurrenceMeta()->where('name', 'tags')->delete();
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ trait TransactionServiceTrait
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): ?Account
|
||||
{
|
||||
|
||||
@@ -41,17 +41,18 @@ class AccountUpdateService
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
// update the account itself:
|
||||
$account->name = $data['name'];
|
||||
$account->active = $data['active'];
|
||||
$account->virtual_balance = trim($data['virtualBalance']) === '' ? '0' : $data['virtualBalance'];
|
||||
$account->virtual_balance = '' === trim($data['virtualBalance']) ? '0' : $data['virtualBalance'];
|
||||
$account->iban = $data['iban'];
|
||||
$account->save();
|
||||
|
||||
if (isset($data['currency_id']) && $data['currency_id'] === 0) {
|
||||
if (isset($data['currency_id']) && 0 === $data['currency_id']) {
|
||||
unset($data['currency_id']);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ class JournalUpdateService
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function update(TransactionJournal $journal, array $data): TransactionJournal
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\RecurrenceMeta;
|
||||
|
||||
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
|
||||
|
||||
@@ -69,6 +69,7 @@ class TransactionUpdateService
|
||||
* @param array $data
|
||||
*
|
||||
* @return Transaction
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function update(Transaction $transaction, array $data): Transaction
|
||||
{
|
||||
@@ -100,7 +101,7 @@ class TransactionUpdateService
|
||||
$transaction->description = $description;
|
||||
$transaction->amount = $amount;
|
||||
$transaction->foreign_amount = null;
|
||||
$transaction->transaction_currency_id = $currency->id;
|
||||
$transaction->transaction_currency_id = null === $currency ? $transaction->transaction_currency_id : $currency->id;
|
||||
$transaction->account_id = $account->id;
|
||||
$transaction->reconciled = $data['reconciled'];
|
||||
$transaction->save();
|
||||
@@ -108,11 +109,11 @@ class TransactionUpdateService
|
||||
// set foreign currency
|
||||
$foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
|
||||
// set foreign amount:
|
||||
if (null !== $data['foreign_amount'] && null !== $foreign) {
|
||||
if (null !== $foreign && null !== $data['foreign_amount']) {
|
||||
$this->setForeignCurrency($transaction, $foreign);
|
||||
$this->setForeignAmount($transaction, $foreignAmount);
|
||||
}
|
||||
if (null === $data['foreign_amount'] || null === $foreign) {
|
||||
if (null === $foreign && null === $data['foreign_amount']) {
|
||||
$this->setForeignCurrency($transaction, null);
|
||||
$this->setForeignAmount($transaction, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user