From bfe73cfa5731f3ee790f2a21182749c3107b6ee2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 17 Dec 2023 15:59:51 +0100 Subject: [PATCH] Fix warnings for zero amount --- app/Console/AutoImports.php | 9 ++------- app/Console/Commands/Import.php | 18 +++++++----------- app/Events/ImportedTransactions.php | 11 ++++++----- .../Import/ConversionController.php | 2 +- .../Routine/TransactionProcessor.php | 1 - .../Nordigen/Conversion/RoutineManager.php | 10 +++++++--- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/app/Console/AutoImports.php b/app/Console/AutoImports.php index 94ffb17f..22499377 100644 --- a/app/Console/AutoImports.php +++ b/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 { diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index c46cf2a5..cd43c338 100644 --- a/app/Console/Commands/Import.php +++ b/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( diff --git a/app/Events/ImportedTransactions.php b/app/Events/ImportedTransactions.php index eb984167..c7c76723 100644 --- a/app/Events/ImportedTransactions.php +++ b/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; } diff --git a/app/Http/Controllers/Import/ConversionController.php b/app/Http/Controllers/Import/ConversionController.php index b80992d3..ea4e1924 100644 --- a/app/Http/Controllers/Import/ConversionController.php +++ b/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()); diff --git a/app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php b/app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php index 1ed43b96..055aabe7 100644 --- a/app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php +++ b/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; } diff --git a/app/Services/Nordigen/Conversion/RoutineManager.php b/app/Services/Nordigen/Conversion/RoutineManager.php index 72e844ef..1037904b 100644 --- a/app/Services/Nordigen/Conversion/RoutineManager.php +++ b/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(),