Skip to content

Commit

Permalink
Fix also for auto import
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Nov 23, 2024
1 parent afdd5b5 commit 84dab41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
28 changes: 25 additions & 3 deletions app/Console/AutoImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ private function importFile(string $directory, string $file): int
// crash here if the conversion failed.
if (0 !== count($this->conversionErrors)) {
$this->error(sprintf('[a] Too many errors in the data conversion (%d), exit.', count($this->conversionErrors)));
app('log')->debug(sprintf('Exit code is %s.', ExitCode::TOO_MANY_ERRORS_PROCESSING->name));
$exitCode = ExitCode::TOO_MANY_ERRORS_PROCESSING->value;

// could still be that there were simply no transactions (from GoCardless). This can result
// in another exit code.
if ($this->isNothingDownloaded()) {
app('log')->debug(sprintf('Exit code changed to %s.', ExitCode::NOTHING_WAS_IMPORTED->name));
$exitCode = ExitCode::NOTHING_WAS_IMPORTED->value;
}

// report about it anyway:
event(
Expand All @@ -272,9 +281,7 @@ private function importFile(string $directory, string $file): int
$this->conversionRateLimits
)
);
app('log')->debug(sprintf('Exit code is %s.', ExitCode::TOO_MANY_ERRORS_PROCESSING->name));

return ExitCode::TOO_MANY_ERRORS_PROCESSING->value;
return $exitCode;
}

$this->line(sprintf('Done converting from file %s using configuration %s.', $importableFile, $jsonFile));
Expand Down Expand Up @@ -666,4 +673,19 @@ private function importUpload(string $jsonFile, string $importableFile): void
)
);
}

protected function isNothingDownloaded(): bool
{
/** @var array $errors */
foreach ($this->conversionErrors as $errors) {
/** @var string $error */
foreach ($errors as $error) {
if (str_contains($error, '[a111]')) {
return true;
}
}
}

return false;
}
}
13 changes: 0 additions & 13 deletions app/Console/Commands/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,5 @@ public function handle(): int
return $exitCode;
}

private function isNothingDownloaded(): bool
{
/** @var array $errors */
foreach ($this->conversionErrors as $errors) {
/** @var string $error */
foreach ($errors as $error) {
if (str_contains($error, '[a111]')) {
return true;
}
}
}

return false;
}
}

0 comments on commit 84dab41

Please sign in to comment.