Browse Source

More exit codes.

pull/687/head
James Cole 1 year ago
parent
commit
bcae3996ea
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 17
      app/Console/Commands/AutoImport.php
  2. 19
      app/Console/Commands/Import.php

17
app/Console/Commands/AutoImport.php

@ -62,7 +62,7 @@ final class AutoImport extends Command
if (false === $access) {
$this->error(sprintf('[a] No access, or no connection is possible to your local Firefly III instance at %s.', config('importer.url')));
return 1;
return 64;
}
$argument = (string) ($this->argument('directory') ?? './');
@ -72,12 +72,12 @@ final class AutoImport extends Command
if (false === $directory) {
$this->error(sprintf('Path "%s" is not a valid location.', $argument));
return 1;
return 65;
}
if (!$this->isAllowedPath($directory)) {
$this->error(sprintf('Path "%s" is not in the list of allowed paths (IMPORT_DIR_ALLOWLIST).', $directory));
return 1;
return 66;
}
$this->line(sprintf('Going to automatically import everything found in %s (%s)', $directory, $argument));
@ -87,18 +87,11 @@ final class AutoImport extends Command
$this->info('To learn more about this process, read the docs:');
$this->info('https://docs.firefly-iii.org/');
return 1;
return 67;
}
$this->line(sprintf('Found %d (importable +) JSON file sets in %s', count($files), $directory));
try {
$result = $this->importFiles($directory, $files);
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
$this->error(sprintf('Import exception (see the logs): %s', $e->getMessage()));
return 1;
}
$result = $this->importFiles($directory, $files);
return $result ? 0 : 1;
}

19
app/Console/Commands/Import.php

@ -69,7 +69,7 @@ final class Import extends Command
if (false === $access) {
$this->error(sprintf('No access granted, or no connection is possible to your local Firefly III instance at %s.', config('importer.url')));
return 1;
return 64;
}
$this->info(sprintf('Welcome to the Firefly III data importer, v%s', config('importer.version')));
@ -83,7 +83,7 @@ final class Import extends Command
if (!$this->isAllowedPath($directory)) {
$this->error(sprintf('Path "%s" is not in the list of allowed paths (IMPORT_DIR_ALLOWLIST).', $directory));
return 1;
return 65;
}
}
@ -93,7 +93,7 @@ final class Import extends Command
if (!$this->isAllowedPath($directory)) {
$this->error(sprintf('Path "%s" is not in the list of allowed paths (IMPORT_DIR_ALLOWLIST).', $directory));
return 1;
return 66;
}
}
@ -102,7 +102,7 @@ final class Import extends Command
$this->error($message);
app('log')->error($message);
return 1;
return 68;
}
$jsonResult = $this->verifyJSON($config);
@ -110,7 +110,7 @@ final class Import extends Command
$message = 'The importer can\'t import: could not decode the JSON in the config file.';
$this->error($message);
return 1;
return 69;
}
$configuration = Configuration::fromArray(json_decode(file_get_contents($config), true));
if ('file' === $configuration->getFlow() && (!file_exists($file) || (file_exists($file) && !is_file($file)))) {
@ -118,7 +118,7 @@ final class Import extends Command
$this->error($message);
app('log')->error($message);
return 1;
return 70;
}
$configuration->updateDateRange();
@ -134,8 +134,10 @@ final class Import extends Command
$this->reportConversion();
// crash here if the conversion failed.
$exitCode = 0;
if (0 !== count($this->conversionErrors)) {
$this->error('There are many errors in the data conversion. The import will stop here.');
$exitCode = 72;
}
if (0 === count($this->conversionErrors)) {
$this->line(sprintf('Done converting from file %s using configuration %s.', $file, $config));
@ -153,7 +155,10 @@ final class Import extends Command
array_merge($this->importErrors, $this->conversionErrors)
)
);
if(0 !== count($this->importErrors)) {
$exitCode = 1;
}
return 0;
return $exitCode;
}
}
Loading…
Cancel
Save