Skip to content

[6.0] Language cache error handling improvement #3678

@jgerman-bot

Description

@jgerman-bot

New language relevant PR in upstream repo: joomla/joomla-cms#46545 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/language/en-GB/lib_joomla.ini b/administrator/language/en-GB/lib_joomla.ini
index f9ea658e0291d..adac9ba169fd2 100644
--- a/administrator/language/en-GB/lib_joomla.ini
+++ b/administrator/language/en-GB/lib_joomla.ini
@@ -689,6 +689,7 @@ JLIB_JS_AJAX_ERROR_TIMEOUT="A timeout has occurred while fetching the JSON data.
 
 JLIB_LANGUAGE_ERROR_CANNOT_LOAD_METADATA="Could not load %s metadata from %s."
 JLIB_LANGUAGE_ERROR_CANNOT_LOAD_METAFILE="Could not load %s language XML file from %s."
+JLIB_LANGUAGE_ERROR_CANNOT_WRITE_CACHE="Unable to write cache file for %s."
 
 JLIB_LOGIN_AUTHORISATION="Your access has been authorised."
 JLIB_LOGIN_DENIED="Your access has been denied."
diff --git a/language/en-GB/lib_joomla.ini b/language/en-GB/lib_joomla.ini
index 0c982bbe4c167..cf596e409c066 100644
--- a/language/en-GB/lib_joomla.ini
+++ b/language/en-GB/lib_joomla.ini
@@ -675,6 +675,7 @@ JLIB_JS_AJAX_ERROR_TIMEOUT="A timeout has occurred while fetching the JSON data.
 
 JLIB_LANGUAGE_ERROR_CANNOT_LOAD_METADATA="Could not load %s metadata from %s."
 JLIB_LANGUAGE_ERROR_CANNOT_LOAD_METAFILE="Could not load %s language XML file from %s."
+JLIB_LANGUAGE_ERROR_CANNOT_WRITE_CACHE="Unable to write cache file for %s."
 
 JLIB_LOGIN_AUTHORISATION="Your access has been authorised."
 JLIB_LOGIN_DENIED="Your access has been denied."
diff --git a/libraries/src/Language/LanguageHelper.php b/libraries/src/Language/LanguageHelper.php
index 0dc660af79dfe..4ea01ea0bfbc1 100644
--- a/libraries/src/Language/LanguageHelper.php
+++ b/libraries/src/Language/LanguageHelper.php
@@ -510,10 +510,22 @@ public static function parseIniFile($fileName, $debug = false)
             $bytesWritten = file_put_contents($cacheFile, $data);
 
             if ($bytesWritten === false || $bytesWritten < \strlen($data)) {
+                if (is_file($cacheFile)) {
+                    File::delete($cacheFile);
+                }
+
                 throw new FilesystemException('Unable to write cache file');
             }
-        } catch (FilesystemException $e) {
-            // We ignore the error, as the file is for caching only.
+        } catch (FilesystemException) {
+            try {
+                Log::add(
+                    Text::sprintf('JLIB_LANGUAGE_ERROR_CANNOT_WRITE_CACHE', str_replace(JPATH_ROOT, '', $cacheFile)),
+                    Log::WARNING,
+                    'language'
+                );
+            } catch (\RuntimeException) {
+                // Ignore logging errors
+            }
         }
 
         return $strings;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions