mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More language lines. Add a check for double lines.
This commit is contained in:
@@ -15,6 +15,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -81,6 +82,19 @@ class ImportStorage
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function alreadyImported(string $hash): bool
|
||||
{
|
||||
|
||||
$count = TransactionJournalMeta::where('name', 'originalImportHash')->where('data', json_encode($hash))->count();
|
||||
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
*
|
||||
@@ -183,6 +197,7 @@ class ImportStorage
|
||||
*/
|
||||
private function storeJournal($entry): TransactionJournal
|
||||
{
|
||||
|
||||
$billId = is_null($entry->fields['bill']) ? null : $entry->fields['bill']->id;
|
||||
$journalData = [
|
||||
'user_id' => $entry->user->id,
|
||||
@@ -204,6 +219,13 @@ class ImportStorage
|
||||
}
|
||||
Log::debug('Created journal', ['id' => $journal->id]);
|
||||
|
||||
// save hash as meta value:
|
||||
$meta = new TransactionJournalMeta;
|
||||
$meta->name = 'originalImportHash';
|
||||
$meta->data = $entry->hash;
|
||||
$meta->transactionjournal()->associate($journal);
|
||||
$meta->save();
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
@@ -230,6 +252,21 @@ class ImportStorage
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($this->alreadyImported($entry->hash)) {
|
||||
Log::warning(sprintf('Cannot import row %d, because it has already been imported.', $index));
|
||||
$result = new ImportResult();
|
||||
$result->failed();
|
||||
$errorText = sprintf('Row #%d: This row has been imported before.', $index);
|
||||
$result->appendError($errorText);
|
||||
$extendedStatus = $this->job->extended_status;
|
||||
$extendedStatus['errors'][] = $errorText;
|
||||
$this->job->extended_status = $extendedStatus;
|
||||
$this->job->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Going to store row %d', $index));
|
||||
|
||||
|
||||
|
@@ -86,7 +86,6 @@ class ImportValidator
|
||||
|
||||
$newCollection->put($index, $entry);
|
||||
$this->job->addStepsDone(1);
|
||||
sleep(1);
|
||||
}
|
||||
Log::notice(sprintf('Finished validating %d entry(ies).', $newCollection->count()));
|
||||
|
||||
|
@@ -66,7 +66,6 @@ class CsvImporter implements ImporterInterface
|
||||
$this->collection->put($line, $importEntry);
|
||||
$this->job->addTotalSteps(3);
|
||||
$this->job->addStepsDone(1);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
|
||||
|
@@ -66,7 +66,7 @@ class TransactionJournalMeta extends Model
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function transactionjournal(): BelongsTo
|
||||
public function transactionJournal(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('FireflyIII\Models\TransactionJournal');
|
||||
}
|
||||
|
Reference in New Issue
Block a user