diff --git a/administrator/components/com_cache/controller.php b/administrator/components/com_cache/controller.php index 88d2f30e51ec9..2b90a066eb4fe 100644 --- a/administrator/components/com_cache/controller.php +++ b/administrator/components/com_cache/controller.php @@ -121,7 +121,7 @@ public function deleteAll() foreach ($mCache->getAll() as $cache) { - if ((int) $mCache->clean($cache->group) !== 1) + if ($mCache->clean($cache->group) === false) { $app->enqueueMessage(JText::sprintf('COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR', $clientStr . $cache->group), 'error'); $allCleared = false; diff --git a/administrator/components/com_cache/models/cache.php b/administrator/components/com_cache/models/cache.php index a21d33c65e425..bddf4384b4030 100644 --- a/administrator/components/com_cache/models/cache.php +++ b/administrator/components/com_cache/models/cache.php @@ -117,42 +117,55 @@ public function getData() { if (empty($this->_data)) { - $cache = $this->getCache(); - $data = $cache->getAll(); - - if ($data && count($data) > 0) + try { - // Process filter by search term. - if ($search = $this->getState('filter.search')) + $cache = $this->getCache(); + $data = $cache->getAll(); + + if ($data && count($data) > 0) { - foreach ($data as $key => $cacheItem) + // Process filter by search term. + if ($search = $this->getState('filter.search')) { - if (stripos($cacheItem->group, $search) === false) + foreach ($data as $key => $cacheItem) { - unset($data[$key]); - continue; + if (stripos($cacheItem->group, $search) === false) + { + unset($data[$key]); + continue; + } } } - } - // Process ordering. - $listOrder = $this->getState('list.ordering', 'group'); - $listDirn = $this->getState('list.direction', 'ASC'); + // Process ordering. + $listOrder = $this->getState('list.ordering', 'group'); + $listDirn = $this->getState('list.direction', 'ASC'); - $this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true); + $this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true); - // Process pagination. - $limit = (int) $this->getState('list.limit', 25); + // Process pagination. + $limit = (int) $this->getState('list.limit', 25); - if ($limit !== 0) - { - $start = (int) $this->getState('list.start', 0); + if ($limit !== 0) + { + $start = (int) $this->getState('list.start', 0); - return array_slice($this->_data, $start, $limit); + return array_slice($this->_data, $start, $limit); + } } + else + { + $this->_data = array(); + } + } + catch (JCacheExceptionConnecting $exception) + { + $this->setError(JText::_('COM_CACHE_ERROR_CACHE_CONNECTION_FAILED')); + $this->_data = array(); } - else + catch (JCacheExceptionUnsupported $exception) { + $this->setError(JText::_('COM_CACHE_ERROR_CACHE_DRIVER_UNSUPPORTED')); $this->_data = array(); } } @@ -163,7 +176,7 @@ public function getData() /** * Method to get cache instance. * - * @return object + * @return JCacheController */ public function getCache($clientId = null) { @@ -181,9 +194,7 @@ public function getCache($clientId = null) 'cachebase' => (int) $clientId === 1 ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache') ); - $cache = JCache::getInstance('', $options); - - return $cache; + return JCache::getInstance('', $options); } /** @@ -216,7 +227,7 @@ public function getTotal() /** * Method to get a pagination object for the cache. * - * @return integer + * @return JPagination */ public function getPagination() { @@ -238,7 +249,18 @@ public function getPagination() */ public function clean($group = '') { - return $this->getCache()->clean($group); + try + { + return $this->getCache()->clean($group); + } + catch (JCacheExceptionConnecting $exception) + { + return false; + } + catch (JCacheExceptionUnsupported $exception) + { + return false; + } } /** @@ -270,6 +292,17 @@ public function cleanlist($array) */ public function purge() { - return JFactory::getCache('')->gc(); + try + { + return JFactory::getCache('')->gc(); + } + catch (JCacheExceptionConnecting $exception) + { + return false; + } + catch (JCacheExceptionUnsupported $exception) + { + return false; + } } } diff --git a/administrator/language/en-GB/en-GB.com_cache.ini b/administrator/language/en-GB/en-GB.com_cache.ini index 97b5fe930a9f2..651806468029c 100644 --- a/administrator/language/en-GB/en-GB.com_cache.ini +++ b/administrator/language/en-GB/en-GB.com_cache.ini @@ -11,6 +11,8 @@ COM_CACHE_CLEAR_CACHE_ADMIN_TITLE="Maintenance: Clear Cache (Administrator)" COM_CACHE_CLEAR_CACHE_SITE_TITLE="Maintenance: Clear Cache (Site)" COM_CACHE_PURGE_EXPIRED_CACHE="Maintenance: Clear Expired Cache" COM_CACHE_CONFIGURATION="Cache: Options" +COM_CACHE_ERROR_CACHE_CONNECTION_FAILED="Could not connect to the cache store to fetch the cache data." +COM_CACHE_ERROR_CACHE_DRIVER_UNSUPPORTED="Could not read the cache data, the configured cache handler is not supported by this environment." COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_DELETED="The selected cache group(s) have been cleared." COM_CACHE_EXPIRED_ITEMS_HAVE_BEEN_PURGED="Expired cached items have been cleared." COM_CACHE_EXPIRED_ITEMS_DELETE_ERROR="Error clearing cache group(s): %s."