Make sure import errors end up where the user can read them.

This commit is contained in:
James Cole 2016-08-13 16:29:24 +02:00
parent ef876a165a
commit 3d63903128
3 changed files with 11 additions and 6 deletions

View File

@ -13,7 +13,6 @@ namespace FireflyIII\Import;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -27,6 +26,8 @@ class ImportEntry
{ {
/** @var array */ /** @var array */
public $certain = []; public $certain = [];
/** @var Collection */
public $errors;
/** @var string */ /** @var string */
public $externalID; public $externalID;
/** @var array */ /** @var array */
@ -35,7 +36,6 @@ class ImportEntry
public $user; public $user;
/** @var bool */ /** @var bool */
public $valid = true; public $valid = true;
/** @var int */ /** @var int */
private $amountMultiplier = 0; private $amountMultiplier = 0;
@ -60,6 +60,8 @@ class ImportEntry
$this->fields[$value] = null; $this->fields[$value] = null;
$this->certain[$value] = 0; $this->certain[$value] = 0;
} }
$this->errors = new Collection;
} }
/** /**
@ -136,12 +138,12 @@ class ImportEntry
case 'ing-debet-credit': case 'ing-debet-credit':
case 'rabo-debet-credit': case 'rabo-debet-credit':
$this->manipulateFloat('amount', 'multiply', $convertedValue); $this->manipulateFloat('amount', 'multiply', $convertedValue);
$this->applyMultiplier('amount'); // if present. $this->applyMultiplier('amount'); // if present.
break; break;
case 'tags-comma': case 'tags-comma':
case 'tags-space': case 'tags-space':
$this->appendCollection('tags', $convertedValue); $this->appendCollection('tags', $convertedValue);
break; break;
case 'external-id': case 'external-id':
$this->externalID = $convertedValue; $this->externalID = $convertedValue;
break; break;

View File

@ -205,10 +205,11 @@ class ImportStorage
private function storeSingle(int $index, ImportEntry $entry): ImportResult private function storeSingle(int $index, ImportEntry $entry): ImportResult
{ {
if ($entry->valid === false) { 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 = new ImportResult();
$result->failed(); $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; return $result;
} }

View File

@ -102,6 +102,7 @@ class ImportValidator
{ {
if ($entry->fields['amount'] == 0) { if ($entry->fields['amount'] == 0) {
$entry->valid = false; $entry->valid = false;
$entry->errors->push('Amount of transaction is zero, cannot handle.');
Log::warning('Amount of transaction is zero, cannot handle.'); Log::warning('Amount of transaction is zero, cannot handle.');
return $entry; return $entry;
@ -383,6 +384,7 @@ class ImportValidator
} }
Log::warning(sprintf('Opposing account is of type %s, cannot handle this.', $type)); Log::warning(sprintf('Opposing account is of type %s, cannot handle this.', $type));
$entry->valid = false; $entry->valid = false;
$entry->errors->push(sprintf('Opposing account is of type %s, cannot handle this.', $type));
return $entry; return $entry;
} }