Completed
Pull Request — develop (#891)
by Luke
04:18
created

ListMviewCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Indexer;
4
5
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class ListMviewCommand extends AbstractMviewIndexerCommand
11
{
12 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        $this
15
            ->setName('index:list:mview')
16
            ->setDescription('Lists all magento mview indexes')
17
            ->addOption(
18
                'format',
19
                null,
20
                InputOption::VALUE_OPTIONAL,
21
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
22
            )
23
        ;
24
25
        $help = <<<HELP
26
Lists all Magento mview indexers of current installation.
27
HELP;
28
        $this->setHelp($help);
29
    }
30
31
    /**
32
     * @param InputInterface  $input
33
     * @param OutputInterface $output
34
     *
35
     * @return int|void
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $this->detectMagento($output, true);
40
        if (!$this->initMagento()) {
41
            return;
42
        }
43
44
        $table = array();
45
        foreach ($this->getMetaDataCollection() as $index) {
46
47
            $pendingCount = $this->getPendingChangelogsCount($index->getData('changelog_name'), $index->getData('version_id'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

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.

Loading history...
48
            if ($pendingCount>0) {
49
                $pendingString = "<error>$pendingCount</error>";
50
            } else {
51
                $pendingString = "<info>$pendingCount</info>";
52
            }
53
54
            $table[] = array(
55
                $index->getData('table_name'),
56
                $index->getData('view_name'),
57
                $index->getData('changelog_name'),
58
                $index->getData('status'),
59
                $index->getData('version_id'),
60
                $pendingString
61
            );
62
        }
63
64
        $this->getHelper('table')
65
            ->setHeaders(array('table_name', 'view_name', 'changelog_name', 'status', 'version_id', 'entries pending reindex'))
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

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.

Loading history...
66
            ->renderByFormat($output, $table, $input->getOption('format'));
67
    }
68
69
    /**
70
     * @param $tableName
71
     * @param $currentVersionId
72
     * @return int
73
     */
74
    protected function getPendingChangelogsCount($tableName, $currentVersionId)
75
    {
76
        /** @var \Mage_Core_Model_Resource $resource */
77
        $resource = $this->_getSingleton('core/resource');
0 ignored issues
show
Bug introduced by
The call to _getSingleton() misses a required argument $mage2class.

This check looks for function calls that miss required arguments.

Loading history...
78
        $readConnection = $resource->getConnection('core_read');
79
80
        $select = $readConnection->select()
81
            ->from($tableName, array('count(*)'))
82
            ->where("version_id > ?", $currentVersionId);
83
        $todoCount = $readConnection->fetchOne($select);
84
85
        return (int) $todoCount;
86
    }
87
}
88