mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
Move source files directly under src/ directory
This commit is contained in:
parent
804261bc26
commit
a37b385c23
190 changed files with 19 additions and 21 deletions
72
src/Command/ListUserCommand.php
Normal file
72
src/Command/ListUserCommand.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Wallabag\CoreBundle\Repository\UserRepository;
|
||||
|
||||
class ListUserCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'wallabag:user:list';
|
||||
protected static $defaultDescription = 'List all users';
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setHelp('This command list all existing users')
|
||||
->addArgument('search', InputArgument::OPTIONAL, 'Filter list by given search term')
|
||||
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max number of displayed users', 100)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$users = $this->userRepository
|
||||
->getQueryBuilderForSearch($input->getArgument('search'))
|
||||
->setMaxResults($input->getOption('limit'))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$nbUsers = $this->userRepository
|
||||
->getSumUsers();
|
||||
|
||||
$rows = [];
|
||||
foreach ($users as $user) {
|
||||
$rows[] = [
|
||||
$user->getUsername(),
|
||||
$user->getEmail(),
|
||||
$user->isEnabled() ? 'yes' : 'no',
|
||||
$user->hasRole('ROLE_SUPER_ADMIN') || $user->hasRole('ROLE_ADMIN') ? 'yes' : 'no',
|
||||
];
|
||||
}
|
||||
|
||||
$io->table(['username', 'email', 'is enabled?', 'is admin?'], $rows);
|
||||
|
||||
$io->success(
|
||||
sprintf(
|
||||
'%s/%s%s user(s) displayed.',
|
||||
\count($users),
|
||||
$nbUsers,
|
||||
null === $input->getArgument('search') ? '' : ' (filtered)'
|
||||
)
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue