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: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_System_CacheController extends Mage_Adminhtml_Controller_Action
35: {
36: 37: 38: 39: 40:
41: protected function _getSession()
42: {
43: return Mage::getSingleton('adminhtml/session');
44: }
45:
46: 47: 48:
49: public function indexAction()
50: {
51: $this->loadLayout()
52: ->_setActiveMenu('system/cache')
53: ->_addContent($this->getLayout()->createBlock('adminhtml/system_cache_edit')->initForm())
54: ->renderLayout();
55: }
56:
57: 58: 59:
60: public function saveAction()
61: {
62: 63: 64:
65: $postData = $this->getRequest()->getPost();
66: if (empty($postData)) {
67: $this->_redirect('*/*');
68: return;
69: }
70:
71: 72: 73:
74: $allCache = $this->getRequest()->getPost('all_cache');
75: if ($allCache=='disable' || $allCache=='refresh') {
76: Mage::app()->cleanCache();
77: }
78:
79: $e = $this->getRequest()->getPost('enable');
80: $enable = array();
81: $clean = array();
82: $cacheTypes = array_keys(Mage::helper('core')->getCacheTypes());
83: foreach ($cacheTypes as $type) {
84: $flag = $allCache!='disable' && (!empty($e[$type]) || $allCache=='enable');
85: $enable[$type] = $flag ? 1 : 0;
86: if ($allCache=='' && !$flag) {
87: $clean[] = $type;
88: }
89: }
90:
91:
92: $beta = $this->getRequest()->getPost('beta');
93: $betaCache = array_keys(Mage::helper('core')->getCacheBetaTypes());
94: foreach ($betaCache as $type) {
95: if (empty($beta[$type])) {
96: $clean[] = $type;
97: } else {
98: $enable[$type] = 1;
99: }
100: }
101:
102:
103: if (!empty($clean)) {
104: Mage::app()->cleanCache($clean);
105: }
106: Mage::app()->saveUseCache($enable);
107:
108:
109: if ($this->getRequest()->getPost('jscss_action')) {
110: if (Mage::getDesign()->cleanMergedJsCss()) {
111: $this->_getSession()->addSuccess(
112: Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleared.')
113: );
114: } else {
115: $this->_getSession()->addError(Mage::helper('adminhtml')->__('Failed to clear the JavaScript/CSS cache.'));
116: }
117: }
118:
119: 120: 121:
122: if ($catalogAction = $this->getRequest()->getPost('catalog_action')) {
123:
124: switch ($catalogAction) {
125: case 'refresh_catalog_rewrites':
126: try {
127: Mage::getSingleton('catalog/url')->refreshRewrites();
128: $this->_getSession()->addSuccess(
129: Mage::helper('adminhtml')->__('The Catalog Rewrites were refreshed.')
130: );
131: }
132: catch (Mage_Core_Exception $e) {
133: $this->_getSession()->addError($e->getMessage());
134: }
135: catch (Exception $e) {
136: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while refreshing the Catalog Rewrites.'));
137: }
138: break;
139:
140: case 'clear_images_cache':
141: try {
142: Mage::getModel('catalog/product_image')->clearCache();
143: $this->_getSession()->addSuccess(
144: Mage::helper('adminhtml')->__('The image cache was cleared.')
145: );
146: }
147: catch (Mage_Core_Exception $e) {
148: $this->_getSession()->addError($e->getMessage());
149: }
150: catch (Exception $e) {
151: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while clearing the image cache.'));
152: }
153: break;
154:
155: case 'refresh_layered_navigation_now':
156: try {
157: $flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf();
158: if ($flag->getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING) {
159: $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf();
160: $kill->setFlagData($flag->getFlagData())->save();
161: }
162:
163: $flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save();
164: Mage::getSingleton('catalogindex/indexer')->plainReindex();
165: $this->_getSession()->addSuccess(
166: Mage::helper('adminhtml')->__('Layered Navigation Indices were refreshed.')
167: );
168: }
169: catch (Mage_Core_Exception $e) {
170: $this->_getSession()->addError($e->getMessage());
171: }
172: catch (Exception $e) {
173: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while refreshing the Layered Navigation indices.'));
174: }
175: break;
176:
177: case 'refresh_layered_navigation':
178: try {
179: $flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf();
180: switch ($flag->getState()) {
181: case Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED:
182: $flag->delete();
183: $this->_getSession()->addSuccess(
184: Mage::helper('adminhtml')->__('The Layered Navigation indexing queue has been canceled.')
185: );
186: break;
187: case Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING:
188: $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf();
189: $kill->setFlagData($flag->getFlagData())->save();
190: $this->_getSession()->addSuccess(
191: Mage::helper('adminhtml')->__('The Layered Navigation process has been queued to be killed.')
192: );
193: break;
194: default:
195: $flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save();
196: $this->_getSession()->addSuccess(
197: Mage::helper('adminhtml')->__('The Layered Navigation indexing has been queued.')
198: );
199: break;
200: }
201: }
202: catch (Mage_Core_Exception $e) {
203: $this->_getSession()->addError($e->getMessage());
204: }
205: catch (Exception $e) {
206: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while refreshing the Layered Navigation indices.'));
207: }
208: break;
209:
210: case 'rebuild_search_index':
211: try {
212: Mage::getSingleton('catalogsearch/fulltext')->rebuildIndex();
213: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The search index has been rebuilt.'));
214: }
215: catch (Mage_Core_Exception $e) {
216: $this->_getSession()->addError($e->getMessage());
217: }
218: catch (Exception $e) {
219: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while rebuilding the search index.'));
220: }
221: break;
222:
223: case 'rebuild_inventory_stock_status':
224: try {
225: Mage::getSingleton('cataloginventory/stock_status')->rebuild();
226: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The CatalogInventory Stock Status has been rebuilt.'));
227: }
228: catch (Mage_Core_Exception $e) {
229: $this->_getSession()->addError($e->getMessage());
230: }
231: catch (Exception $e) {
232: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while rebuilding the CatalogInventory Stock Status.'));
233: }
234: break;
235:
236: case 'rebuild_catalog_index':
237: try {
238: Mage::getSingleton('catalog/index')->rebuild();
239: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The catalog index has been rebuilt.'));
240: }
241: catch (Mage_Core_Exception $e) {
242: $this->_getSession()->addError($e->getMessage());
243: }
244: catch (Exception $e) {
245: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while rebuilding the catalog index.'));
246: }
247: break;
248:
249: case 'rebuild_flat_catalog_category':
250: try {
251: Mage::getResourceModel('catalog/category_flat')->rebuild();
252: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The flat catalog category has been rebuilt.'));
253: }
254: catch (Mage_Core_Exception $e) {
255: $this->_getSession()->addError($e->getMessage());
256: }
257: catch (Exception $e) {
258: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while rebuilding the flat catalog category.'));
259: }
260: break;
261:
262: case 'rebuild_flat_catalog_product':
263: try {
264: Mage::getResourceModel('catalog/product_flat_indexer')->rebuild();
265: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__('The Flat Catalog Product was rebuilt'));
266: }
267: catch (Mage_Core_Exception $e) {
268: $this->_getSession()->addError($e->getMessage());
269: }
270: catch (Exception $e) {
271: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while rebuilding the flat product catalog.'));
272: }
273: break;
274:
275: default:
276: break;
277: }
278: }
279:
280: $this->_redirect('*/*');
281: }
282:
283: public function refreshCatalogRewritesAction()
284: {
285: try {
286: Mage::getSingleton('catalog/url')->refreshRewrites();
287: $this->_getSession()->addSuccess(
288: Mage::helper('adminhtml')->__('The catalog rewrites have been refreshed.')
289: );
290: }
291: catch (Mage_Core_Exception $e) {
292: $this->_getSession()->addError($e->getMessage());
293: }
294: catch (Exception $e) {
295: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while refreshing the catalog rewrites.'));
296: }
297:
298: $this->_redirect('*/*');
299: }
300:
301: public function clearImagesCacheAction()
302: {
303: try {
304: Mage::getModel('catalog/product_image')->clearCache();
305: $this->_getSession()->addSuccess(
306: Mage::helper('adminhtml')->__('The image cache was cleared.')
307: );
308: }
309: catch (Mage_Core_Exception $e) {
310: $this->_getSession()->addError($e->getMessage());
311: }
312: catch (Exception $e) {
313: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while clearing the image cache.'));
314: }
315:
316: $this->_redirect('*/*');
317: }
318:
319: public function refreshLayeredNavigationAction()
320: {
321: try {
322: Mage::getSingleton('catalogindex/indexer')->plainReindex();
323: $this->_getSession()->addSuccess(
324: Mage::helper('adminhtml')->__('The Layered Navigation indices were refreshed.')
325: );
326: }
327: catch (Mage_Core_Exception $e) {
328: $this->_getSession()->addError($e->getMessage());
329: }
330: catch (Exception $e) {
331: $this->_getSession()->addException($e, Mage::helper('adminhtml')->__('An error occurred while refreshing the layered navigation indices.'));
332: }
333:
334: $this->_redirect('*/*');
335: }
336:
337: protected function _isAllowed()
338: {
339: return Mage::getSingleton('admin/session')->isAllowed('system/cache');
340: }
341: }
342: