/** * Clear cache */ public function clearCacheAction() { // get a cache form $cacheForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Application\\Form\\ApplicationClearCache'); $request = $this->getRequest(); // validate the form if ($request->isPost()) { // fill the form with received values $cacheForm->getForm()->setData($request->getPost(), false); // check the form validation if ($cacheForm->getForm()->isValid()) { if (null != ($caches = $cacheForm->getForm()->getData()['cache'])) { // clear selected caches foreach ($caches as $cache) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $result; } $clearResult = false; switch ($cache) { case self::CACHE_STATIC: $clearResult = CacheUtility::clearStaticCache(); break; case self::CACHE_DYNAMIC: $clearResult = CacheUtility::clearDynamicCache(); break; case self::CACHE_CONFIG: $clearResult = CacheUtility::clearConfigCache(); break; case self::CACHE_JS: $clearResult = CacheUtility::clearJsCache(); break; case self::CACHE_CSS: $clearResult = CacheUtility::clearCssCache(); break; } if (false === $clearResult) { $this->flashMessenger()->setNamespace('error')->addMessage(sprintf($this->getTranslator()->translate('Error clearing caches'), $cache)); break; } } if (true === $clearResult) { ApplicationEvent::fireClearCacheEvent($cache); $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('Selected caches have been cleared')); } return $this->redirectTo('settings-administration', 'clear-cache'); } } } return new ViewModel(['cacheForm' => $cacheForm->getForm()]); }