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 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 ImportEntry
public $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;
}
/**

View File

@ -205,10 +205,11 @@ class ImportStorage
private 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;
}

View File

@ -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;
}