/** * Manage updates sent from the AdminConfig@index form. */ protected function update() { if (Auth::isAdmin()) { $ihooks = HookProvider::getInstance()->getInstalledHooks(); $module_names = Database::prepare("SELECT module_name FROM `##module` WHERE status='disabled'")->fetchOneColumn(); if ($ihooks !== null) { foreach ($ihooks as $ihook => $params) { if (Filter::post('hook-' . $params['id']) === 'yes') { $array_hook = explode('#', $ihook); //Update status $new_status = Filter::postBool('status-' . $params['id']); if (in_array($array_hook[0], $module_names)) { $new_status = false; } $previous_status = $params['status']; if ($new_status !== null) { $new_status = $new_status ? 'enabled' : 'disabled'; if ($new_status != $previous_status) { $chook = new Hook($array_hook[1], $array_hook[2]); switch ($new_status) { case 'enabled': $chook->enable($array_hook[0]); break; case 'disabled': $chook->disable($array_hook[0]); break; default: break; } } } //Update priority $new_priority = Filter::postInteger("moduleorder-{$params['id']}"); $previous_priority = $params['priority']; if ($new_priority !== null) { if ($new_priority != $previous_priority) { $chook = new Hook($array_hook[1], $array_hook[2]); $chook->setPriority($array_hook[0], $new_priority); } } } } } } }
/** * {@inheritDoc} * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::updateHooks() */ public function updateHooks() { if (Auth::isAdmin()) { $ihooks = self::getInstalledHooks(); $phooks = self::getPossibleHooks(); // Insert hooks not existing yet in the DB if ($phooks !== null) { foreach ($phooks as $phook => $priority) { $array_hook = explode('#', $phook); if ($ihooks === null || !array_key_exists($phook, $ihooks)) { $chook = new Hook($array_hook[1], $array_hook[2]); $chook->subscribe($array_hook[0]); $chook->setPriority($array_hook[0], $priority); } } } //Remove hooks not existing any more in the file system if ($ihooks !== null) { foreach (array_keys($ihooks) as $ihook) { $array_hook = explode('#', $ihook); if ($phooks === null || !array_key_exists($ihook, $phooks)) { $chook = new Hook($array_hook[1], $array_hook[2]); $chook->remove($array_hook[0]); } } } } }