Browse Source

Ajout d'une commande pour activer tous les utilisateurs

François 6 years ago
parent
commit
90fa93f96f
1 changed files with 48 additions and 0 deletions
  1. 48 0
      src/AppBundle/Command/AppUsersActivateCommand.php

+ 48 - 0
src/AppBundle/Command/AppUsersActivateCommand.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace AppBundle\Command;
+
+use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\ConfirmationQuestion;
+
+class AppUsersActivateCommand extends ContainerAwareCommand
+{
+    private $em;
+
+    public function __construct(EntityManagerInterface $em)
+    {
+        $this->em = $em;
+        parent::__construct();
+    }
+
+    protected function configure()
+    {
+        $this
+            ->setName('app:users:activate')
+            ->setDescription('Activer tous les users')
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $helper = $this->getHelper('question');
+        $question = new ConfirmationQuestion('Activer tous les utilisateurs ?', false);
+        if (!$helper->ask($input, $output, $question))
+        {
+            return;
+        }
+        $users = $this->em->getRepository('AppBundle:User')->findAll();
+        foreach ($users as $user)
+        {
+            $user->setActivated(true);
+        }
+        $this->em->flush();
+
+        $output->writeln('Les utilisateurs sont activés');
+    }
+
+}