From c71112d94e03d2370b8ebf67a2fca15e4db8f109 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 22:41:20 +0200 Subject: [PATCH] Invalidate watermark cache on rule changes --- tools/watermark_settings.inc.php | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/watermark_settings.inc.php b/tools/watermark_settings.inc.php index cfa2948..4e29868 100644 --- a/tools/watermark_settings.inc.php +++ b/tools/watermark_settings.inc.php @@ -4,6 +4,59 @@ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); } +function bratonien_tools_watermark_cache_dir() +{ + return PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.'bratonien-watermark'; +} + +function bratonien_tools_remove_tree($path) +{ + $path = rtrim((string)$path, DIRECTORY_SEPARATOR); + if ($path === '' || !file_exists($path)) return; + + if (is_file($path) || is_link($path)) + { + @unlink($path); + return; + } + + foreach (scandir($path) ?: array() as $entry) + { + if ($entry === '.' || $entry === '..') continue; + bratonien_tools_remove_tree($path.DIRECTORY_SEPARATOR.$entry); + } + @rmdir($path); +} + +function bratonien_tools_clear_watermark_cache() +{ + $dir = bratonien_tools_watermark_cache_dir(); + $derivative_root = realpath(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR); + $parent = realpath(dirname($dir)); + + if ($derivative_root === false || $parent === false || $parent !== $derivative_root) + { + throw new RuntimeException('Wasserzeichen-Cachepfad ist ungueltig.'); + } + + if (is_dir($dir)) + { + bratonien_tools_remove_tree($dir); + } +} + +function bratonien_tools_watermark_cache_upgrade() +{ + $version = '0.9.7.13'; + if ((string)conf_get_param('bratonien_watermark_cache_version', '') === $version) + { + return; + } + + bratonien_tools_clear_watermark_cache(); + conf_update_param('bratonien_watermark_cache_version', $version); +} + function bratonien_tools_get_watermark_defaults() { $defaults = conf_get_param('bratonien_watermark_defaults', null); @@ -40,6 +93,7 @@ function bratonien_tools_save_watermark_defaults() ); conf_update_param('bratonien_watermark_defaults', json_encode($config)); + bratonien_tools_clear_watermark_cache(); return array('message'=>'Globale Wasserzeichenregeln gespeichert.'); }