Completed
Pull Request — develop (#810)
by Robbie
04:27
created

LockdownCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 65
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
B execute() 0 39 6
1
<?php
2
3
namespace N98\Magento\Command\Admin\User;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class LockdownCommand extends LockCommand
11
{
12
    /**
13
     * Setup
14
     *
15
     * @return void
16
     */
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('admin:user:lockdown')
21
            ->addArgument('lifetime', InputArgument::OPTIONAL, 'Optional - lock lifetime (default one month)')
22
            ->setDescription(
23
                <<<HELP
24
Lock every admin user account for the optionally specified lifetime (in days). If not provided, defaults to one month.
25
HELP
26
            );
27
    }
28
29
    /**
30
     * @param InputInterface  $input
31
     * @param OutputInterface $output
32
     *
33
     * @return void
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $this->detectMagento($output, true);
38
        if (!$this->initMagento()) {
39
            return;
40
        }
41
42
        $lifetime = $input->getArgument('lifetime') ?: $this->daysToSeconds(self::LIFETIME_DEFAULT);
43
44
        $userIds = \Mage::getModel('admin/user')->getCollection()->getAllIds();
45
46
        if (empty($userIds)) {
47
            $output->writeln('<error>No admin users were found!</error>');
48
            return;
49
        }
50
51
        /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
52
        $dialog = $this->getHelperSet()->get('dialog');
53
        $confirm = $dialog->ask(
54
            $output,
55
            '<info><comment>Are you sure? This will lock all admin accounts! Type "yes" to continue...</comment></info>'
56
            . PHP_EOL
57
        );
58
59
        if ('yes' !== $confirm) {
60
            return;
61
        }
62
63
        \Mage::getResourceModel('enterprise_pci/admin_user')->lock($userIds, 0, $lifetime);
64
65
        $lifetimeMessage = '';
66
        if ($input->getArgument('lifetime')) {
67
            $lifetimeMessage = sprintf(' for %d days.', $input->getArgument('lifetime'));
68
        }
69
70
        $output->writeln(
71
            sprintf('<info><comment>All %d admins</comment> locked%s</info>', count($userIds), $lifetimeMessage)
72
        );
73
    }
74
}
75