joomla/joomla-cms — pull request #2947 by garyamort (2014-01-29 18:15:56+00:00)
Title: Config is saved even if cache is broken

Fix for a number of ancient bugs, such as http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=20506

Issue summary:
If caching was disabled but is now enabled, com_config tries to clean the cache of any old data before saving the new config. If it fails to clean the cache[for example, folder permission errors] then this attempt at cleaning the cache will cause com_config to abort before saving the new configuration.

Regardless of whether or not caching is enabled, com_config will attempt to for a clean on it's own cache[$this->cleanCache('_system',0), $this->cleanCache('_system',1) - since Joomla defaults are set to assume file caching this means if either the administrator/cache or the cache folders are not writable these calls fail and the new configuration will not be saved.

Simple fix is to move these 3 attempts to clean the cache from before writeConfigFile to afterwards to ensure the new configuration is saved. In addition, adding error suppression to these calls ensures that a misconfigured cache will not cause com_config to abort.

To reproduce:
On a working installation of Jooml:
Step 1: Enable file caching through system admin
Step 2: Load some pages to create some cache files in the cache folder
Step 3: Disable file caching through system admin, save[not save and close] so the screen remains open
Step 4: from the command line, go to the directory Joomla is installed in and make the cache files read only.:
chmod 600 cache
chmod 600 administrator\cache
Step 5: Enable the file caching again in the system admin[already open from 3], save

Result: Configuration will not save and instead cache error will be displayed

Apply patch for this code to your system
Repeat steps to reproduce problem. Configuration should save.