FOS\UserBundle\Command\PromoteSuperAdminCommand::execute PHP Method

execute() protected method

See also: Command
protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->container->get('security.context')->setToken(new UsernamePasswordToken('command.line', null, array(User::ROLE_SUPERADMIN)));
        $userManager = $this->container->get('fos_user.user_manager');
        $user = $userManager->findUserByUsername($input->getArgument('username'));
        if (!$user) {
            throw new \InvalidArgumentException(sprintf('The user "%s" does not exist', $input->getArgument('username')));
        }
        $user->setSuperAdmin(true);
        $userManager->updateUser($user);
        $output->writeln(sprintf('User "%s" has been promoted as a super administrator.', $user->getUsername()));
    }
PromoteSuperAdminCommand