X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FHook.php;h=81c5d882dc1b6688219e4e057e3d2229491c39f9;hb=2ab0d06996410f68cf501e6e2014bf4829b121ae;hp=b8ad0fb8bd3b7d33399d671c0e111dfaaaf0af77;hpb=03038e7a3bb74bdab497d26b7f829a5c3036d1c2;p=friendica.git diff --git a/src/Core/Hook.php b/src/Core/Hook.php index b8ad0fb8bd..81c5d882dc 100644 --- a/src/Core/Hook.php +++ b/src/Core/Hook.php @@ -1,7 +1,24 @@ . + * */ + namespace Friendica\Core; use Friendica\App; @@ -45,7 +62,7 @@ class Hook } /** - * @brief Adds a new hook to the hooks array. + * Adds a new hook to the hooks array. * * This function is meant to be called by modules on each page load as it works after loadHooks has been called. * @@ -62,7 +79,7 @@ class Hook } /** - * @brief Registers a hook. + * Registers a hook. * * This function is meant to be called once when an addon is enabled for example as it doesn't add to the current hooks. * @@ -82,9 +99,7 @@ class Hook return true; } - $result = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]); - - return $result; + return self::insert(['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]); } /** @@ -102,10 +117,10 @@ class Hook // This here is only needed for fixing a problem that existed on the develop branch $condition = ['hook' => $hook, 'file' => $file, 'function' => $function]; - DBA::delete('hook', $condition); + self::delete($condition); $condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function]; - $result = DBA::delete('hook', $condition); + $result = self::delete($condition); return $result; } @@ -127,7 +142,7 @@ class Hook } /** - * @brief Forks a hook. + * Forks a hook. * * Use this function when you want to fork a hook via the worker. * @@ -162,7 +177,7 @@ class Hook } /** - * @brief Calls a hook. + * Calls a hook. * * Use this function when you want to be able to allow a hook to manipulate * the provided data. @@ -181,7 +196,7 @@ class Hook } /** - * @brief Calls a single hook. + * Calls a single hook. * * @param App $a * @param string $name of the hook to call @@ -203,7 +218,7 @@ class Hook } else { // remove orphan hooks $condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]]; - DBA::delete('hook', $condition, ['cascade' => false]); + self::delete($condition); } } @@ -228,4 +243,44 @@ class Hook return false; } + + /** + * Deletes one or more hook records + * + * We have to clear the cached routerDispatchData because addons can provide routes + * + * @param array $condition + * @return bool + * @throws \Exception + */ + public static function delete(array $condition) + { + $result = DBA::delete('hook', $condition); + + if ($result) { + DI::cache()->delete('routerDispatchData'); + } + + return $result; + } + + /** + * Inserts a hook record + * + * We have to clear the cached routerDispatchData because addons can provide routes + * + * @param array $condition + * @return bool + * @throws \Exception + */ + private static function insert(array $condition) + { + $result = DBA::insert('hook', $condition); + + if ($result) { + DI::cache()->delete('routerDispatchData'); + } + + return $result; + } }