Browse Source

Factorisarion commande optionsUpdate

François Drouhard 2 years ago
parent
commit
0c17957b44
1 changed files with 4 additions and 18 deletions
  1. 4 18
      src/Command/UpdateOptionsCommand.php

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