Fix broken duplication test routine.

This commit is contained in:
James Cole 2019-08-09 18:35:34 +02:00
parent 1e3d85439e
commit b09504d0f7
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 15 additions and 12 deletions

View File

@ -384,13 +384,14 @@ class TransactionJournalFactory
*/
private function hashArray(NullArrayObject $row): string
{
$row['import_hash_v2'] = null;
$row['original_source'] = null;
$json = json_encode($row);
$dataRow = $row->getArrayCopy();
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
$json = json_encode($dataRow);
if (false === $json) {
// @codeCoverageIgnoreStart
$json = json_encode((string)microtime());
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $row->getArrayCopy());
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
// @codeCoverageIgnoreEnd
}
$hash = hash('sha256', $json);

View File

@ -234,6 +234,16 @@ class ImportArrayStorage
private function storeGroup(int $index, array $group): ?TransactionGroup
{
Log::debug(sprintf('Going to store entry #%d', $index + 1));
// do some basic error catching.
foreach ($group['transactions'] as $groupIndex => $transaction) {
$group['transactions'][$groupIndex]['date'] = Carbon::parse($transaction['date'], config('app.timezone'));
$group['transactions'][$groupIndex]['description'] = '' === $transaction['description'] ? '(empty description)' : $transaction['description'];
}
// do duplicate detection!
if ($this->duplicateDetected($index, $group)) {
Log::warning(sprintf('Row #%d seems to be a imported already and will be ignored.', $index));
@ -241,14 +251,6 @@ class ImportArrayStorage
return null;
}
Log::debug(sprintf('Going to store entry #%d', $index + 1));
// do some basic error catching.
foreach ($group['transactions'] as $index => $transaction) {
$group['transactions'][$index]['date'] = Carbon::parse($transaction['date'], config('app.timezone'));
$group['transactions'][$index]['description'] = '' === $transaction['description'] ? '(empty description)' : $transaction['description'];
}
// store the group
try {
$newGroup = $this->groupRepos->store($group);