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_Adminhtml_CacheController extends Mage_Adminhtml_Controller_Action
28: {
29: 30: 31: 32: 33:
34: protected function _getSession()
35: {
36: return Mage::getSingleton('adminhtml/session');
37: }
38:
39: 40: 41:
42: public function indexAction()
43: {
44: $this->_title($this->__('System'))->_title($this->__('Cache Management'));
45:
46: $this->loadLayout()
47: ->_setActiveMenu('system/cache')
48: ->renderLayout();
49: }
50:
51: 52: 53:
54: public function flushAllAction()
55: {
56: Mage::dispatchEvent('adminhtml_cache_flush_all');
57: Mage::app()->getCacheInstance()->flush();
58: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("The cache storage has been flushed."));
59: $this->_redirect('*/*');
60: }
61:
62: 63: 64:
65: public function flushSystemAction()
66: {
67: Mage::app()->cleanCache();
68: Mage::dispatchEvent('adminhtml_cache_flush_system');
69: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("The Magento cache storage has been flushed."));
70: $this->_redirect('*/*');
71: }
72:
73: 74: 75:
76: public function massEnableAction()
77: {
78: $types = $this->getRequest()->getParam('types');
79: $allTypes = Mage::app()->useCache();
80:
81: $updatedTypes = 0;
82: foreach ($types as $code) {
83: if (empty($allTypes[$code])) {
84: $allTypes[$code] = 1;
85: $updatedTypes++;
86: }
87: }
88: if ($updatedTypes > 0) {
89: Mage::app()->saveUseCache($allTypes);
90: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) enabled.", $updatedTypes));
91: }
92: $this->_redirect('*/*');
93: }
94:
95: 96: 97:
98: public function massDisableAction()
99: {
100: $types = $this->getRequest()->getParam('types');
101: $allTypes = Mage::app()->useCache();
102:
103: $updatedTypes = 0;
104: foreach ($types as $code) {
105: if (!empty($allTypes[$code])) {
106: $allTypes[$code] = 0;
107: $updatedTypes++;
108: }
109: $tags = Mage::app()->getCacheInstance()->cleanType($code);
110: }
111: if ($updatedTypes > 0) {
112: Mage::app()->saveUseCache($allTypes);
113: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) disabled.", $updatedTypes));
114: }
115: $this->_redirect('*/*');
116: }
117:
118: 119: 120:
121: public function massRefreshAction()
122: {
123: $types = $this->getRequest()->getParam('types');
124: $updatedTypes = 0;
125: if (!empty($types)) {
126: foreach ($types as $type) {
127: $tags = Mage::app()->getCacheInstance()->cleanType($type);
128: Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $type));
129: $updatedTypes++;
130: }
131: }
132: if ($updatedTypes > 0) {
133: $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) refreshed.", $updatedTypes));
134: }
135: $this->_redirect('*/*');
136: }
137:
138: 139: 140:
141: public function cleanMediaAction()
142: {
143: try {
144: Mage::getModel('core/design_package')->cleanMergedJsCss();
145: Mage::dispatchEvent('clean_media_cache_after');
146: $this->_getSession()->addSuccess(
147: Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleaned.')
148: );
149: }
150: catch (Exception $e) {
151: $this->_getSession()->addException(
152: $e,
153: Mage::helper('adminhtml')->__('An error occurred while clearing the JavaScript/CSS cache.')
154: );
155: }
156: catch (Mage_Core_Exception $e) {
157: $this->_getSession()->addError($e->getMessage());
158: }
159: $this->_redirect('*/*');
160: }
161:
162: 163: 164:
165: public function cleanImagesAction()
166: {
167: try {
168: Mage::getModel('catalog/product_image')->clearCache();
169: Mage::dispatchEvent('clean_catalog_images_cache_after');
170: $this->_getSession()->addSuccess(
171: Mage::helper('adminhtml')->__('The image cache was cleaned.')
172: );
173: }
174: catch (Mage_Core_Exception $e) {
175: $this->_getSession()->addError($e->getMessage());
176: }
177: catch (Exception $e) {
178: $this->_getSession()->addException(
179: $e,
180: Mage::helper('adminhtml')->__('An error occurred while clearing the image cache.')
181: );
182: }
183: $this->_redirect('*/*');
184: }
185:
186: 187: 188: 189: 190:
191: protected function _isAllowed()
192: {
193: return Mage::getSingleton('admin/session')->isAllowed('system/cache');
194: }
195: }
196: