ChangeVersionCommand::execute()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 28
rs 8.8571
c 1
b 0
f 1
cc 2
eloc 16
nc 2
nop 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
     */
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('sys:setup:change-version')
18
            ->addArgument('module', InputArgument::REQUIRED, 'Module name')
19
            ->addArgument('version', InputArgument::REQUIRED, 'New version value')
20
            ->setDescription('Change module resource version');
21
        $help = <<<HELP
22
Change a module's resource version
23
HELP;
24
        $this->setHelp($help);
25
    }
26
27
    /**
28
     * @param InputInterface $input
29
     * @param OutputInterface $output
30
     * @return int|null|void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $this->detectMagento($output, true);
35
36
        if (!$this->initMagento()) {
37
            return;
38
        }
39
40
        $moduleVersion = $input->getArgument('version');
41
        $moduleName    = $this->getMagentoModuleName($input->getArgument('module'));
42
43
        /** @var \Magento\Framework\Module\ResourceInterface $resource */
44
        $resource = $this->getMagentoModuleResource();
45
46
        $originalVersion = $resource->getDbVersion($moduleName);
47
48
        $resource->setDbVersion($moduleName, $moduleVersion);
49
        $resource->setDataVersion($moduleName, $moduleVersion);
50
51
        $output->writeln(
52
            sprintf(
53
                '<info>Successfully updated: "%s" from version "%s" to version: "%s"</info>',
54
                $moduleName,
55
                $originalVersion,
56
                $moduleVersion
57
            )
58
        );
59
    }
60
}
61