Browse Source

Replace import of Log.

pull/20/head
James Cole 4 years ago
parent
commit
d7b19db676
No known key found for this signature in database GPG Key ID: BDE6667570EADBD5
  1. 15
      app/Console/AutoImports.php
  2. 3
      app/Console/Commands/AutoImport.php
  3. 7
      app/Console/Commands/Import.php
  4. 3
      app/Console/VerifyJSON.php

15
app/Console/AutoImports.php

@ -36,7 +36,6 @@ use App\Services\Shared\Import\Status\SubmissionStatusManager;
use App\Services\Spectre\Conversion\RoutineManager as SpectreRoutineManager;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use JsonException;
use Log;
use Storage;
/**
@ -204,7 +203,7 @@ trait AutoImports
$this->conversionWarnings = [];
$this->conversionErrors = [];
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
switch ($configuration->getFlow()) {
default:
@ -235,14 +234,14 @@ trait AutoImports
try {
$transactions = $manager->start();
} catch (ImporterErrorException $e) {
Log::error($e->getMessage());
app('log')->error($e->getMessage());
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
}
if (0 === count($transactions)) {
Log::error('Zero transactions!');
app('log')->error('Zero transactions!');
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
@ -254,7 +253,7 @@ trait AutoImports
try {
$disk->put(sprintf('%s.json', $this->identifier), json_encode($transactions, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
} catch (JsonException $e) {
Log::error(sprintf('JSON exception: %s', $e->getMessage()));
app('log')->error(sprintf('JSON exception: %s', $e->getMessage()));
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
@ -302,7 +301,7 @@ trait AutoImports
*/
private function startImport(Configuration $configuration): void
{
Log::debug(sprintf('Now at %s', __METHOD__));
app('log')->debug(sprintf('Now at %s', __METHOD__));
$routine = new RoutineManager($this->identifier);
SubmissionStatusManager::startOrFindSubmission($this->identifier);
$disk = Storage::disk('jobs');
@ -324,7 +323,7 @@ trait AutoImports
try {
$json = $disk->get($fileName);
$transactions = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
Log::debug(sprintf('Found %d transactions on the drive.', count($transactions)));
app('log')->debug(sprintf('Found %d transactions on the drive.', count($transactions)));
} catch (FileNotFoundException | JsonException $e) {
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
$message = sprintf('File "%s" could not be decoded, cannot continue..', $fileName);
@ -345,7 +344,7 @@ trait AutoImports
try {
$routine->start();
} catch (ImporterErrorException $e) {
Log::error($e->getMessage());
app('log')->error($e->getMessage());
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
SubmissionStatusManager::addError($this->identifier, 0, $e->getMessage());
$this->importMessages = $routine->getAllMessages();

3
app/Console/Commands/AutoImport.php

@ -29,7 +29,6 @@ use App\Console\HaveAccess;
use App\Console\VerifyJSON;
use App\Exceptions\ImporterErrorException;
use Illuminate\Console\Command;
use Log;
/**
* Class AutoImport
@ -81,7 +80,7 @@ class AutoImport extends Command
try {
$this->importFiles($directory, $files);
} catch (ImporterErrorException $e) {
Log::error($e->getMessage());
app('log')->error($e->getMessage());
$this->error(sprintf('Import exception (see the logs): %s', $e->getMessage()));
}

7
app/Console/Commands/Import.php

@ -30,7 +30,6 @@ use App\Console\VerifyJSON;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use Illuminate\Console\Command;
use Log;
/**
* Class Import
@ -71,14 +70,14 @@ class Import extends Command
}
$this->info(sprintf('Welcome to the Firefly III data importer, v%s', config('importer.version')));
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$file = (string) $this->argument('file');
$config = (string) $this->argument('config');
if (!file_exists($config) || (file_exists($config) && !is_file($config))) {
$message = sprintf('The importer can\'t import: configuration file "%s" does not exist or could not be read.', $config);
$this->error($message);
Log::error($message);
app('log')->error($message);
return 1;
}
@ -95,7 +94,7 @@ class Import extends Command
if ('csv' === $configuration->getFlow() && (!file_exists($file) || (file_exists($file) && !is_file($file)))) {
$message = sprintf('The importer can\'t import: CSV file "%s" does not exist or could not be read.', $file);
$this->error($message);
Log::error($message);
app('log')->error($message);
return 1;
}

3
app/Console/VerifyJSON.php

@ -26,7 +26,6 @@ namespace App\Console;
use Exception;
use JsonException;
use Log;
/**
* Trait VerifyJSON
@ -46,7 +45,7 @@ trait VerifyJSON
json_decode($json, true, 512, JSON_THROW_ON_ERROR);
} catch (Exception | JsonException $e) {
$message = sprintf('The importer can\'t import: could not decode the JSON in the config file: %s', $e->getMessage());
Log::error($message);
app('log')->error($message);
return false;

Loading…
Cancel
Save