public function preImportStep(PreImportEvent $event)
 {
     $this->finish();
     if ($this->stopWatch) {
         $this->stopWatch->start('geonamesImportStep');
     }
     $name = $this->getBuilderName($event->getBuilder());
     $this->output->writeln("<info>Import {$name}</info>");
 }
示例#2
0
 private function importStep(ImportStepBuilder $builder, &$totSynced, &$totSkipped, &$totErrors)
 {
     if ($this->dispatcher) {
         $event = new PreImportEvent();
         $event->setBuilder($builder);
         $this->dispatcher->dispatch(GeonamesImportEvents::PRE_IMPORT_STEP, $event);
     }
     $synced = $skipped = $errors = 0;
     $reader = $builder->buildReader();
     $reader->open();
     $totalSize = $reader->count();
     foreach ($reader as $size => $value) {
         try {
             $this->emptyToNull($value);
             $entity = $builder->buildEntity($value);
             $this->om->persist($entity);
             ++$synced;
         } catch (SkipImportException $e) {
             ++$skipped;
             if ($this->dispatcher) {
                 $ev = new ImportErrorEvent($builder->getClass(), $value, $e);
                 $this->dispatcher->dispatch(GeonamesImportEvents::ON_SKIP, $ev);
             }
         } catch (FailedImportException $e) {
             ++$errors;
             if ($this->dispatcher) {
                 $ev = new ImportErrorEvent($builder->getClass(), $value, $e);
                 $this->dispatcher->dispatch(GeonamesImportEvents::ON_ERROR, $ev);
             }
         }
         if ($this->dispatcher) {
             $this->dispatcher->dispatch(GeonamesImportEvents::ON_IMPORT_STEP_PROGRESS, new OnProgressEvent($totalSize, $size + 1));
         }
     }
     $reader->close();
     $this->om->flush();
     if ($this->dispatcher) {
         $this->dispatcher->dispatch(GeonamesImportEvents::POST_IMPORT_STEP, new PostImportEvent($synced, $skipped, $errors));
     }
     $totSynced += $synced;
     $totSkipped += $skipped;
     $totErrors += $errors;
 }