|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the FOSUserBundle package. |
|
5 * |
|
6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace FOS\UserBundle\Command; |
|
13 |
|
14 use Symfony\Component\Console\Output\OutputInterface; |
|
15 use FOS\UserBundle\Util\UserManipulator; |
|
16 |
|
17 /** |
|
18 * @author Antoine Hérault <antoine.herault@gmail.com> |
|
19 * @author Lenar Lõhmus <lenar@city.ee> |
|
20 */ |
|
21 class DemoteUserCommand extends RoleCommand |
|
22 { |
|
23 /** |
|
24 * @see Command |
|
25 */ |
|
26 protected function configure() |
|
27 { |
|
28 parent::configure(); |
|
29 |
|
30 $this |
|
31 ->setName('fos:user:demote') |
|
32 ->setDescription('Demote a user by removing a role') |
|
33 ->setHelp(<<<EOT |
|
34 The <info>fos:user:demote</info> command demotes a user by removing a role |
|
35 |
|
36 <info>php app/console fos:user:demote matthieu ROLE_CUSTOM</info> |
|
37 <info>php app/console fos:user:demote --super matthieu</info> |
|
38 EOT |
|
39 ); |
|
40 } |
|
41 |
|
42 protected function executeRoleCommand(UserManipulator $manipulator, OutputInterface $output, $username, $super, $role) |
|
43 { |
|
44 if ($super) { |
|
45 $manipulator->demote($username); |
|
46 $output->writeln(sprintf('User "%s" has been demoted as a simple user.', $username)); |
|
47 } else { |
|
48 if ($manipulator->removeRole($username, $role)) { |
|
49 $output->writeln(sprintf('Role "%s" has been removed from user "%s".', $role, $username)); |
|
50 } else { |
|
51 $output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role)); |
|
52 } |
|
53 } |
|
54 } |
|
55 } |