Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $jobKey = $this->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
  */
 public function start(ImportJob $job)
 {
     set_time_limit(0);
     if ($job->status == 'settings_complete') {
         ImportProcedure::runImport($job);
     }
 }