partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

ProtectUserCommand.php (1367B)


      1 <?php
      2 
      3 namespace PartKeepr\AuthBundle\Command;
      4 
      5 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
      6 use Symfony\Component\Console\Input\InputArgument;
      7 use Symfony\Component\Console\Input\InputInterface;
      8 use Symfony\Component\Console\Output\OutputInterface;
      9 
     10 class ProtectUserCommand extends ContainerAwareCommand
     11 {
     12     public function configure()
     13     {
     14         parent::configure();
     15         $this->setName('partkeepr:user:protect');
     16         $this->setDescription('Protects a given user against changes');
     17         $this->addArgument('username', InputArgument::REQUIRED, 'The username to protect against changes');
     18     }
     19 
     20     public function execute(InputInterface $input, OutputInterface $output)
     21     {
     22         $userService = $this->getContainer()->get('partkeepr.userservice');
     23 
     24         $fosUser = $this->getContainer()->get('fos_user.user_manager')->findUserByUsername(
     25             $input->getArgument('username')
     26         );
     27 
     28         if ($fosUser === null) {
     29             $output->writeln(sprintf('User %s not found', $input->getArgument('username')));
     30         } else {
     31             $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true);
     32             $userService->protect($user);
     33             $output->writeln(sprintf('User %s protected against changes', $input->getArgument('username')));
     34         }
     35     }
     36 }