Ver Fonte

Factorisarion commande activate

François Drouhard há 2 anos atrás
pai
commit
beefc94a76
1 ficheiros alterados com 6 adições e 7 exclusões
  1. 6 7
      src/Command/AppUsersActivateCommand.php

+ 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);