X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FUsersCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FUsersCommand.php;h=4fc6c1f748819b971558a33348d221c30960af08;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Create/UsersCommand.php b/vendor/drupal/console/src/Command/Create/UsersCommand.php new file mode 100644 index 000000000..4fc6c1f74 --- /dev/null +++ b/vendor/drupal/console/src/Command/Create/UsersCommand.php @@ -0,0 +1,190 @@ +drupalApi = $drupalApi; + $this->createUserData = $createUserData; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('create:users') + ->setDescription($this->trans('commands.create.users.description')) + ->addArgument( + 'roles', + InputArgument::IS_ARRAY, + $this->trans('commands.create.users.arguments.roles') + ) + ->addOption( + 'limit', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.users.options.limit') + ) + ->addOption( + 'password', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.users.options.password') + ) + ->addOption( + 'time-range', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.users.options.time-range') + ); + } + + /** + * {@inheritdoc} + */ + 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( + $this->trans('commands.create.users.questions.roles'), + array_values($roles), + null, + true + ); + + $rids = array_map( + function ($role) use ($roles) { + return array_search($role, $roles); + }, + $rids + ); + + $input->setArgument('roles', $rids); + } + + $limit = $input->getOption('limit'); + if (!$limit) { + $limit = $io->ask( + $this->trans('commands.create.users.questions.limit'), + 10 + ); + $input->setOption('limit', $limit); + } + + $password = $input->getOption('password'); + if (!$password) { + $password = $io->ask( + $this->trans('commands.create.users.questions.password'), + 5 + ); + + $input->setOption('password', $password); + } + + $timeRange = $input->getOption('time-range'); + if (!$timeRange) { + $timeRanges = $this->getTimeRange(); + + $timeRange = $io->choice( + $this->trans('commands.create.nodes.questions.time-range'), + array_values($timeRanges) + ); + + $input->setOption('time-range', array_search($timeRange, $timeRanges)); + } + } + + /** + * {@inheritdoc} + */ + 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'); + $timeRange = $input->getOption('time-range')?:31536000; + + if (!$roles) { + $roles = $this->drupalApi->getRoles(); + } + + $users = $this->createUserData->create( + $roles, + $limit, + $password, + $timeRange + ); + + $tableHeader = [ + $this->trans('commands.create.users.messages.user-id'), + $this->trans('commands.create.users.messages.username'), + $this->trans('commands.create.users.messages.roles'), + $this->trans('commands.create.users.messages.created'), + ]; + + if ($users['success']) { + $io->table($tableHeader, $users['success']); + + $io->success( + sprintf( + $this->trans('commands.create.users.messages.created-users'), + $limit + ) + ); + } + + return 0; + } +}