Skip to content

Firefly III: a personal finances manager

Better reporting for double imported rows. See also #164

James Cole106665a4683a
diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.php
index 445dc18caa..cf0f90eb24 100644
--- a/app/Import/ImportStorage.php
+++ b/app/Import/ImportStorage.php
@@ -85,14 +85,17 @@ class ImportStorage
/**
* @param string $hash
*
- * @return bool
+ * @return TransactionJournal
*/
- private function alreadyImported(string $hash): bool
+ private function alreadyImported(string $hash): TransactionJournal
{
- $count = TransactionJournalMeta::where('name', 'originalImportHash')->where('data', json_encode($hash))->count();
+ $meta = TransactionJournalMeta::where('name', 'originalImportHash')->where('data', json_encode($hash))->first(['journal_meta.*']);
+ if (!is_null($meta)) {
+ return $meta->transactionjournal;
+ }
- return $count > 0;
+ return new TransactionJournal;
}
/**
@@ -252,12 +255,15 @@ class ImportStorage
return $result;
}
-
- if ($this->alreadyImported($entry->hash)) {
- Log::warning(sprintf('Cannot import row %d, because it has already been imported.', $index));
+ $alreadyImported = $this->alreadyImported($entry->hash);
+ if (!is_null($alreadyImported->id)) {
+ Log::warning(sprintf('Cannot import row %d, because it has already been imported (journal #%d).', $index, $alreadyImported->id));
$result = new ImportResult();
$result->failed();
- $errorText = sprintf('Row #%d: This row has been imported before.', $index);
+ $errorText = trans(
+ 'firefly.import_double',
+ ['row' => $index, 'link' => route('transactions.show', [$alreadyImported->id]), 'description' => $alreadyImported->description]
+ );
$result->appendError($errorText);
$extendedStatus = $this->job->extended_status;
$extendedStatus['errors'][] = $errorText;
diff --git a/public/js/ff/import/status.js b/public/js/ff/import/status.js
index 8d98731f1b..f8415ae119 100644
--- a/public/js/ff/import/status.js
+++ b/public/js/ff/import/status.js
@@ -71,7 +71,7 @@ function reportErrors(data) {
// fill the list with error texts
$('#import-status-error-list').empty();
for (var i = 0; i < data.errors.length; i++) {
- var item = $('<li>').text(data.errors[i]);
+ var item = $('<li>').html(data.errors[i]);
$('#import-status-error-list').append(item);
}
}
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 93769ecd60..80fc765ada 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -790,4 +790,5 @@ return [
'import_error_multi' => 'Some errors occured during the import.',
'import_error_fatal' => 'There was an error during the import routine. Please check the log files. The error seems to be:',
'import_error_timeout' => 'The import seems to have timed out. If this error persists, please import your data using the console command.',
+ 'import_double' => 'Row #:row: This row has been imported before, and is stored in <a href=":link">:description</a>.',
];