99use Symfony \Component \Console \Output \OutputInterface ;
1010use tracky \dataprovider \Helper ;
1111use tracky \ImageFetcher ;
12+ use tracky \model \MovieSet ;
1213use tracky \model \Show ;
14+ use tracky \orm \MovieSetRepository ;
1315use tracky \orm \ShowRepository ;
1416
15- #[AsCommand(name: "update-data " , description: "Fetch new episodes and seasons for all shows needing an update " )]
17+ #[AsCommand(name: "update-data " , description: "Fetch updates of shows and movie sets needing an update " )]
1618class UpdateDataCommand extends Command
1719{
1820 public function __construct (
1921 private readonly Helper $ dataProviderHelper ,
2022 private readonly ShowRepository $ showRepository ,
23+ private readonly MovieSetRepository $ movieSetRepository ,
2124 private readonly ImageFetcher $ imageFetcher ,
2225 private readonly EntityManagerInterface $ entityManager ,
2326 private readonly int $ showFetchInterval ,
27+ private readonly int $ movieSetFetchInterval ,
2428 private readonly bool $ downloadAllImages
2529 )
2630 {
@@ -29,7 +33,7 @@ public function __construct(
2933
3034 protected function configure (): void
3135 {
32- $ this ->addOption ("force " , "f " , InputOption::VALUE_NONE , "Update all shows even if they don't need an update " );
36+ $ this ->addOption ("force " , "f " , InputOption::VALUE_NONE , "Update all shows and movie sets even if they don't need an update " );
3337 }
3438
3539 public function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -55,6 +59,27 @@ public function execute(InputInterface $input, OutputInterface $output): int
5559 }
5660 }
5761
62+ /**
63+ * @var MovieSet
64+ */
65+ foreach ($ this ->movieSetRepository ->findAll () as $ movieSet ) {
66+ if (!$ input ->getOption ("force " ) and !$ movieSet ->needsUpdate ($ this ->movieSetFetchInterval )) {
67+ continue ;
68+ }
69+
70+ $ output ->writeln (sprintf ("Fetching data for movie set: %s " , $ movieSet ->getTitle ()));
71+
72+ $ dataProvider = $ this ->dataProviderHelper ->getProviderByEntry ($ movieSet );
73+ $ dataProvider ->fetchMovieSet ($ movieSet );
74+
75+ $ this ->entityManager ->persist ($ movieSet );
76+ $ this ->entityManager ->flush ();
77+
78+ if ($ this ->downloadAllImages ) {
79+ $ movieSet ->fetchPosterImages ($ this ->imageFetcher , true );
80+ }
81+ }
82+
5883 return self ::SUCCESS ;
5984 }
6085}
0 commit comments