]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Addon.php
Add Comments to Worker Exponent Implementation
[friendica.git] / src / Core / Addon.php
index a721bd67eaba16443a509de64186ea9af594aa87..50247d240f42fbffb1480493273b3416412c59a4 100644 (file)
@@ -6,6 +6,7 @@ namespace Friendica\Core;
 
 use Friendica\Core\Config;
 use Friendica\Database\DBM;
+use Friendica\Core\Worker;
 
 use dba;
 
@@ -185,6 +186,25 @@ class Addon
                dba::close($r);
        }
 
+       /**
+        * @brief Forks a hook.
+        *
+        * Use this function when you want to fork a hook via the worker.
+        *
+        * @param string $name of the hook to call
+        * @param string|array $data to transmit to the callback handler
+        */
+       public static function forkHooks($priority, $name, $data = null)
+       {
+               $a = get_app();
+
+               if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
+                       foreach ($a->hooks[$name] as $hook) {
+                               Worker::add($priority, 'ForkHook', $name, $hook, $data);
+                       }
+               }
+       }
+
        /**
         * @brief Calls a hook.
         *
@@ -208,14 +228,15 @@ class Addon
        /**
         * @brief Calls a single hook.
         *
-        * @param string $name of the hook to call
-        * @param array $hook Hook data
-        * @param string|array &$data to transmit to the callback handler
+        * @param \Friendica\App $a
+        * @param string         $name of the hook to call
+        * @param array          $hook Hook data
+        * @param string|array   &$data to transmit to the callback handler
         */
-       public static function callSingleHook($a, $name, $hook, &$data = null)
+       public static function callSingleHook(\Friendica\App $a, $name, $hook, &$data = null)
        {
                // Don't run a theme's hook if the user isn't using the theme
-               if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false) {
+               if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
                        return;
                }
 
@@ -226,7 +247,7 @@ class Addon
                } else {
                        // remove orphan hooks
                        $condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
-                       dba::delete('hook', $condition);
+                       dba::delete('hook', $condition, ['cascade' => false]);
                }
        }