From cdf4931171694ed5b2c4396cda4458342971770b Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Mon, 31 Aug 2026 15:49:48 +0200 Subject: [PATCH] fix: avoid "No clang found" when the clang cache is deleted by a parallel request `rex_clang::checkCache()` checked the cache file with `is_file()` and read it afterwards. If a parallel request cleared the cache in between, the read failed silently, `rex_file::getCache()` returned its empty default and the clang list stayed empty for the whole request - which surfaces as `LogicException: No clang found.` in `getStartId()`, and as silently wrong results in `exists()`/`getAll()`. Read the file first and fall back to a freshly generated cache if the result is empty. `rex_clang_service::generateCache()` now returns the generated data, so the fallback does not have to read the file again and cannot lose the same race. --- redaxo/src/core/lib/clang/clang.php | 10 +++++++--- redaxo/src/core/lib/clang/service.php | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/redaxo/src/core/lib/clang/clang.php b/redaxo/src/core/lib/clang/clang.php index 6e6ee84359..6501aaec8d 100644 --- a/redaxo/src/core/lib/clang/clang.php +++ b/redaxo/src/core/lib/clang/clang.php @@ -243,10 +243,14 @@ private static function checkCache() } $file = rex_path::coreCache('clang.cache'); - if (!is_file($file)) { - rex_clang_service::generateCache(); + $cache = rex_file::getCache($file); + + // deliberately no is_file() check: a parallel cache clear could delete the file between check and read + if (!$cache) { + $cache = rex_clang_service::generateCache(); } - foreach (rex_file::getCache($file) as $id => $data) { + + foreach ($cache as $id => $data) { $clang = new self(); $clang->id = (int) $id; $clang->priority = (int) $data['priority']; diff --git a/redaxo/src/core/lib/clang/service.php b/redaxo/src/core/lib/clang/service.php index a704314e27..ac361ab506 100644 --- a/redaxo/src/core/lib/clang/service.php +++ b/redaxo/src/core/lib/clang/service.php @@ -127,7 +127,7 @@ public static function deleteCLang($id) * Schreibt Spracheigenschaften in die Datei include/clang.php. * * @throws rex_exception - * @return void + * @return array> */ public static function generateCache() { @@ -146,5 +146,7 @@ public static function generateCache() if (!rex_file::putCache($file, $clangs)) { throw new rex_exception('Clang cache file could not be generated'); } + + return $clangs; } }