From 2ddd03f5975c43ff497c3dfdf491262fd519c1bb Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 27 Apr 2016 22:44:06 -0700 Subject: provide a Hook method to unregister all hooks with a given filespec component. This will be useful in upgrading plugins to use new interfaces, as you won't have to individually unregister hook declarations that you are no longer using in the code. --- Zotlabs/Extend/Hook.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Extend/Hook.php b/Zotlabs/Extend/Hook.php index edfacfa3b..d95defc43 100644 --- a/Zotlabs/Extend/Hook.php +++ b/Zotlabs/Extend/Hook.php @@ -20,6 +20,15 @@ class Hook { if($r) return true; + // To aid in upgrade and transition, remove old settings for any registered hooks that match in all respects except + // for priority or hook_version + + $r = q("DELETE FROM `hook` where `hook` = '%s' and `file` = '%s' and `function` = '%s'", + dbesc($hook), + dbesc($file), + dbesc($function), + ); + $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`, `hook_version`) VALUES ( '%s', '%s', '%s', %d, %d )", dbesc($hook), dbesc($file), @@ -46,6 +55,18 @@ class Hook { return $r; } + // unregister all hooks with this file component. + // Useful for addon upgrades where you want to clean out old interfaces. + + static public function unregister_by_file($file) { + + $r = q("DELETE FROM hook WHERE `file` = '%s' ", + dbesc($file), + ); + + return $r; + } + /** * @brief Inserts a hook into a page request. -- cgit v1.2.3