DemoteUserCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 Antoine Hérault <antoine.herault@gmail.com>
  15. * @author Lenar Lõhmus <lenar@city.ee>
  16. */
  17. class DemoteUserCommand extends RoleCommand
  18. {
  19. /**
  20. * @see Command
  21. */
  22. protected function configure()
  23. {
  24. parent::configure();
  25. $this
  26. ->setName('fos:user:demote')
  27. ->setDescription('Demote a user by removing a role')
  28. ->setHelp(<<<EOT
  29. The <info>fos:user:demote</info> command demotes a user by removing a role
  30. <info>php app/console fos:user:demote matthieu ROLE_CUSTOM</info>
  31. <info>php app/console fos:user:demote --super matthieu</info>
  32. EOT
  33. );
  34. }
  35. protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role)
  36. {
  37. if ($super) {
  38. $manipulator->demote($username);
  39. $output->writeln(sprintf('User "%s" has been demoted as a simple user.', $username));
  40. } else {
  41. if ($manipulator->removeRole($username, $role)) {
  42. $output->writeln(sprintf('Role "%s" has been removed from user "%s".', $role, $username));
  43. } else {
  44. $output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
  45. }
  46. }
  47. }
  48. }