Skip to content

Commit e39b012

Browse files
committed
Add 'schedule status' column to admin indexer grid
This is a copy of the 'schedule status' column available via command line.
1 parent c0e73a8 commit e39b012

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;
7+
8+
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
9+
use Magento\Framework\Mview\View;
10+
use Magento\Framework\Phrase;
11+
12+
class ScheduleStatus extends AbstractRenderer
13+
{
14+
/**
15+
* @var \Magento\Framework\Mview\ViewInterface
16+
*/
17+
protected $viewModel;
18+
19+
public function __construct(
20+
\Magento\Backend\Block\Context $context,
21+
View $viewModel,
22+
array $data = []
23+
) {
24+
parent::__construct($context, $data);
25+
$this->viewModel = $viewModel;
26+
}
27+
28+
/**
29+
* Render indexer status
30+
*
31+
* @param \Magento\Framework\DataObject $row
32+
* @return string
33+
*/
34+
public function render(\Magento\Framework\DataObject $row)
35+
{
36+
try {
37+
if (!$row->getIsScheduled()) {
38+
return '';
39+
}
40+
41+
try {
42+
$view = $this->viewModel->load($row->getIndexerId());
43+
} catch (\InvalidArgumentException $exception) {
44+
// No view for this index.
45+
return '';
46+
}
47+
48+
$state = $view->getState()->loadByView($view->getId());
49+
$changelog = $view->getChangelog()->setViewId($view->getId());
50+
$currentVersionId = $changelog->getVersion();
51+
$count = count($changelog->getList($state->getVersionId(), $currentVersionId));
52+
53+
if ($count > 1000) {
54+
$class = 'grid-severity-critical';
55+
} elseif ($count > 100) {
56+
$class = 'grid-severity-major';
57+
} elseif ($count > 10) {
58+
$class = 'grid-severity-minor';
59+
} else {
60+
$class = 'grid-severity-notice';
61+
}
62+
63+
if ($state->getStatus() !== 'idle') {
64+
$class = 'grid-severity-minor';
65+
}
66+
67+
$text = new Phrase(
68+
"%status (%count in backlog)",
69+
[
70+
'status' => $state->getStatus(),
71+
'count' => $count,
72+
]
73+
);
74+
75+
return '<span class="' . $class . '"><span>' . $text . '</span></span>';
76+
} catch (\Exception $exception) {
77+
return '<span class="grid-severity-minor"><span>' .
78+
htmlspecialchars(
79+
get_class($exception) . ': ' . $exception->getMessage()
80+
) . '</span></span>';
81+
}
82+
}
83+
}

app/code/Magento/Indexer/view/adminhtml/layout/indexer_indexer_list_grid.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@
7676
<argument name="column_css_class" xsi:type="string">indexer-status</argument>
7777
</arguments>
7878
</block>
79+
<block class="Magento\Backend\Block\Widget\Grid\Column" name="adminhtml.indexer.grid.columnSet.indexer_schedule_status" as="indexer_schedule_status">
80+
<arguments>
81+
<argument name="header" xsi:type="string" translate="true">Schedule Status</argument>
82+
<argument name="index" xsi:type="string">schedule_status</argument>
83+
<argument name="renderer" xsi:type="string">Magento\Indexer\Block\Backend\Grid\Column\Renderer\ScheduleStatus</argument>
84+
<argument name="sortable" xsi:type="string">0</argument>
85+
<argument name="column_css_class" xsi:type="string">indexer-schedule-status</argument>
86+
</arguments>
87+
</block>
7988
<block class="Magento\Backend\Block\Widget\Grid\Column" name="adminhtml.indexer.grid.columnSet.indexer_updated" as="indexer_updated">
8089
<arguments>
8190
<argument name="header" xsi:type="string" translate="true">Updated</argument>

0 commit comments

Comments
 (0)