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