/**
  * @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;
 }
 /**
  * @param Import    $import
  * @param array     $transport
  * @param \DateTime $scheduleDate
  * @param int       $position
  *
  * @return ImportPart
  */
 public function createPart(Import $import, array $transport, \DateTime $scheduleDate = null, $position = null)
 {
     if (is_null($scheduleDate)) {
         $scheduleDate = new \DateTime();
     }
     if (is_null($position)) {
         $position = 0;
         /** @var ImportPart $part */
         foreach ($import->getParts() as $part) {
             if ($part->getPosition() > $position) {
                 $position = $part->getPosition();
             }
         }
         ++$position;
     }
     $part = new ImportPart();
     $part->setPosition($position);
     $part->setTransportConfig($transport);
     $part->setDatetimeScheduled($scheduleDate);
     $part->setImport($import);
     $import->addPart($part);
     $this->getEntityManager()->persist($part);
     $this->getEntityManager()->flush($part);
     return $part;
 }