Esempio n. 1
0
 /**
  * @param $album
  * @param $images
  * @param $terms
  *
  * @return AlbumModel
  * @throws InvalidAlbumInputException
  */
 protected function saveAlbum($album, $images, $terms)
 {
     if (empty($terms)) {
         throw new InvalidAlbumInputException(sprintf("terms are null in %s", __METHOD__));
     } elseif (empty($album)) {
         throw new InvalidAlbumInputException(sprintf("album is null for '%s' terms in %s", $terms, __METHOD__));
     } elseif (empty($images)) {
         throw new InvalidAlbumInputException(sprintf("images list is null for '%s' terms in %s", $terms, __METHOD__));
     }
     $albumModel = new AlbumModel();
     try {
         $this->logger->info(sprintf('Trying to SAVE %s ALBUM INFOS using the TrackRetriever', $terms));
         $albumModel->fromXml($album);
         //$albumModel->setImagesfromXml($images);
         $albumModel->setPublished(true);
         $this->saveAlbumImages($albumModel, $images);
         $exists = $this->albumExistsYet($albumModel);
         if ('RadioSolution\\ProgramBundle\\Entity\\Album' === get_class($exists)) {
             $this->logger->info(sprintf('Album #%d "%s" already existing found for given "%s" terms', $exists->getId(), $exists->getTitle(), $terms));
             return array(self::ALREADY_EXISTS, $exists);
         }
         $this->entityManager->persist($albumModel);
         $this->entityManager->flush();
     } catch (InvalidAlbumInputException $e) {
         $this->logger->error(sprintf('An error occurred : %s', $e));
         return array(self::SOMETHING_TERRIBLE_HAPPENED, null);
     }
     return array(self::NEWLY_SAVED, $albumModel);
 }