Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UnlockAdminAccountCommand.php
Go to the documentation of this file.
1 <?php
7 
8 use Symfony\Component\Console\Command\Command;
9 use Symfony\Component\Console\Input\InputArgument;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
13 
17 class UnlockAdminAccountCommand extends Command
18 {
19  const ARGUMENT_ADMIN_USERNAME = 'username';
20  const ARGUMENT_ADMIN_USERNAME_DESCRIPTION = 'The admin username to unlock';
21  const COMMAND_ADMIN_ACCOUNT_UNLOCK = 'admin:user:unlock';
22  const COMMAND_DESCRIPTION = 'Unlock Admin Account';
23  const USER_ID = 'user_id';
24 
28  private $adminUser;
29 
35  public function __construct(
36  AdminUser $adminUser,
37  $name = null
38  ) {
39  $this->adminUser = $adminUser;
40  parent::__construct($name);
41  }
42 
46  protected function execute(InputInterface $input, OutputInterface $output)
47  {
48  $adminUserName = $input->getArgument(self::ARGUMENT_ADMIN_USERNAME);
49  $userData = $this->adminUser->loadByUsername($adminUserName);
50  $outputMessage = sprintf('Couldn\'t find the user account "%s"', $adminUserName);
51  if ($userData) {
52  if (isset($userData[self::USER_ID]) && $this->adminUser->unlock($userData[self::USER_ID])) {
53  $outputMessage = sprintf('The user account "%s" has been unlocked', $adminUserName);
54  } else {
55  $outputMessage = sprintf(
56  'The user account "%s" was not locked or could not be unlocked',
57  $adminUserName
58  );
59  }
60  }
61  $output->writeln('<info>' . $outputMessage . '</info>');
62  }
63 
67  protected function configure()
68  {
69  $this->setName(self::COMMAND_ADMIN_ACCOUNT_UNLOCK);
70  $this->setDescription(self::COMMAND_DESCRIPTION);
71  $this->addArgument(
72  self::ARGUMENT_ADMIN_USERNAME,
73  InputArgument::REQUIRED,
74  self::ARGUMENT_ADMIN_USERNAME_DESCRIPTION
75  );
76  $this->setHelp(
77  <<<HELP
78 This command unlocks an admin account by its username.
79 To unlock:
80  <comment>%command.full_name% username</comment>
81 HELP
82  );
83  parent::configure();
84  }
85 }
execute(InputInterface $input, OutputInterface $output)
if(!isset($_GET['name'])) $name
Definition: log.php:14