/**
  * @throws \RuntimeException When the part has not started yet
  */
 protected function finish()
 {
     $this->logger->debug(sprintf('Finishing part %d on position %d for import %d', $this->part->getId(), $this->part->getPosition(), $this->part->getImport()->getId()));
     $this->repository->finishImportPart($this->part);
     $this->importer->dispatchEvent(ImportEvents::PART_FINISH, new ImporterEvent($this->part, $this->importer));
     // if this is the last part, end the import also
     $import = $this->part->getImport();
     if (!$this->repository->importHasUnfinishedParts($import)) {
         $this->repository->finishImport($import);
         $this->importer->dispatchEvent(ImportEvents::IMPORT_FINISH, new ImportEvent($import));
     }
 }