/**
  * Check if the session contains ids.
  * If the session has no ids, then the db adapter must be used to retrieve them.
  * Then writes these ids to the session and sets the session state to "active".
  * For now we will write the ids as a serialized array.
  *
  * @param Profile $profile
  * @param array $data
  * @throws \Exception
  */
 public function start(Profile $profile, array $data)
 {
     $sessionEntity = $this->getEntity();
     if (isset($data['totalCountedIds']) && $data['totalCountedIds'] > 0) {
         //set count
         $sessionEntity->setTotalCount($data['totalCountedIds']);
     }
     //set ids
     $sessionEntity->setIds($data['serializedIds']);
     //set type
     $sessionEntity->setType($data['type']);
     //set position
     $sessionEntity->setPosition(0);
     $dateTime = new \DateTime('now');
     //set date/time
     $sessionEntity->setCreatedAt($dateTime);
     if (!isset($data['fileName'])) {
         throw new \Exception('Invalid file name.');
     }
     /** @var UploadPathProvider $uploadPathProvider */
     $uploadPathProvider = Shopware()->Container()->get('swag_import_export.upload_path_provider');
     //set fileName
     $sessionEntity->setFileName($uploadPathProvider->getFileNameFromPath($data['fileName']));
     if (isset($data['fileSize'])) {
         $sessionEntity->setFileSize($data['fileSize']);
     }
     if (!isset($data['format'])) {
         throw new \Exception('Invalid format.');
     }
     //set username
     $sessionEntity->setUserName($data['username']);
     //set format
     $sessionEntity->setFormat($data['format']);
     //change state
     $sessionEntity->setState('active');
     //set profile
     $sessionEntity->setProfile($profile->getEntity());
     $this->getManager()->persist($sessionEntity);
     $this->getManager()->flush();
     $this->sessionId = $sessionEntity->getId();
 }
 /**
  * Returns the profile tree.
  *
  * @return array
  */
 private function getProfileTree()
 {
     return json_decode($this->profile->getEntity()->getTree(), true);
 }