<?php
/**
- * @file src/Core/Hook.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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;
}
/**
- * @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.
*
}
/**
- * @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.
*
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]);
}
/**
// 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;
}
}
/**
- * @brief Forks a hook.
+ * Forks a hook.
*
* Use this function when you want to fork a hook via the worker.
*
}
/**
- * @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.
}
/**
- * @brief Calls a single hook.
+ * Calls a single hook.
*
* @param App $a
* @param string $name of the hook to call
} else {
// remove orphan hooks
$condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
- DBA::delete('hook', $condition, ['cascade' => false]);
+ self::delete($condition, ['cascade' => false]);
}
}
return false;
}
+
+ /**
+ * Deletes one or more hook records
+ *
+ * We have to clear the cached routerDispatchData because addons can provide routes
+ *
+ * @param array $condition
+ * @param array $options
+ * @return bool
+ * @throws \Exception
+ */
+ public static function delete(array $condition, array $options = [])
+ {
+ $result = DBA::delete('hook', $condition, $options);
+
+ 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;
+ }
}