Completed
Pull Request — develop (#167)
by Robbie
04:11
created

ChangeVersionCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

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
    /**
12
     * Setup
13
     * @return void
14
     */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('sys:setup:change-version')
19
            ->addArgument('module', InputArgument::REQUIRED, 'Module name')
20
            ->addArgument('version', InputArgument::REQUIRED, 'New version value')
21
            ->setDescription('Change module resource version');
22
        $help = <<<HELP
23
Change a module's resource version
24
HELP;
25
        $this->setHelp($help);
26
    }
27
28
    /**
29
     * @param  InputInterface  $input
30
     * @param  OutputInterface $output
31
     * @return void
32
     */
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->detectMagento($output, true);
36
37
        if (!$this->initMagento()) {
38
            return;
39
        }
40
41
        $moduleVersion = $input->getArgument('version');
42
        $moduleName    = $this->getMagentoModuleName($input->getArgument('module'));
43
44
        /** @var \Magento\Framework\Module\ResourceInterface */
45
        $this->getMagentoModuleResource()->setDbVersion($moduleName, $moduleVersion);
46
        $this->getMagentoModuleResource()->setDataVersion($moduleName, $moduleVersion);
47
48
        $output->writeln(
49
            sprintf(
50
                '<info>Successfully updated: "%s" to version: "%s"</info>',
51
                $moduleName,
52
                $moduleVersion
53
            )
54
        );
55
    }
56
}
57