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::runImport($job); /** * @var int $index * @var TransactionJournal $journal */ foreach ($result as $index => $journal) { if (!is_null($journal->id)) { $this->line(sprintf('Line #%d has been imported as transaction #%d.', $index, $journal->id)); continue; } $this->error(sprintf('Could not store line #%d', $index)); } $this->line('The import has completed.'); // get any errors from the importer: $extendedStatus = $job->extended_status; if (isset($extendedStatus['errors']) && count($extendedStatus['errors']) > 0) { $this->line(sprintf('The following %d error(s) occured during the import:', count($extendedStatus['errors']))); foreach ($extendedStatus['errors'] as $error) { $this->error($error); } } return; } /** * @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; } }