diff options
author | redmatrix <git@macgirvin.com> | 2016-04-27 22:44:06 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-04-27 22:44:06 -0700 |
commit | 2ddd03f5975c43ff497c3dfdf491262fd519c1bb (patch) | |
tree | 3fdb4822d56e30f8a6859b34790ef6c9fafac083 | |
parent | bdef71bda0cbd148e57181275339ae88df9c12fe (diff) | |
download | volse-hubzilla-2ddd03f5975c43ff497c3dfdf491262fd519c1bb.tar.gz volse-hubzilla-2ddd03f5975c43ff497c3dfdf491262fd519c1bb.tar.bz2 volse-hubzilla-2ddd03f5975c43ff497c3dfdf491262fd519c1bb.zip |
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.
-rw-r--r-- | Zotlabs/Extend/Hook.php | 21 |
1 files changed, 21 insertions, 0 deletions
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. |