PromoteUserCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the FOSUserBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\UserBundle\Command;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. use FOS\UserBundle\Util\UserManipulator;
  13. /**
  14. * @author Matthieu Bontemps <matthieu@knplabs.com>
  15. * @author Thibault Duplessis <thibault.duplessis@gmail.com>
  16. * @author Luis Cordova <cordoval@gmail.com>
  17. * @author Lenar Lõhmus <lenar@city.ee>
  18. */
  19. class PromoteUserCommand extends RoleCommand
  20. {
  21. /**
  22. * @see Command
  23. */
  24. protected function configure()
  25. {
  26. parent::configure();
  27. $this
  28. ->setName('fos:user:promote')
  29. ->setDescription('Promotes a user by adding a role')
  30. ->setHelp(<<<EOT
  31. The <info>fos:user:promote</info> command promotes a user by adding a role
  32. <info>php app/console fos:user:promote matthieu ROLE_CUSTOM</info>
  33. <info>php app/console fos:user:promote --super matthieu</info>
  34. EOT
  35. );
  36. }
  37. protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role)
  38. {
  39. if ($super) {
  40. $manipulator->promote($username);
  41. $output->writeln(sprintf('User "%s" has been promoted as a super administrator.', $username));
  42. } else {
  43. if ($manipulator->addRole($username, $role)) {
  44. $output->writeln(sprintf('Role "%s" has been added to user "%s".', $role, $username));
  45. } else {
  46. $output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role));
  47. }
  48. }
  49. }
  50. }