|
| 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 | +} |
0 commit comments