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() |
|
|
|
|
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
|
|
|
$changelogName = $index->getData('changelog_name'); |
47
|
|
|
$versionId = $index->getData('version_id'); |
48
|
|
|
$pendingCount = $this->getPendingChangelogsCount($changelogName, $versionId); |
49
|
|
|
if ($pendingCount>0) { |
50
|
|
|
$pendingString = "<error>$pendingCount</error>"; |
51
|
|
|
} else { |
52
|
|
|
$pendingString = "<info>$pendingCount</info>"; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$table[] = array( |
56
|
|
|
$index->getData('table_name'), |
57
|
|
|
$index->getData('view_name'), |
58
|
|
|
$changelogName, |
59
|
|
|
$index->getData('status'), |
60
|
|
|
$versionId, |
61
|
|
|
$pendingString, |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->getHelper('table') |
66
|
|
|
->setHeaders( |
67
|
|
|
array( |
68
|
|
|
'table_name', |
69
|
|
|
'view_name', |
70
|
|
|
'changelog_name', |
71
|
|
|
'status', |
72
|
|
|
'version_id', |
73
|
|
|
'entries pending reindex' |
74
|
|
|
) |
75
|
|
|
) |
76
|
|
|
->renderByFormat($output, $table, $input->getOption('format')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param $tableName |
81
|
|
|
* @param $currentVersionId |
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
|
|
protected function getPendingChangelogsCount($tableName, $currentVersionId) |
85
|
|
|
{ |
86
|
|
|
/** @var \Mage_Core_Model_Resource $resource */ |
87
|
|
|
$resource = $this->_getSingleton('core/resource'); |
|
|
|
|
88
|
|
|
$readConnection = $resource->getConnection('core_read'); |
89
|
|
|
|
90
|
|
|
$select = $readConnection->select() |
91
|
|
|
->from($tableName, array('count(*)')) |
92
|
|
|
->where("version_id > ?", $currentVersionId); |
93
|
|
|
$todoCount = $readConnection->fetchOne($select); |
94
|
|
|
|
95
|
|
|
return (int) $todoCount; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.