Browse Source

Fix warnings for zero amount

pull/492/head
James Cole 2 years ago
parent
commit
bfe73cfa57
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 9
      app/Console/AutoImports.php
  2. 18
      app/Console/Commands/Import.php
  3. 11
      app/Events/ImportedTransactions.php
  4. 2
      app/Http/Controllers/Import/ConversionController.php
  5. 1
      app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php
  6. 10
      app/Services/Nordigen/Conversion/RoutineManager.php

9
app/Console/AutoImports.php

@ -222,9 +222,6 @@ trait AutoImports
// crash here if the conversion failed.
if (0 !== count($this->conversionErrors)) {
app('log')->error('Conversion errors', $this->conversionErrors);
app('log')->error('Conversion warnings', $this->conversionWarnings);
app('log')->error('Conversion messages', $this->conversionMessages);
$this->error(sprintf('Too many errors in the data conversion (%d), exit.', count($this->conversionErrors)));
// report about it anyway:
@ -280,9 +277,6 @@ trait AutoImports
// crash here if the conversion failed.
if (0 !== count($this->conversionErrors)) {
app('log')->error('Conversion errors', $this->conversionErrors);
app('log')->error('Conversion warnings', $this->conversionWarnings);
app('log')->error('Conversion messages', $this->conversionMessages);
$this->error(sprintf('Too many errors in the data conversion (%d), exit.', count($this->conversionErrors)));
throw new ImporterErrorException('Too many errors in the data conversion.');
}
@ -427,12 +421,13 @@ trait AutoImports
$this->conversionErrors = $manager->getAllErrors();
}
if (0 === count($transactions)) {
app('log')->error('Zero transactions!');
app('log')->error('[a] Zero transactions!');
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
}
// save transactions in 'jobs' directory under the same key as the conversion thing.
$disk = Storage::disk('jobs');
try {

18
app/Console/Commands/Import.php

@ -136,18 +136,14 @@ final class Import extends Command
// crash here if the conversion failed.
if (0 !== count($this->conversionErrors)) {
app('log')->error('Conversion errors', $this->conversionErrors);
app('log')->error('Conversion warnings', $this->conversionWarnings);
app('log')->error('Conversion messages', $this->conversionMessages);
$this->error(sprintf('Too many errors in the data conversion (%d), exit.', count($this->conversionErrors)));
throw new ImporterErrorException('Too many errors in the data conversion.');
$this->error('There are many errors in the data conversion. The import will stop here.');
}
if (0 === count($this->conversionErrors)) {
$this->line(sprintf('Done converting from file %s using configuration %s.', $file, $config));
$this->startImport($configuration);
$this->reportImport();
$this->line('Done!');
}
$this->line(sprintf('Done converting from file %s using configuration %s.', $file, $config));
$this->startImport($configuration);
$this->reportImport();
$this->line('Done!');
event(
new ImportedTransactions(

11
app/Events/ImportedTransactions.php

@ -50,17 +50,18 @@ class ImportedTransactions
app('log')->debug('Created event ImportedTransactions with filtering (2)');
// filter messages:
$this->messages = $this->filterArray($messages);
$this->warnings = $this->filterArray($warnings);
$this->errors = $this->filterArray($errors);
$this->messages = $this->filterArray('message(s)', $messages);
$this->warnings = $this->filterArray('warning(s)',$warnings);
$this->errors = $this->filterArray('error(s)', $errors);
}
/**
* @param array $collection
*
* @string $title
* @return array
*/
private function filterArray(array $collection): array
private function filterArray(string $title, array $collection): array
{
$count = 0;
$newCollection = [];
@ -77,7 +78,7 @@ class ImportedTransactions
$newCollection[$index] = $newSet;
}
}
app('log')->debug(sprintf('Array contains %d line(s)', $count));
app('log')->debug(sprintf('Array contains %d %s', $count, $title));
return $newCollection;
}

2
app/Http/Controllers/Import/ConversionController.php

@ -205,7 +205,7 @@ class ConversionController extends Controller
}
app('log')->debug(sprintf('Conversion routine "%s" was started successfully.', $flow));
if (0 === count($transactions)) {
app('log')->error('Zero transactions!');
app('log')->error('[b] Zero transactions!');
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED);
return response()->json($importJobStatus->toArray());

1
app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php

@ -110,7 +110,6 @@ class TransactionProcessor
app('log')->debug(sprintf('Done downloading transactions for account %s "%s"', $key, $account));
}
app('log')->debug('Done with download');
return $return;
}

10
app/Services/Nordigen/Conversion/RoutineManager.php

@ -116,7 +116,11 @@ class RoutineManager implements RoutineManagerInterface
}
// collect errors from transactionProcessor.
if (0 === count($nordigen)) {
$total = 0;
foreach($nordigen as $accountId => $transactions) {
$total += count($transactions);
}
if (0 === $total) {
app('log')->warning('Downloaded nothing, will return nothing.');
// add error to current error thing:
$this->addError(0, 'Zero transactions found at GoCardless');
@ -170,7 +174,7 @@ class RoutineManager implements RoutineManagerInterface
*/
private function mergeWarnings(int $count): void
{
$this->allErrors = $this->mergeArrays(
$this->allWarnings = $this->mergeArrays(
[
$this->getWarnings(),
$this->transactionFilter->getWarnings(),
@ -185,7 +189,7 @@ class RoutineManager implements RoutineManagerInterface
*/
private function mergeMessages(int $count): void
{
$this->allErrors = $this->mergeArrays(
$this->allMessages = $this->mergeArrays(
[
$this->getMessages(),
$this->transactionFilter->getMessages(),

Loading…
Cancel
Save