|
@@ -0,0 +1,55 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Command;
|
|
|
+
|
|
|
+use App\Repository\CommentaireRepository;
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
+
|
|
|
+#[AsCommand(
|
|
|
+ name: 'app:seen-when-comment',
|
|
|
+ description: 'Passer les films en vu lorsque commenté par le user',
|
|
|
+)]
|
|
|
+class SeenWhenCommentCommand extends Command
|
|
|
+{
|
|
|
+ public function __construct(
|
|
|
+ protected EntityManagerInterface $em,
|
|
|
+ protected CommentaireRepository $commentaireRepository
|
|
|
+ )
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function configure(): void
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Juste tester dans enregistrer')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
+ {
|
|
|
+ $io = new SymfonyStyle($input, $output);
|
|
|
+
|
|
|
+ $commentaires = $this->commentaireRepository->findAll();
|
|
|
+ foreach($commentaires as $commentaire) {
|
|
|
+ if (!$commentaire->getFilm()->getUsersWhoSeen()->contains($commentaire->getUser())) {
|
|
|
+ $commentaire->getFilm()->addUserWhoSeen($commentaire->getUser());
|
|
|
+ $io->text(sprintf("Film : %s --- User : %s", $commentaire->getFilm()->getTitre(), $commentaire->getUser()->getUserIdentifier()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$input->getOption('dry-run')) {
|
|
|
+ $this->em->flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ $io->success('Les films commentés par un utilisateur sont maintenant passs en "vu"');
|
|
|
+
|
|
|
+ return Command::SUCCESS;
|
|
|
+ }
|
|
|
+}
|