/** * @param AlbumModel $albumModel * @param string $terms * @param array $tracks * * @return array */ protected function saveTrackList(AlbumModel $albumModel, $terms = '', $tracks = array()) { $trackList = array(); if ($albumModel->getId()) { foreach ($tracks as $position => $title) { if ("titre inconnu" == trim(strtolower($title))) { $this->logger->info(sprintf('IGNORING %s - %s TRACK INFOS while processsing %s (album #%s) track list', $terms, $title, $albumModel->getId())); continue; } try { $this->logger->info(sprintf('Trying to SAVE %s - %s TRACK INFOS using the TrackRetriever', $terms, $title)); $trackModel = new Track(); $trackModel->fromAlbum($albumModel, $title, $position + 1); // position is an index's an index $this->entityManager->persist($trackModel); $this->entityManager->flush(); $trackList[] = $trackModel; } catch (InvalidAlbumInputException $e) { $this->logger->error(sprintf('An error occurred : %s', $e)); } } } return $trackList; }