From 25132cd75ebc929a3756d515ffc7c305106238a3 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Sat, 11 May 2024 19:04:47 +0300 Subject: [PATCH] Invalidating routes cache on options change (tags, favorite and blog URLs may be changed). --- _admin/options.php | 15 ++++++++++++--- _include/src/Model/ExtensionCache.php | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/_admin/options.php b/_admin/options.php index 93463f49..db5242b2 100644 --- a/_admin/options.php +++ b/_admin/options.php @@ -199,7 +199,8 @@ function s2_save_options ($opt) /** @var DbLayer $s2_db */ $s2_db = \Container::get(DbLayer::class); - $return = array(); + $return = []; + $hasChanged = false; ($hook = s2_hook('fn_save_options_start')) ? eval($hook) : null; foreach ($s2_const_types as $name => $type) { @@ -218,16 +219,24 @@ function s2_save_options ($opt) ($hook = s2_hook('fn_save_options_loop')) ? eval($hook) : null; if (constant($name) !== $value) { - $query = array( + $hasChanged = true; + $query = [ 'UPDATE' => 'config', 'SET' => 'value = \''.$s2_db->escape($value).'\'', 'WHERE' => 'name = \''.$s2_db->escape($name).'\'' - ); + ]; ($hook = s2_hook('fn_save_options_loop_pre_update_qr')) ? eval($hook) : null; $s2_db->buildAndQuery($query); } } + if ($hasChanged) { + // URL settings for tags and favorite page may be changed + /** @var \S2\Cms\Model\ExtensionCache $extensionCache */ + $extensionCache = \Container::get(\S2\Cms\Model\ExtensionCache::class); + $extensionCache->clearRoutesCache(); + } + $style = preg_replace('#[\.\\\/]#', '', $opt['style']); if (!file_exists(S2_ROOT.'_styles/'.$style.'/'.$style.'.php')) { $return[] = $lang_admin_opt['Invalid style']; diff --git a/_include/src/Model/ExtensionCache.php b/_include/src/Model/ExtensionCache.php index 0ec4440a..383c0537 100644 --- a/_include/src/Model/ExtensionCache.php +++ b/_include/src/Model/ExtensionCache.php @@ -157,6 +157,11 @@ public function getHookNames(): array return $hookNames; } + public function clearRoutesCache(): void + { + @unlink($this->getCachedRoutesFilename()); + } + public function getCachedRoutesFilename(): string { return S2_CACHE_DIR . 'cache_routes.php';