mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve import routine.
This commit is contained in:
parent
3b3579025d
commit
e4e1873770
@ -14,10 +14,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Artisan;
|
||||
use FireflyIII\Import\Logging\CommandHandler;
|
||||
use FireflyIII\Import\Routine\ImportRoutine;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
|
||||
/**
|
||||
* Class CreateImport
|
||||
@ -73,30 +77,55 @@ class CreateImport extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info(sprintf('Going to create a job to import file: %s', $file));
|
||||
$this->info(sprintf('Using configuration file: %s', $configuration));
|
||||
$this->info(sprintf('Import into user: #%d (%s)', $user->id, $user->email));
|
||||
$this->info(sprintf('Type of import: %s', $type));
|
||||
$this->line(sprintf('Going to create a job to import file: %s', $file));
|
||||
$this->line(sprintf('Using configuration file: %s', $configuration));
|
||||
$this->line(sprintf('Import into user: #%d (%s)', $user->id, $user->email));
|
||||
$this->line(sprintf('Type of import: %s', $type));
|
||||
|
||||
|
||||
/** @var ImportJobRepositoryInterface $jobRepository */
|
||||
$jobRepository = app(ImportJobRepositoryInterface::class);
|
||||
$jobRepository->setUser($user);
|
||||
$job = $jobRepository->create($type);
|
||||
$this->line(sprintf('Created job "%s"...', $job->key));
|
||||
$this->line(sprintf('Created job "%s"', $job->key));
|
||||
|
||||
|
||||
Artisan::call('firefly:encrypt-file', ['file' => $file, 'key' => $job->key]);
|
||||
$this->line('Stored import data...');
|
||||
|
||||
|
||||
$job->configuration = $configurationData;
|
||||
$job->status = 'configured';
|
||||
$job->save();
|
||||
$this->line('Stored configuration...');
|
||||
|
||||
|
||||
if ($this->option('start') === true) {
|
||||
$this->line('The import will start in a moment. This process is not visible...');
|
||||
Log::debug('Go for import!');
|
||||
Artisan::call('firefly:start-import', ['key' => $job->key]);
|
||||
$this->line('Done!');
|
||||
|
||||
// normally would refer to other firefly:start-import but that doesn't seem to work all to well...
|
||||
$monolog = Log::getMonolog();
|
||||
$handler = new CommandHandler($this);
|
||||
$formatter = new LineFormatter(null, null, false, true);
|
||||
$handler->setFormatter($formatter);
|
||||
$monolog->pushHandler($handler);
|
||||
|
||||
|
||||
// start the actual routine:
|
||||
/** @var ImportRoutine $routine */
|
||||
$routine = app(ImportRoutine::class);
|
||||
$routine->setJob($job);
|
||||
$routine->run();
|
||||
|
||||
// give feedback.
|
||||
/** @var MessageBag $error */
|
||||
foreach ($routine->errors as $index => $error) {
|
||||
$this->error(sprintf('Error importing line #%d: %s', $index, $error));
|
||||
}
|
||||
$this->line(
|
||||
sprintf('The import has finished. %d transactions have been imported out of %d records.', $routine->journals->count(), $routine->lines)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -36,7 +36,8 @@ class CommandHandler extends AbstractProcessingHandler
|
||||
{
|
||||
parent::__construct();
|
||||
$this->command = $command;
|
||||
$this->changeLevel(env('LOG_LEVEL', 'debug'));
|
||||
|
||||
$this->changeLevel(env('APP_LOG_LEVEL', 'info'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,9 +57,10 @@ class CommandHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
private function changeLevel(string $level)
|
||||
{
|
||||
$level = strtoupper($level);
|
||||
if (defined(sprintf('Logger::%s', $level))) {
|
||||
$this->setLevel(constant(sprintf('Logger::%s', $level)));
|
||||
$level = strtoupper($level);
|
||||
$reference = sprintf('\Monolog\Logger::%s', $level);
|
||||
if (defined($reference)) {
|
||||
$this->setLevel(constant($reference));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user