From 4145d9eb3c1fd91aa4638b79120246349dcbd44c Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 11 Apr 2026 17:49:22 +0200 Subject: [PATCH] Fix: Clear hooks on plugin uninstall Fixes error with gesior-shop-system clear-cache.php being called, despite it's removed --- system/src/Hooks.php | 20 ++++++++++++++++++++ system/src/Plugins.php | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/system/src/Hooks.php b/system/src/Hooks.php index 8dac8eda..75ad0fe4 100644 --- a/system/src/Hooks.php +++ b/system/src/Hooks.php @@ -14,6 +14,26 @@ class Hooks self::$_hooks[$hook->type()][] = $hook; } + public function unregister($name, $type, $file): void + { + if (is_string($type)) { + $type = constant($type); + } + + if(!isset(self::$_hooks[$type])) { + return; + } + + foreach(self::$_hooks[$type] as $id => $hook) { + if($name == $hook->name() + && $type == $hook->type() + && $file == $hook->file() + ) { + unset(self::$_hooks[$type][$id]); + } + } + } + public function trigger($type, $params = []): bool { $ret = true; diff --git a/system/src/Plugins.php b/system/src/Plugins.php index c6651679..6a88fcab 100644 --- a/system/src/Plugins.php +++ b/system/src/Plugins.php @@ -868,6 +868,11 @@ class Plugins { } } + global $hooks; + foreach($plugin_info['hooks'] ?? [] as $name => $info) { + $hooks->unregister($name, $info['type'], $info['file']); + } + clearCache(); return true; }