1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Indexer; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class ReindexMviewCommand extends AbstractMviewIndexerCommand |
11
|
|
|
{ |
12
|
|
|
protected function configure() |
13
|
|
|
{ |
14
|
|
|
$this |
15
|
|
|
->setName('index:reindex:mview') |
16
|
|
|
->addArgument('table_name', InputArgument::REQUIRED, 'View table name"') |
17
|
|
|
->setDescription('Reindex a magento index by code using the materialised view functionality'); |
18
|
|
|
|
19
|
|
|
$help = <<<HELP |
20
|
|
|
Trigger a mview index by table_name. |
21
|
|
|
|
22
|
|
|
$ n98-magerun.phar index:reindex:mview [table_name] |
23
|
|
|
HELP; |
24
|
|
|
$this->setHelp($help); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param InputInterface $input |
29
|
|
|
* @param OutputInterface $output |
30
|
|
|
* |
31
|
|
|
* @return int|void |
32
|
|
|
*/ |
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
34
|
|
|
{ |
35
|
|
|
$this->detectMagento($output, true); |
36
|
|
|
if (!$this->initMagento()) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
$tableName = $input->getArgument('table_name'); |
40
|
|
|
|
41
|
|
|
$indexers = $this->getIndexers(); |
42
|
|
|
|
43
|
|
|
if (!array_key_exists($tableName, $indexers)) { |
44
|
|
|
throw new \InvalidArgumentException("$tableName is not a view table"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$indexerData = $indexers[$tableName]; |
48
|
|
|
$indexTable = (string) $indexerData->index_table; |
49
|
|
|
$actionName = (string) $indexerData->action_model->changelog; |
50
|
|
|
|
51
|
|
|
$client = $this->getMviewClient(); |
52
|
|
|
$client->init($indexTable); |
53
|
|
|
if (!$client->getMetadata()->getId()) { |
54
|
|
|
throw new \InvalidArgumentException("Could not load metadata for $tableName"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$output->writeln("<info>Starting mview indexer <comment>{$indexTable}</comment> with action <comment>{$actionName}</comment> </info>"); |
|
|
|
|
58
|
|
|
$client->execute($actionName); |
59
|
|
|
$output->writeln("<info>Done</info>"); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.