1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: class Mage_Index_Block_Adminhtml_Process_Grid extends Mage_Adminhtml_Block_Widget_Grid
28: {
29: 30: 31: 32: 33:
34: protected $_processModel;
35:
36: 37: 38: 39: 40:
41: protected $_massactionBlockName = 'index/adminhtml_process_grid_massaction';
42:
43: 44: 45:
46: public function __construct()
47: {
48: parent::__construct();
49: $this->_processModel = Mage::getSingleton('index/process');
50: $this->setId('indexer_processes_grid');
51: $this->_filterVisibility = false;
52: $this->_pagerVisibility = false;
53: }
54:
55: 56: 57:
58: protected function _prepareCollection()
59: {
60: $collection = Mage::getResourceModel('index/process_collection');
61: $this->setCollection($collection);
62: return parent::_prepareCollection();
63: }
64:
65: 66: 67:
68: protected function _afterLoadCollection()
69: {
70:
71: foreach ($this->_collection as $key => $item) {
72: if (!$item->getIndexer()->isVisible()) {
73: $this->_collection->removeItemByKey($key);
74: continue;
75: }
76: $item->setName($item->getIndexer()->getName());
77: $item->setDescription($item->getIndexer()->getDescription());
78: $item->setUpdateRequired($item->getUnprocessedEventsCollection()->count() > 0 ? 1 : 0);
79: if ($item->isLocked()) {
80: $item->setStatus(Mage_Index_Model_Process::STATUS_RUNNING);
81: }
82: }
83: return $this;
84: }
85:
86: 87: 88:
89: protected function _prepareColumns()
90: {
91: $baseUrl = $this->getUrl();
92: $this->addColumn('indexer_code', array(
93: 'header' => Mage::helper('index')->__('Index'),
94: 'width' => '180',
95: 'align' => 'left',
96: 'index' => 'name',
97: 'sortable' => false,
98: ));
99:
100: $this->addColumn('description', array(
101: 'header' => Mage::helper('index')->__('Description'),
102: 'align' => 'left',
103: 'index' => 'description',
104: 'sortable' => false,
105: ));
106:
107: $this->addColumn('mode', array(
108: 'header' => Mage::helper('index')->__('Mode'),
109: 'width' => '150',
110: 'align' => 'left',
111: 'index' => 'mode',
112: 'type' => 'options',
113: 'options' => $this->_processModel->getModesOptions()
114: ));
115:
116: $this->addColumn('status', array(
117: 'header' => Mage::helper('index')->__('Status'),
118: 'width' => '120',
119: 'align' => 'left',
120: 'index' => 'status',
121: 'type' => 'options',
122: 'options' => $this->_processModel->getStatusesOptions(),
123: 'frame_callback' => array($this, 'decorateStatus')
124: ));
125:
126: $this->addColumn('update_required', array(
127: 'header' => Mage::helper('index')->__('Update Required'),
128: 'sortable' => false,
129: 'width' => '120',
130: 'align' => 'left',
131: 'index' => 'update_required',
132: 'type' => 'options',
133: 'options' => $this->_processModel->getUpdateRequiredOptions(),
134: 'frame_callback' => array($this, 'decorateUpdateRequired')
135: ));
136:
137: $this->addColumn('ended_at', array(
138: 'header' => Mage::helper('index')->__('Updated At'),
139: 'type' => 'datetime',
140: 'width' => '180',
141: 'align' => 'left',
142: 'index' => 'ended_at',
143: 'frame_callback' => array($this, 'decorateDate')
144: ));
145:
146: $this->addColumn('action',
147: array(
148: 'header' => Mage::helper('index')->__('Action'),
149: 'width' => '100',
150: 'type' => 'action',
151: 'getter' => 'getId',
152: 'actions' => array(
153: array(
154: 'caption' => Mage::helper('index')->__('Reindex Data'),
155: 'url' => array('base'=> '*/*/reindexProcess'),
156: 'field' => 'process'
157: ),
158: ),
159: 'filter' => false,
160: 'sortable' => false,
161: 'is_system' => true,
162: ));
163:
164: return parent::_prepareColumns();
165: }
166:
167: 168: 169: 170: 171: 172: 173: 174: 175:
176: public function decorateStatus($value, $row, $column, $isExport)
177: {
178: $class = '';
179: switch ($row->getStatus()) {
180: case Mage_Index_Model_Process::STATUS_PENDING :
181: $class = 'grid-severity-notice';
182: break;
183: case Mage_Index_Model_Process::STATUS_RUNNING :
184: $class = 'grid-severity-major';
185: break;
186: case Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX :
187: $class = 'grid-severity-critical';
188: break;
189: }
190: return '<span class="'.$class.'"><span>'.$value.'</span></span>';
191: }
192:
193: 194: 195: 196: 197: 198: 199: 200: 201:
202: public function decorateUpdateRequired($value, $row, $column, $isExport)
203: {
204: $class = '';
205: switch ($row->getUpdateRequired()) {
206: case 0:
207: $class = 'grid-severity-notice';
208: break;
209: case 1:
210: $class = 'grid-severity-critical';
211: break;
212: }
213: return '<span class="'.$class.'"><span>'.$value.'</span></span>';
214: }
215:
216: 217: 218: 219: 220:
221: public function decorateDate($value, $row, $column, $isExport)
222: {
223: if(!$value) {
224: return $this->__('Never');
225: }
226: return $value;
227: }
228:
229: 230: 231: 232: 233:
234: public function getRowUrl($row)
235: {
236: return $this->getUrl('*/*/edit', array('process'=>$row->getId()));
237: }
238:
239: 240: 241:
242: protected function _prepareMassaction()
243: {
244: $this->setMassactionIdField('process_id');
245: $this->getMassactionBlock()->setFormFieldName('process');
246:
247: $modeOptions = Mage::getModel('index/process')->getModesOptions();
248:
249: $this->getMassactionBlock()->addItem('change_mode', array(
250: 'label' => Mage::helper('index')->__('Change Index Mode'),
251: 'url' => $this->getUrl('*/*/massChangeMode'),
252: 'additional' => array(
253: 'mode' => array(
254: 'name' => 'index_mode',
255: 'type' => 'select',
256: 'class' => 'required-entry',
257: 'label' => Mage::helper('index')->__('Index mode'),
258: 'values' => $modeOptions
259: )
260: )
261: ));
262:
263: $this->getMassactionBlock()->addItem('reindex', array(
264: 'label' => Mage::helper('index')->__('Reindex Data'),
265: 'url' => $this->getUrl('*/*/massReindex'),
266: 'selected' => true,
267: ));
268:
269: return $this;
270: }
271: }
272: