use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Command\Shared\CreateTrait;
use Drupal\Console\Utils\Create\UserData;
use Drupal\Console\Utils\DrupalApi;
-use Drupal\Console\Core\Style\DrupalStyle;
/**
* Class UsersCommand
class UsersCommand extends Command
{
use CreateTrait;
- use CommandTrait;
/**
* @var DrupalApi
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.create.users.options.time-range')
- );
+ )->setAliases(['cru']);
}
/**
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$rids = $input->getArgument('roles');
if (!$rids) {
$roles = $this->drupalApi->getRoles();
- $rids = $io->choice(
+ $rids = $this->getIo()->choice(
$this->trans('commands.create.users.questions.roles'),
array_values($roles),
null,
$limit = $input->getOption('limit');
if (!$limit) {
- $limit = $io->ask(
+ $limit = $this->getIo()->ask(
$this->trans('commands.create.users.questions.limit'),
10
);
$password = $input->getOption('password');
if (!$password) {
- $password = $io->ask(
+ $password = $this->getIo()->ask(
$this->trans('commands.create.users.questions.password'),
5
);
if (!$timeRange) {
$timeRanges = $this->getTimeRange();
- $timeRange = $io->choice(
+ $timeRange = $this->getIo()->choice(
$this->trans('commands.create.nodes.questions.time-range'),
array_values($timeRanges)
);
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$roles = $input->getArgument('roles');
$limit = $input->getOption('limit')?:25;
$password = $input->getOption('password');
$roles = $this->drupalApi->getRoles();
}
- $users = $this->createUserData->create(
+ $result = $this->createUserData->create(
$roles,
$limit,
$password,
$this->trans('commands.create.users.messages.created'),
];
- if ($users['success']) {
- $io->table($tableHeader, $users['success']);
+ if ($result['success']) {
+ $this->getIo()->table($tableHeader, $result['success']);
- $io->success(
+ $this->getIo()->success(
sprintf(
$this->trans('commands.create.users.messages.created-users'),
- $limit
+ count($result['success'])
)
);
}
+ if (isset($result['error'])) {
+ foreach ($result['error'] as $error) {
+ $this->getIo()->error(
+ sprintf(
+ $this->trans('commands.create.users.messages.error'),
+ $error
+ )
+ );
+ }
+ }
+
return 0;
}
}