netz98 /
n98-magerun2
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace N98\Magento\Command\Admin\User; |
||
| 4 | |||
| 5 | use Symfony\Component\Console\Input\InputArgument; |
||
| 6 | use Symfony\Component\Console\Input\InputInterface; |
||
| 7 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 8 | use Symfony\Component\Console\Input\InputOption; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class DeleteUserCommand |
||
| 12 | */ |
||
| 13 | class DeleteUserCommand extends AbstractAdminUserCommand |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Configure |
||
| 17 | */ |
||
| 18 | protected function configure() |
||
| 19 | { |
||
| 20 | $this |
||
| 21 | ->setName('admin:user:delete') |
||
| 22 | ->addArgument('id', InputArgument::OPTIONAL, 'Username or Email') |
||
| 23 | ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force') |
||
| 24 | ->setDescription('Delete the account of a adminhtml user.') |
||
| 25 | ; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param InputInterface $input |
||
| 30 | * @param OutputInterface $output |
||
| 31 | * @throws \Exception |
||
| 32 | * @return int|void |
||
| 33 | */ |
||
| 34 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 35 | { |
||
| 36 | $this->detectMagento($output); |
||
| 37 | if ($this->initMagento()) { |
||
| 38 | |||
| 39 | $dialog = $this->getHelperSet()->get('dialog'); |
||
| 40 | // Username |
||
| 41 | if (($id = $input->getArgument('id')) == null) { |
||
| 42 | $id = $dialog->ask($output, '<question>Username or Email:</question>'); |
||
| 43 | } |
||
| 44 | |||
| 45 | $user = $this->userModel->loadByUsername($id); |
||
| 46 | if (!$user->getId()) { |
||
| 47 | $user = $this->userModel->load($id, 'email'); |
||
| 48 | } |
||
| 49 | |||
| 50 | if (!$user->getId()) { |
||
| 51 | $output->writeln('<error>User was not found</error>'); |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | $shouldRemove = $input->getOption('force'); |
||
| 56 | if (!$shouldRemove) { |
||
| 57 | $shouldRemove = $dialog->askConfirmation($output, '<question>Are you sure?</question> <comment>[n]</comment>: ', false); |
||
|
0 ignored issues
–
show
|
|||
| 58 | } |
||
| 59 | |||
| 60 | if ($shouldRemove) { |
||
| 61 | try { |
||
| 62 | $user->delete(); |
||
| 63 | $output->writeln('<info>User was successfully deleted</info>'); |
||
| 64 | } catch (\Exception $e) { |
||
| 65 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | $output->writeln('<error>Aborting delete</error>'); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.