Completed
Pull Request — develop (#166)
by Robbie
04:29
created

ChangeVersionCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 23 2
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ChangeVersionCommand extends AbstractSetupCommand
10
{
11
    protected $moduleList;
12
    /**
13
     * Setup
14
     * @return void
15
     */
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('sys:setup:change-version')
20
            ->addArgument('module', InputArgument::REQUIRED, 'Module name')
21
            ->addArgument('version', InputArgument::REQUIRED, 'New version value')
22
            ->setDescription('Change module resource version');
23
        $help = <<<HELP
24
Change a module's resource version
25
HELP;
26
        $this->setHelp($help);
27
    }
28
29
    /**
30
     * @param  InputInterface  $input
31
     * @param  OutputInterface $output
32
     * @return void
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->detectMagento($output, true);
37
38
        if (!$this->initMagento()) {
39
            return;
40
        }
41
42
        $moduleVersion = $input->getArgument('version');
43
        $moduleName    = $this->getModuleName($input->getArgument('module'));
44
45
        /** @var \Magento\Framework\Module\ResourceInterface */
46
        $this->getResource()->setDbVersion($moduleName, $moduleVersion);
47
        $this->getResource()->setDataVersion($moduleName, $moduleVersion);
48
49
        $output->writeln(
50
            sprintf(
51
                '<info>Successfully updated: "%s" to version: "%s"</info>',
52
                $moduleName,
53
                $moduleVersion
54
            )
55
        );
56
    }
57
}
58