ltbxdGateway->parseFile(); } catch (GatewayException $e) { $output->writeln('/!\ '.$e->getMessage()); return Command::FAILURE; } $i = 0; foreach ($ltbxdMovies as $ltbxdMovie) { // If the movie already exists, skip if (0 < $this->em->getRepository(Movie::class)->count(['ltbxdRef' => $ltbxdMovie->getLtbxdRef()])) { continue; } // Search movie on TMDB try { $film = $this->TMDBGateway->searchMovie($ltbxdMovie->getName()); } catch (GatewayException $e) { $output->writeln('/!\ '.$e->getMessage()); return Command::FAILURE; } if ($film) { $output->writeln('* Found '.$ltbxdMovie->getName()); $filmEntity = new Movie() ->setLtbxdRef($ltbxdMovie->getLtbxdRef()) ->setTitle($ltbxdMovie->getName()) ->setTmdbId($film->getId()) ; $this->em->persist($filmEntity); } ++$i; if (0 === $i % 50) { $this->em->flush(); } } $this->em->flush(); $output->writeln('Films synced'); return Command::SUCCESS; } }