argument('key'); $job = ImportJob::whereKey($jobKey)->first(); if (!$this->isValid($job)) { return; } $this->line('Going to import job with key "' . $job->key . '" of type ' . $job->file_type); $monolog = Log::getMonolog(); $handler = new CommandHandler($this); $monolog->pushHandler($handler); $result = ImportProcedure::run($job); /** * @var int $index * @var ImportResult $entry */ foreach ($result as $index => $entry) { if ($entry->isSuccess()) { $this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $entry->journal->id)); continue; } $errors = join(', ', $entry->errors->all()); $this->error(sprintf('Could not store line #%d, because: %s', $index, $errors)); } $this->line('The import has completed.'); } /** * @param ImportJob $job * * @return bool */ private function isValid(ImportJob $job): bool { if (is_null($job)) { $this->error('This job does not seem to exist.'); return false; } if ($job->status != 'settings_complete') { $this->error('This job is not ready to be imported.'); return false; } return true; } }