Browse Source

Merge branch 'develop' into features/background

François Drouhard 2 years ago
parent
commit
960b9005b3

+ 6 - 17
src/Command/AppUserCreateCommand.php

@@ -36,23 +36,12 @@ class AppUserCreateCommand extends Command
     {
         $io = new SymfonyStyle($input, $output);
 
-        $helper = $this->getHelper('question');
-        $questionUsername = new Question('Nom (username) de l\'utilisateur : ', 'admin_user');
-        $questionPrenom = new Question('Prénom de l\'utilisateur : ');
-        $questionNom = new Question('Nom de l\'utilisateur : ');
-        $questionPassword = new Question('Mot de passe :', 'MotDePasse');
-        $questionPassword->setHidden(true);
-        $questionPassword->setHiddenFallback(false);
-        $questionMail = new Question('Email :', 'bidule@truc.chose');
-        $questionRole = new ChoiceQuestion('Roles :', array('ROLE_SUPER_ADMIN', 'ROLE_ADMIN', 'ROLE_USER', 'ROLE_MODERATEUR'), '0');
-        $questionRole->setMultiselect(true);
-
-        $username = $helper->ask($input, $output, $questionUsername);
-        $prenom = $helper->ask($input, $output, $questionPrenom);
-        $nom = $helper->ask($input, $output, $questionNom);
-        $mail = $helper->ask($input, $output, $questionMail);
-        $password = $helper->ask($input, $output, $questionPassword);
-        $roles = $helper->ask($input, $output, $questionRole);
+        $username = $io->askQuestion(new Question('Nom (username) de l\'utilisateur '));
+        $prenom = $io->askQuestion(new Question('Prénom de l\'utilisateur '));
+        $nom = $io->askQuestion(new Question('Nom de l\'utilisateur '));
+        $mail = $io->askQuestion(new Question('Email ', 'bidule@truc.chose'));
+        $password = $io->askHidden("Mot de passe");
+        $roles = $io->askQuestion((new ChoiceQuestion('Roles ', array('ROLE_SUPER_ADMIN', 'ROLE_ADMIN', 'ROLE_USER', 'ROLE_MODERATEUR'), '0'))->setMultiselect(true));
 
         $this->userManager->createUser(
             "$username",

+ 6 - 7
src/Command/AppUsersActivateCommand.php

@@ -2,6 +2,7 @@
 
 namespace App\Command;
 
+use App\Repository\UserRepository;
 use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
@@ -11,11 +12,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
 
 class AppUsersActivateCommand extends Command
 {
-    private $em;
-
-    public function __construct(EntityManagerInterface $em)
+    public function __construct(private UserRepository $repoUser, private EntityManagerInterface $em)
     {
-        $this->em = $em;
         parent::__construct();
     }
 
@@ -30,13 +28,14 @@ class AppUsersActivateCommand extends Command
     protected function execute(InputInterface $input, OutputInterface $output) :int
     {
         $io = new SymfonyStyle($input, $output);
-        $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Activer tous les utilisateurs ?', false);
-        if (!$helper->ask($input, $output, $question))
+        
+        if (! $io->askQuestion($question))
         {
+            $io->warning("Pas d'activation des users.");
             return COMMAND::INVALID;
         }
-        $users = $this->em->getRepository('App:User')->findAll();
+        $users = $this->repoUser->findAll();
         foreach ($users as $user)
         {
             $user->setActivated(true);

+ 3 - 7
src/Command/UpdateCommentairesCommand.php

@@ -2,8 +2,8 @@
 
 namespace App\Command;
 
+use App\Repository\FilmRepository;
 use App\Service\NoteMoyenne;
-use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -11,13 +11,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
 
 class UpdateCommentairesCommand extends Command
 {
-    private $em;
-    private $notesAndComs;
 
-    public function __construct(EntityManagerInterface $em, NoteMoyenne $notesAndComs)
+    public function __construct(private NoteMoyenne $notesAndComs, private FilmRepository $repoFilm)
     {
-        $this->em = $em;
-        $this->notesAndComs = $notesAndComs;
         parent::__construct();
     }
 
@@ -32,7 +28,7 @@ class UpdateCommentairesCommand extends Command
     protected function execute(InputInterface $input, OutputInterface $output) :int
     {
         $io = new SymfonyStyle($input, $output);
-        $films = $this->em->getRepository('App:Film')->findAll();
+        $films = $this->repoFilm->findAll();
         foreach ($films as $film)
         {
             $this->notesAndComs->calculerMoyenne($film);

+ 4 - 18
src/Command/UpdateOptionsCommand.php

@@ -5,23 +5,16 @@ namespace App\Command;
 use App\Entity\Profile;
 use App\Repository\UserRepository;
 use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
 
 class UpdateOptionsCommand extends Command
-{
-    protected $em;
-    protected $repoUser;
-    
-    public function __construct(EntityManagerInterface $em, UserRepository $repoUser)
+{    
+    public function __construct(private EntityManagerInterface $em, private UserRepository $repoUser)
     {
-        $this->em = $em;
-        $this->repoUser = $repoUser;
         parent::__construct();
     }
 
@@ -30,7 +23,6 @@ class UpdateOptionsCommand extends Command
         $this
             ->setName('app:update:options')
             ->setDescription('Commande pour rattacher une entité Profile aux users existants')
-            //->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
             ->addOption('force', null, InputOption::VALUE_NONE, 'Forcer la création des profils utilisateur')
         ;
     }
@@ -38,11 +30,6 @@ class UpdateOptionsCommand extends Command
     protected function execute(InputInterface $input, OutputInterface $output): int
     {
         $io = new SymfonyStyle($input, $output);
-        /*$arg1 = $input->getArgument('arg1');
-
-        if ($arg1) {
-            $io->note(sprintf('You passed an argument: %s', $arg1));
-        }*/
 
         if ($input->getOption('force')) {
             $users = $this->repoUser->findAll();
@@ -50,13 +37,12 @@ class UpdateOptionsCommand extends Command
                 if ($user->getProfile() === null)
                 {
                     $io->note(sprintf('%s : pas de profil', $user->getNomComplet()));
-                    $profil = new Profile;
+                    $profil = new Profile();
                     $profil->setUser($user);
                     $this->em->persist($profil);
-                    $this->em->flush();
                 }
             }
-
+            $this->em->flush();
 
             $io->success(sprintf('La bdd a été modifiée.'));
             return Command::SUCCESS;