X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FUser%2FLoginCleanAttemptsCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FUser%2FLoginCleanAttemptsCommand.php;h=b8c3a40efa50f8638b01ccde63dc24da8b28c5d8;hp=94fd669f48c3942b586aa2caf6d1c7828962ee62;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/User/LoginCleanAttemptsCommand.php b/vendor/drupal/console/src/Command/User/LoginCleanAttemptsCommand.php index 94fd669f4..b8c3a40ef 100644 --- a/vendor/drupal/console/src/Command/User/LoginCleanAttemptsCommand.php +++ b/vendor/drupal/console/src/Command/User/LoginCleanAttemptsCommand.php @@ -10,18 +10,12 @@ namespace Drupal\Console\Command\User; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; -use Drupal\Console\Command\Shared\ConfirmationTrait; -use Symfony\Component\Console\Command\Command; -use Drupal\Console\Core\Command\Shared\CommandTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Database\Connection; -use Drupal\Console\Core\Style\DrupalStyle; use Drupal\user\Entity\User; -class LoginCleanAttemptsCommand extends Command +class LoginCleanAttemptsCommand extends UserBase { - use CommandTrait; - use ConfirmationTrait; - /** * @var Connection */ @@ -30,12 +24,15 @@ class LoginCleanAttemptsCommand extends Command /** * LoginCleanAttemptsCommand constructor. * - * @param Connection $database + * @param Connection $database + * @param EntityTypeManagerInterface $entityTypeManager */ - public function __construct(Connection $database) - { + public function __construct( + Connection $database, + EntityTypeManagerInterface $entityTypeManager + ) { $this->database = $database; - parent::__construct(); + parent::__construct($entityTypeManager); } /** @@ -47,7 +44,12 @@ class LoginCleanAttemptsCommand extends Command setName('user:login:clear:attempts') ->setDescription($this->trans('commands.user.login.clear.attempts.description')) ->setHelp($this->trans('commands.user.login.clear.attempts.help')) - ->addArgument('uid', InputArgument::REQUIRED, $this->trans('commands.user.login.clear.attempts.options.user-id')); + ->addArgument( + 'user', + InputArgument::REQUIRED, + $this->trans('commands.user.login.clear.attempts.arguments.user') + ) + ->setAliases(['ulca']); } /** @@ -55,42 +57,7 @@ class LoginCleanAttemptsCommand extends Command */ protected function interact(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - - $uid = $input->getArgument('uid'); - // Check if $uid argument is already set. - if (!$uid) { - while (true) { - // Request $uid argument. - $uid = $io->ask( - $this->trans('commands.user.login.clear.attempts.questions.uid'), - 1, - function ($uid) use ($io) { - $message = (!is_numeric($uid)) ? - $this->trans('commands.user.login.clear.attempts.questions.numeric-uid') : - false; - // Check if $uid is upper than zero. - if (!$message && $uid <= 0) { - $message = $this->trans('commands.user.login.clear.attempts.questions.invalid-uid'); - } - // Check if message was defined. - if ($message) { - $io->error($message); - - return false; - } - // Return a valid $uid. - return (int) $uid; - } - ); - - if ($uid) { - break; - } - } - - $input->setArgument('uid', $uid); - } + $this->getUserArgument(); } /** @@ -98,17 +65,14 @@ class LoginCleanAttemptsCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - - $uid = $input->getArgument('uid'); - $account = User::load($uid); + $user = $input->getArgument('user'); + $userEntity = $this->getUserEntity($user); - if (!$account) { - // Error loading User entity. - $io->error( + if (!$userEntity) { + $this->getIo()->error( sprintf( $this->trans('commands.user.login.clear.attempts.errors.invalid-user'), - $uid + $user ) ); @@ -119,14 +83,14 @@ class LoginCleanAttemptsCommand extends Command $event = 'user.failed_login_user'; // Identifier is created by uid and IP address, // Then we defined a generic identifier. - $identifier = "{$account->id()}-"; + $identifier = "{$userEntity->id()}-"; // Retrieve current database connection. $schema = $this->database->schema(); $flood = $schema->findTables('flood'); if (!$flood) { - $io->error( + $this->getIo()->error( $this->trans('commands.user.login.clear.attempts.errors.no-flood') ); @@ -140,10 +104,10 @@ class LoginCleanAttemptsCommand extends Command ->execute(); // Command executed successful. - $io->success( + $this->getIo()->success( sprintf( $this->trans('commands.user.login.clear.attempts.messages.successful'), - $uid + $userEntity->getUsername() ) ); }