| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Kunstmaan\AdminBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Doctrine\ORM\EntityManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use FOS\UserBundle\Model\GroupManager as FOSGroupManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use FOS\UserBundle\Model\UserManager as FOSUserManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Kunstmaan\AdminBundle\Entity\Group; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Kunstmaan\AdminBundle\Service\GroupManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Kunstmaan\AdminBundle\Service\UserManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Console\Exception\InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Question\ChoiceQuestion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Question\Question; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Symfony CLI command to create a user using bin/console kuma:user:create <username_of_the_user> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @final since 5.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class CreateUserCommand extends ContainerAwareCommand | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected static $defaultName = 'kuma:user:create'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** @var array */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $groups = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** @var EntityManagerInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     private $em; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** @var GroupManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private $groupManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** @var UserManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     private $defaultLocale; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     public function __construct(/* EntityManagerInterface */ $em = null, /* GroupManager */ $groupManager = null, /* UserManager */ $userManager, $defaultLocale = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         parent::__construct(); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         if (!$em instanceof EntityManagerInterface) { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |             $this->setName(null === $em ? 'kuma:user:create' : $em); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             return; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         if (!$groupManager instanceof GroupManager && !$groupManager instanceof FOSGroupManager) { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             throw new \InvalidArgumentException(sprintf('The "$groupManager" argument must be of type "%s" or type "%s"', GroupManager::class, FOSGroupManager::class)); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         if ($groupManager instanceof FOSGroupManager) { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             // NEXT_MAJOR set the groupmanager typehint to the kunstmaan groupmanager. | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             @trigger_error(sprintf('Passing the groupmanager from FOSUserBundle as the first argument of "%s" is deprecated since KunstmaanAdminBundle 5.8 and will be removed in KunstmaanAdminBundle 6.0. Use the "%s" class instead.', __METHOD__, GroupManager::class), E_USER_DEPRECATED); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         if (!$userManager instanceof UserManager && !$userManager instanceof FOSUserManager) { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             throw new \InvalidArgumentException(sprintf('The "$userManager" argument must be of type "%s" or type "%s"', UserManager::class, FOSUserManager::class)); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         if ($userManager instanceof FOSUserManager) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             // NEXT_MAJOR set the usermanager typehint to the kunstmaan usermanager. | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             @trigger_error(sprintf('Passing the usermanager from FOSUserBundle as the first argument of "%s" is deprecated since KunstmaanAdminBundle 5.8 and will be removed in KunstmaanAdminBundle 6.0. Use the "%s" class instead.', __METHOD__, UserManager::class), E_USER_DEPRECATED); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         $this->em = $em; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $this->groupManager = $groupManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         $this->userManager = $userManager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         $this->defaultLocale = $defaultLocale; | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         parent::configure(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->setDescription('Create a user.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ->setDefinition([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 new InputArgument('username', InputArgument::REQUIRED, 'The username'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 new InputArgument('email', InputArgument::REQUIRED, 'The email'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 new InputArgument('password', InputArgument::REQUIRED, 'The password'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 new InputArgument('locale', InputArgument::OPTIONAL, 'The locale (language)'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 new InputOption('group', null, InputOption::VALUE_REQUIRED, 'The group(s) the user should belong to'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 new InputOption('super-admin', null, InputOption::VALUE_NONE, 'Set the user as super admin'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 new InputOption('inactive', null, InputOption::VALUE_NONE, 'Set the user as inactive'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ->setHelp(<<<'EOT' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | The <info>kuma:user:create</info> command creates a user: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |   <info>php bin/console kuma:user:create matthieu --group=Users</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | This interactive shell will ask you for an email and then a password. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | You can alternatively specify the email, password and locale and group as extra arguments: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |   <info>php bin/console kuma:user:create matthieu [email protected] mypassword en --group=Users</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | You can create a super admin via the super-admin flag: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |   <info>php bin/console kuma:user:create admin --super-admin --group=Administrators</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | You can create an inactive user (will not be able to log in): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |   <info>php bin/console kuma:user:create thibault --inactive --group=Users</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | <comment>Note:</comment> You have to specify at least one group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | EOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     protected function initialize(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $this->groups = $this->getGroups(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     private function getGroups() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $groups = $this->groupManager->findGroups(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         // reindexing the array, using the db id as the key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $newGroups = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         foreach ($groups as $group) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             $newGroups[$group->getId()] = $group; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         return $newGroups; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * Executes the current command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param InputInterface  $input  The input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @param OutputInterface $output The output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         if (null === $this->em) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             $this->groupManager = $this->getContainer()->get('kunstmaan_admin.group_manager'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             $this->userManager = $this->getContainer()->get('kunstmaan_admin.user_manager'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             $this->defaultLocale = $this->getContainer()->getParameter('kunstmaan_admin.default_admin_locale'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $username = $input->getArgument('username'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $email = $input->getArgument('email'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $password = $input->getArgument('password'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $locale = $input->getArgument('locale'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $superAdmin = $input->getOption('super-admin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         $inactive = $input->getOption('inactive'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $groupOption = $input->getOption('group'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         if (null === $locale) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $locale = $this->defaultLocale; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $user = $this->userManager->createUser(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $user->setUsername($username); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $user->setEmail($email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $user->setPlainPassword($password); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $user->setEnabled(!((bool) $inactive)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $user->setSuperAdmin((bool) $superAdmin); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         $user->setCreatedBy('kuma:user:create command'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $this->userManager->updateUser($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $output->writeln(sprintf('Created user <comment>%s</comment>', $username)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         // Attach groups | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         $groupOutput = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         foreach (explode(',', $groupOption) as $groupId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             if ((int) $groupId === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                 foreach ($this->groups as $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                     if ($groupId === $value->getName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                         $group = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                         break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |                 $group = $this->groups[$groupId]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             if (isset($group) && $group instanceof Group) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 $groupOutput[] = $group->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |                 $user->getGroups()->add($group); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |                 throw new \RuntimeException('The selected group(s) can\'t be found.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         // Set admin interface locale and enable password changed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $user->setAdminLocale($locale); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         $user->setPasswordChanged(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         // Persist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         $this->userManager->updateUser($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         $output->writeln(sprintf('Added user <comment>%s</comment> to groups <comment>%s</comment>', $input->getArgument('username'), implode(',', $groupOutput))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * Interacts with the user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * @param InputInterface  $input  The input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      * @param OutputInterface $output The output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      * @throws \InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     protected function interact(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |     { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 217 |  | View Code Duplication |         if (!$input->getArgument('username')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             $question = new Question('Please choose a username:'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             $question->setValidator(function ($username) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |                 if (null === $username) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |                     throw new \InvalidArgumentException('Username can not be empty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |                 return $username; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             $username = $this->getHelper('question')->ask( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |                 $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                 $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |                 $question | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |             $input->setArgument('username', $username); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 234 |  | View Code Duplication |         if (!$input->getArgument('email')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             $question = new Question('Please choose an email:'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             $question->setValidator(function ($email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |                 if (null === $email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |                     throw new \InvalidArgumentException('Email can not be empty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 return $email; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |             $email = $this->getHelper('question')->ask( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |                 $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |                 $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |                 $question | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             $input->setArgument('email', $email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         if (!$input->getArgument('password')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |             $question = new Question('Please choose a password:'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |             $question->setHidden(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |             $question->setHiddenFallback(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |             $question->setValidator(function ($password) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |                 if (null === $password) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |                     throw new \InvalidArgumentException('Password can not be empty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                 return $password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |             $password = $this->getHelper('question')->ask( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                 $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                 $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                 $question | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             $input->setArgument('password', $password); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         if (!$input->getArgument('locale')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |             $locale = $this->getHelper('question')->ask( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |                 $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |                 $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |                 new Question('Please enter the locale (or leave empty for default admin locale):') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |             $input->setArgument('locale', $locale); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         if (!$input->getOption('group')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |             $question = new ChoiceQuestion( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |                 'Please enter the group(s) the user should be a member of (multiple possible, separated by comma):', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |                 $this->groups, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |                 '' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |             $question->setMultiselect(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |             $question->setValidator(function ($groupsInput) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |                 if (!$this->groups) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |                     throw new \RuntimeException('No user group(s) could be found'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |                 // Validate that the chosen group options exist in the available groups | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |                 $groupNames = array_unique(explode(',', $groupsInput)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |                 if (\count(array_intersect_key(array_flip($groupNames), $this->groups)) !== \count($groupNames)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |                     throw new InvalidArgumentException('You have chosen non existing group(s)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |                 if ($groupsInput === '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |                     throw new \RuntimeException('Group(s) must be of type integer and can not be empty'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |                 return $groupsInput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |             // Group has to be imploded because $input->setOption expects a string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |             $groups = $this->getHelper('question')->ask($input, $output, $question); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |             $input->setOption('group', $groups); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 311 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 312 |  |  |  | 
            
                        
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.