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: class Mage_Index_Adminhtml_ProcessController extends Mage_Adminhtml_Controller_Action
27: {
28: 29: 30: 31: 32:
33: protected function _initProcess()
34: {
35: $processId = $this->getRequest()->getParam('process');
36: if ($processId) {
37: $process = Mage::getModel('index/process')->load($processId);
38: if ($process->getId()) {
39: return $process;
40: }
41: }
42: return false;
43: }
44:
45: 46: 47:
48: public function listAction()
49: {
50: $this->_title($this->__('System'))->_title($this->__('Index Management'));
51:
52: $this->loadLayout();
53: $this->_setActiveMenu('system/index');
54: $this->_addContent($this->getLayout()->createBlock('index/adminhtml_process'));
55: $this->renderLayout();
56: }
57:
58: 59: 60:
61: public function editAction()
62: {
63: $process = $this->_initProcess();
64: if ($process) {
65: $this->_title($process->getIndexCode());
66:
67: $this->_title($this->__('System'))
68: ->_title($this->__('Index Management'))
69: ->_title($this->__($process->getIndexer()->getName()));
70:
71: Mage::register('current_index_process', $process);
72: $this->loadLayout();
73: $this->renderLayout();
74: } else {
75: $this->_getSession()->addError(
76: Mage::helper('index')->__('Cannot initialize the indexer process.')
77: );
78: $this->_redirect('*/*/list');
79: }
80: }
81:
82: 83: 84:
85: public function saveAction()
86: {
87: $process = $this->_initProcess();
88: if ($process) {
89: $mode = $this->getRequest()->getPost('mode');
90: if ($mode) {
91: $process->setMode($mode);
92: }
93: try {
94: $process->save();
95: $this->_getSession()->addSuccess(
96: Mage::helper('index')->__('The index has been saved.')
97: );
98: } catch (Mage_Core_Exception $e) {
99: $this->_getSession()->addError($e->getMessage());
100: } catch (Exception $e) {
101: $this->_getSession()->addException($e,
102: Mage::helper('index')->__('There was a problem with saving process.')
103: );
104: }
105: $this->_redirect('*/*/list');
106: } else {
107: $this->_getSession()->addError(
108: Mage::helper('index')->__('Cannot initialize the indexer process.')
109: );
110: $this->_redirect('*/*/list');
111: }
112: }
113:
114: 115: 116:
117: public function reindexProcessAction()
118: {
119: $process = $this->_initProcess();
120: if ($process) {
121: try {
122: Varien_Profiler::start('__INDEX_PROCESS_REINDEX_ALL__');
123:
124: $process->reindexEverything();
125: Varien_Profiler::stop('__INDEX_PROCESS_REINDEX_ALL__');
126: $this->_getSession()->addSuccess(
127: Mage::helper('index')->__('%s index was rebuilt.', $process->getIndexer()->getName())
128: );
129: } catch (Mage_Core_Exception $e) {
130: $this->_getSession()->addError($e->getMessage());
131: } catch (Exception $e) {
132: $this->_getSession()->addException($e,
133: Mage::helper('index')->__('There was a problem with reindexing process.')
134: );
135: }
136: } else {
137: $this->_getSession()->addError(
138: Mage::helper('index')->__('Cannot initialize the indexer process.')
139: );
140: }
141:
142: $this->_redirect('*/*/list');
143: }
144:
145: 146: 147:
148: public function reindexEventsAction()
149: {
150:
151: }
152:
153: 154: 155:
156: public function reindexAllAction()
157: {
158:
159: }
160:
161: 162: 163: 164:
165: public function massReindexAction()
166: {
167:
168: $indexer = Mage::getSingleton('index/indexer');
169: $processIds = $this->getRequest()->getParam('process');
170: if (empty($processIds) || !is_array($processIds)) {
171: $this->_getSession()->addError(Mage::helper('index')->__('Please select Indexes'));
172: } else {
173: try {
174: foreach ($processIds as $processId) {
175:
176: $process = $indexer->getProcessById($processId);
177: if ($process) {
178: $process->reindexEverything();
179: }
180: }
181: $count = count($processIds);
182: $this->_getSession()->addSuccess(
183: Mage::helper('index')->__('Total of %d index(es) have reindexed data.', $count)
184: );
185: } catch (Mage_Core_Exception $e) {
186: $this->_getSession()->addError($e->getMessage());
187: } catch (Exception $e) {
188: $this->_getSession()->addException($e, Mage::helper('index')->__('Cannot initialize the indexer process.'));
189: }
190: }
191:
192: $this->_redirect('*/*/list');
193: }
194:
195: 196: 197: 198:
199: public function massChangeModeAction()
200: {
201: $processIds = $this->getRequest()->getParam('process');
202: if (empty($processIds) || !is_array($processIds)) {
203: $this->_getSession()->addError(Mage::helper('index')->__('Please select Index(es)'));
204: } else {
205: try {
206: $mode = $this->getRequest()->getParam('index_mode');
207: foreach ($processIds as $processId) {
208:
209: $process = Mage::getModel('index/process')->load($processId);
210: if ($process->getId()) {
211: $process->setMode($mode)
212: ->save();
213: }
214: }
215: $count = count($processIds);
216: $this->_getSession()->addSuccess(
217: Mage::helper('index')->__('Total of %d index(es) have changed index mode.', $count)
218: );
219: } catch (Mage_Core_Exception $e) {
220: $this->_getSession()->addError($e->getMessage());
221: } catch (Exception $e) {
222: $this->_getSession()->addException($e, Mage::helper('index')->__('Cannot initialize the indexer process.'));
223: }
224: }
225:
226: $this->_redirect('*/*/list');
227: }
228:
229: 230: 231: 232: 233:
234: protected function _isAllowed()
235: {
236: return Mage::getSingleton('admin/session')->isAllowed('system/index');
237: }
238: }
239: