]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Hook.php
Merge pull request #11015 from MrPetovan/task/10979-frio-time-tooltip
[friendica.git] / src / Core / Hook.php
index b8ad0fb8bd3b7d33399d671c0e111dfaaaf0af77..81c5d882dc1b6688219e4e057e3d2229491c39f9 100644 (file)
@@ -1,7 +1,24 @@
 <?php
 /**
- * @file src/Core/Hook.php
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 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;
+       }
 }