Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexerStatusCommand.php
Go to the documentation of this file.
1 <?php
7 
8 use Symfony\Component\Console\Input\InputInterface;
9 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Helper\Table;
13 
18 {
22  protected function configure()
23  {
24  $this->setName('indexer:status')
25  ->setDescription('Shows status of Indexer')
26  ->setDefinition($this->getInputList());
27 
28  parent::configure();
29  }
30 
34  protected function execute(InputInterface $input, OutputInterface $output)
35  {
36  $table = new Table($output);
37  $table->setHeaders(['Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']);
38 
39  $rows = [];
40 
41  $indexers = $this->getIndexers($input);
42  foreach ($indexers as $indexer) {
43  $view = $indexer->getView();
44 
45  $rowData = [
46  'Title' => $indexer->getTitle(),
47  'Status' => $this->getStatus($indexer),
48  'Update On' => $indexer->isScheduled() ? 'Schedule' : 'Save',
49  'Schedule Status' => '',
50  'Updated' => '',
51  ];
52 
53  if ($indexer->isScheduled()) {
54  $state = $view->getState();
55  $rowData['Schedule Status'] = "{$state->getStatus()} ({$this->getPendingCount($view)} in backlog)";
56  $rowData['Updated'] = $state->getUpdated();
57  }
58 
59  $rows[] = $rowData;
60  }
61 
62  usort($rows, function ($comp1, $comp2) {
63  return strcmp($comp1['Title'], $comp2['Title']);
64  });
65 
66  $table->addRows($rows);
67  $table->render();
68  }
69 
74  private function getStatus(Indexer\IndexerInterface $indexer)
75  {
76  $status = 'unknown';
77  switch ($indexer->getStatus()) {
78  case \Magento\Framework\Indexer\StateInterface::STATUS_VALID:
79  $status = 'Ready';
80  break;
81  case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID:
82  $status = 'Reindex required';
83  break;
84  case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING:
85  $status = 'Processing';
86  break;
87  }
88  return $status;
89  }
90 
95  private function getPendingCount(Mview\ViewInterface $view)
96  {
97  $changelog = $view->getChangelog();
98 
99  try {
100  $currentVersionId = $changelog->getVersion();
101  } catch (Mview\View\ChangelogTableNotExistsException $e) {
102  return '';
103  }
104 
105  $state = $view->getState();
106 
107  $pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId));
108 
109  $pendingString = "<error>$pendingCount</error>";
110  if ($pendingCount <= 0) {
111  $pendingString = "<info>$pendingCount</info>";
112  }
113 
114  return $pendingString;
115  }
116 }
execute(InputInterface $input, OutputInterface $output)
$status
Definition: order_status.php:8
$table
Definition: trigger.php:14