]>
Commit | Line | Data |
---|---|---|
af31cfed NH |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Command; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
f7a4b441 | 6 | use Symfony\Component\Console\Input\InputArgument; |
af31cfed | 7 | use Symfony\Component\Console\Input\InputInterface; |
f7a4b441 | 8 | use Symfony\Component\Console\Input\InputOption; |
af31cfed NH |
9 | use Symfony\Component\Console\Output\OutputInterface; |
10 | use Symfony\Component\Console\Style\SymfonyStyle; | |
11 | ||
12 | class ListUserCommand extends ContainerAwareCommand | |
13 | { | |
14 | protected function configure() | |
15 | { | |
16 | $this | |
17 | ->setName('wallabag:user:list') | |
18 | ->setDescription('List all users') | |
19 | ->setHelp('This command list all existing users') | |
f7a4b441 NH |
20 | ->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term') |
21 | ->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100) | |
af31cfed NH |
22 | ; |
23 | } | |
24 | ||
25 | protected function execute(InputInterface $input, OutputInterface $output) | |
26 | { | |
27 | $io = new SymfonyStyle($input, $output); | |
28 | ||
f7a4b441 NH |
29 | $users = $this->getContainer()->get('wallabag_user.user_repository') |
30 | ->getQueryBuilderForSearch($input->getArgument('search')) | |
31 | ->setMaxResults($input->getOption('limit')) | |
32 | ->getQuery() | |
33 | ->getResult(); | |
34 | ||
35 | $nbUsers = $this->getContainer()->get('wallabag_user.user_repository') | |
36 | ->getSumUsers(); | |
af31cfed NH |
37 | |
38 | $rows = []; | |
39 | foreach ($users as $user) { | |
40 | $rows[] = [ | |
41 | $user->getUsername(), | |
42 | $user->getEmail(), | |
43 | $user->isEnabled() ? 'yes' : 'no', | |
44 | $user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_ADMIN') ? 'yes' : 'no', | |
45 | ]; | |
46 | } | |
47 | ||
48 | $io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows); | |
49 | ||
f7a4b441 NH |
50 | $io->success( |
51 | sprintf( | |
52 | '%s/%s%s user(s) displayed.', | |
2a1ceb67 | 53 | \count($users), |
f7a4b441 | 54 | $nbUsers, |
3ef055ce | 55 | null === $input->getArgument('search') ? '' : ' (filtered)' |
f7a4b441 NH |
56 | ) |
57 | ); | |
af31cfed NH |
58 | |
59 | return 0; | |
60 | } | |
61 | } |