Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Make sure import errors end up where the user can read them.
James Cole3d639031287b
diff --git a/app/Import/ImportEntry.php b/app/Import/ImportEntry.phpindex 3f2d577a2c..759263171e 100644--- a/app/Import/ImportEntry.php+++ b/app/Import/ImportEntry.php@@ -13,7 +13,6 @@ namespace FireflyIII\Import;use Carbon\Carbon;use FireflyIII\Exceptions\FireflyException;-use FireflyIII\Models\Account;use FireflyIII\User;use Illuminate\Support\Collection;use Log;@@ -27,6 +26,8 @@ class ImportEntry{/** @var array */public $certain = [];+ /** @var Collection */+ public $errors;/** @var string */public $externalID;/** @var array */@@ -35,7 +36,6 @@ class ImportEntrypublic $user;/** @var bool */public $valid = true;-/** @var int */private $amountMultiplier = 0;@@ -60,6 +60,8 @@ class ImportEntry$this->fields[$value] = null;$this->certain[$value] = 0;}+ $this->errors = new Collection;+}/**@@ -136,12 +138,12 @@ class ImportEntrycase 'ing-debet-credit':case 'rabo-debet-credit':$this->manipulateFloat('amount', 'multiply', $convertedValue);- $this->applyMultiplier('amount'); // if present.+ $this->applyMultiplier('amount'); // if present.break;case 'tags-comma':case 'tags-space':$this->appendCollection('tags', $convertedValue);- break;+ break;case 'external-id':$this->externalID = $convertedValue;break;diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.phpindex 3f14f636e7..28497a39d0 100644--- a/app/Import/ImportStorage.php+++ b/app/Import/ImportStorage.php@@ -205,10 +205,11 @@ class ImportStorageprivate function storeSingle(int $index, ImportEntry $entry): ImportResult{if ($entry->valid === false) {- Log::warning(sprintf('Cannot import row %d, because valid=false', $index));+ Log::warning(sprintf('Cannot import row %d, because the entry is not valid.', $index));$result = new ImportResult();$result->failed();- $result->appendError(sprintf('Cannot import row %d, because the current line is not valid.', $index));+ $errors = join(', ', $entry->errors->all());+ $result->appendError(sprintf('Row #%d: ' . $errors, $index));return $result;}diff --git a/app/Import/ImportValidator.php b/app/Import/ImportValidator.phpindex 1f837118dd..9724bde290 100644--- a/app/Import/ImportValidator.php+++ b/app/Import/ImportValidator.php@@ -102,6 +102,7 @@ class ImportValidator{if ($entry->fields['amount'] == 0) {$entry->valid = false;+ $entry->errors->push('Amount of transaction is zero, cannot handle.');Log::warning('Amount of transaction is zero, cannot handle.');return $entry;@@ -383,6 +384,7 @@ class ImportValidator}Log::warning(sprintf('Opposing account is of type %s, cannot handle this.', $type));$entry->valid = false;+ $entry->errors->push(sprintf('Opposing account is of type %s, cannot handle this.', $type));return $entry;}