Skip to content

Firefly III: a personal finances manager

Removed the ImportResult class because it was lame.

James Coleff3396e28643
diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php
index 94066089a2..f1345172b5 100644
--- a/app/Console/Commands/Import.php
+++ b/app/Console/Commands/Import.php
@@ -12,9 +12,9 @@ declare(strict_types = 1);
namespace FireflyIII\Console\Commands;
use FireflyIII\Import\ImportProcedure;
-use FireflyIII\Import\ImportResult;
use FireflyIII\Import\Logging\CommandHandler;
use FireflyIII\Models\ImportJob;
+use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Log;
@@ -70,23 +70,29 @@ class Import extends Command
$result = ImportProcedure::runImport($job);
-
/**
- * @var int $index
- * @var ImportResult $entry
+ * @var int $index
+ * @var TransactionJournal $journal
*/
- foreach ($result as $index => $entry) {
- if ($entry->isSuccess()) {
- $this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $entry->journal->id));
+ foreach ($result as $index => $journal) {
+ if (!is_null($journal->id)) {
+ $this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id));
continue;
}
- $errors = join(', ', $entry->errors->all());
- $this->error(sprintf('Could not store line #%d, because: %s', $index, $errors));
+ $this->error(sprintf('Could not store line #%d', $index));
}
-
$this->line('The import has completed.');
+ // get any errors from the importer:
+ $extendedStatus = $job->extended_status;
+ if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) {
+ $this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors'])));
+ foreach ($extendedStatus['errors'] as $error) {
+ $this->error($error);
+ }
+ }
+ return;
}
/**
diff --git a/app/Import/ImportResult.php b/app/Import/ImportResult.php
deleted file mode 100644
index a65612d854..0000000000
--- a/app/Import/ImportResult.php
+++ /dev/null
@@ -1,188 +0,0 @@
-<?php
-/**
- * ImportResult.php
- * Copyright (C) 2016 [email protected]
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- */
-
-declare(strict_types = 1);
-
-namespace FireflyIII\Import;
-
-use FireflyIII\Models\TransactionJournal;
-use Illuminate\Support\Collection;
-
-/**
- * Class ImportResult
- *
- * @package FireflyIII\Import
- */
-class ImportResult
-{
- const IMPORT_SUCCESS = 1;
- const IMPORT_FAILED = 0;
- const IMPORT_VALID = 2;
-
- /** @var Collection */
- public $errors;
- /** @var TransactionJournal */
- public $journal;
- /** @var Collection */
- public $messages;
- /** @var int */
- public $status = 0;
- /** @var string */
- public $title = 'No result yet.';
- /** @var Collection */
- public $warnings;
-
- /**
- * ImportResult constructor.
- */
- public function __construct()
- {
- $this->errors = new Collection;
- $this->warnings = new Collection;
- $this->messages = new Collection;
- }
-
- /**
- * @param string $error
- *
- * @return $this
- */
- public function appendError(string $error)
- {
- $this->errors->push($error);
-
- return $this;
- }
-
- /**
- * @param string $message
- *
- * @return $this
- */
- public function appendMessage(string $message)
- {
- $this->messages->push($message);
-
- return $this;
- }
-
- /**
- * @param string $title
- *
- * @return $this
- */
- public function appendTitle(string $title)
- {
- $this->title .= $title;
-
- return $this;
- }
-
- /**
- * @param string $warning
- *
- * @return $this
- */
- public function appendWarning(string $warning)
- {
- $this->warnings->push($warning);
-
- return $this;
- }
-
- /**
- * @return $this
- */
- public function failed()
- {
- $this->status = self::IMPORT_FAILED;
-
- return $this;
- }
-
- /**
- * @return bool
- */
- public function isSuccess(): bool
- {
- return $this->status === self::IMPORT_SUCCESS;
- }
-
- /**
- * @param Collection $errors
- */
- public function setErrors(Collection $errors)
- {
- $this->errors = $errors;
- }
-
- /**
- * @param TransactionJournal $journal
- */
- public function setJournal(TransactionJournal $journal)
- {
- $this->journal = $journal;
- }
-
- /**
- * @param Collection $messages
- */
- public function setMessages(Collection $messages)
- {
- $this->messages = $messages;
- }
-
- /**
- * @param string $title
- *
- * @return $this
- */
- public function setTitle(string $title)
- {
- $this->title = $title;
-
- return $this;
- }
-
- /**
- * @param Collection $warnings
- */
- public function setWarnings(Collection $warnings)
- {
- $this->warnings = $warnings;
- }
-
- /**
- * @return $this
- */
- public function success()
- {
- $this->status = self::IMPORT_SUCCESS;
-
- return $this;
- }
-
- /**
- * @return bool
- */
- public function valid(): bool
- {
- return $this->status === self::IMPORT_VALID;
- }
-
- /**
- *
- */
- public function validated()
- {
- $this->status = self::IMPORT_VALID;
- }
-
-
-}