/**
  * @param Import    $import
  * @param array     $transport
  * @param \DateTime $scheduleDate
  * @param int       $position
  *
  * @return ImportPart
  */
 protected function createImportPart(Import $import, array $transport, \DateTime $scheduleDate = null, $position = null)
 {
     if (is_null($scheduleDate)) {
         $scheduleDate = new \DateTime();
     }
     if (is_null($position)) {
         $positions = $import->getParts()->map(function (ImportPart $part) {
             return $part->getPosition();
         })->toArray();
         // add this to ensure we have at least 1 position
         $positions[] = 0;
         $position = max($positions) + 1;
     }
     $part = new ImportPart();
     $part->setPosition($position);
     $part->setTransportConfig($transport);
     $part->setDatetimeScheduled($scheduleDate);
     $part->setImport($import);
     $import->addPart($part);
     $this->getRepository()->savePart($part);
     return $part;
 }
 /**
  * Checks if the import has any parts that are unfinished.
  *
  * @param Import $import  The import
  * @param bool   $refresh Whether to refresh the checked parts first. This
  *                        is useful when time has passed since the import
  *                        start, and you want to avoid race conditions
  *
  * @return bool
  */
 public function importHasUnfinishedParts(Import $import, $refresh = true)
 {
     foreach ($import->getParts() as $part) {
         if ($refresh === true) {
             $this->getEntityManager()->refresh($part);
         }
         if (!$part->isFinished()) {
             return true;
         }
     }
     return false;
 }