diff --git a/administrator/components/com_config/model/application.php b/administrator/components/com_config/model/application.php index 8c96c10f1d03d..45d1a383046eb 100644 --- a/administrator/components/com_config/model/application.php +++ b/administrator/components/com_config/model/application.php @@ -279,20 +279,95 @@ public function save($data) $data['caching'] = 0; } - $path = JPATH_SITE . '/cache'; + /* + * Look for a custom cache_path + * First check if a path is given in the submitted data, then check if a path exists in the previous data, otherwise use the default + */ + if ($data['cache_path']) + { + $path = $data['cache_path']; + } + elseif (!$data['cache_path'] && $prev['cache_path']) + { + $path = $prev['cache_path']; + } + else + { + $path = JPATH_SITE . '/cache'; + } // Give a warning if the cache-folder can not be opened if ($data['caching'] > 0 && $data['cache_handler'] == 'file' && @opendir($path) == false) { - JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror'); - $data['caching'] = 0; + $error = true; + + // If a custom path is in use, try using the system default instead of disabling cache + if ($path !== JPATH_SITE . '/cache' && @opendir(JPATH_SITE . '/cache') != false) + { + try + { + JLog::add( + JText::sprintf('COM_CONFIG_ERROR_CUSTOM_CACHE_PATH_NOTWRITABLE_USING_DEFAULT', $path, JPATH_SITE . '/cache'), + JLog::WARNING, + 'jerror' + ); + } + catch (RuntimeException $logException) + { + $app->enqueueMessage( + JText::sprintf('COM_CONFIG_ERROR_CUSTOM_CACHE_PATH_NOTWRITABLE_USING_DEFAULT', $path, JPATH_SITE . '/cache'), + 'warning' + ); + } + + $path = JPATH_SITE . '/cache'; + $error = false; + + $data['cache_path'] = ''; + } + + if ($error) + { + JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror'); + $data['caching'] = 0; + } + } + + // Did the user remove their custom cache path? Don't save the variable to the config + if (empty($data['cache_path'])) + { + unset($data['cache_path']); } - // Clean the cache if disabled but previously enabled. - if (!$data['caching'] && $prev['caching']) + // Clean the cache if disabled but previously enabled or changing cache handlers; these operations use the `$prev` data already in memory + if ((!$data['caching'] && $prev['caching']) || $data['cache_handler'] !== $prev['cache_handler']) { - $cache = JFactory::getCache(); - $cache->clean(); + try + { + JFactory::getCache()->clean(); + } + catch (JCacheExceptionConnecting $exception) + { + try + { + JLog::add(JText::_('COM_CONFIG_ERROR_CACHE_CONNECTION_FAILED'), JLog::WARNING, 'jerror'); + } + catch (RuntimeException $logException) + { + $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CACHE_CONNECTION_FAILED'), 'warning'); + } + } + catch (JCacheExceptionUnsupported $exception) + { + try + { + JLog::add(JText::_('COM_CONFIG_ERROR_CACHE_DRIVER_UNSUPPORTED'), JLog::WARNING, 'jerror'); + } + catch (RuntimeException $logException) + { + $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CACHE_DRIVER_UNSUPPORTED'), 'warning'); + } + } } // Create the new configuration object. diff --git a/administrator/components/com_config/model/form/application.xml b/administrator/components/com_config/model/form/application.xml index d5387811c40d2..094878e68a2b1 100644 --- a/administrator/components/com_config/model/form/application.xml +++ b/administrator/components/com_config/model/form/application.xml @@ -13,6 +13,15 @@ filter="word" /> + +