@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public static function getInstance() |
| 45 | 45 | { |
| 46 | - if (null === static::$instance) { |
|
| 47 | - static::$instance = new static(); |
|
| 48 | - } |
|
| 46 | + if (null === static::$instance) { |
|
| 47 | + static::$instance = new static(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return static::$instance; |
|
| 50 | + return static::$instance; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::get() |
| 56 | 56 | */ |
| 57 | 57 | public function get($hook_function, $hook_context = null) { |
| 58 | - return new Hook($hook_function, $hook_context); |
|
| 58 | + return new Hook($hook_function, $hook_context); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -73,20 +73,20 @@ discard block |
||
| 73 | 73 | public function getPossibleHooks() { |
| 74 | 74 | static $hooks=null; |
| 75 | 75 | if ($hooks === null) { |
| 76 | - $hooks = array(); |
|
| 76 | + $hooks = array(); |
|
| 77 | 77 | |
| 78 | - // Cannot use the same logic as the core Module loading, |
|
| 79 | - // as this forces a new include of the module.php file. |
|
| 80 | - // This causes issue when classes are defined in this file. |
|
| 81 | - // Cannot use Module::getActiveModules as well, as this is private. |
|
| 82 | - $module_names = Database::prepare( |
|
| 83 | - 'SELECT SQL_CACHE module_name FROM `##module`' |
|
| 84 | - )->fetchOneColumn(); |
|
| 78 | + // Cannot use the same logic as the core Module loading, |
|
| 79 | + // as this forces a new include of the module.php file. |
|
| 80 | + // This causes issue when classes are defined in this file. |
|
| 81 | + // Cannot use Module::getActiveModules as well, as this is private. |
|
| 82 | + $module_names = Database::prepare( |
|
| 83 | + 'SELECT SQL_CACHE module_name FROM `##module`' |
|
| 84 | + )->fetchOneColumn(); |
|
| 85 | 85 | |
| 86 | - foreach($module_names as $module_name) { |
|
| 87 | - $module = Module::getModuleByName($module_name); |
|
| 86 | + foreach($module_names as $module_name) { |
|
| 87 | + $module = Module::getModuleByName($module_name); |
|
| 88 | 88 | |
| 89 | - if($module instanceof HookSubscriberInterface){ |
|
| 89 | + if($module instanceof HookSubscriberInterface){ |
|
| 90 | 90 | $subscribedhooks = $module->getSubscribedHooks(); |
| 91 | 91 | if(is_array($subscribedhooks)){ |
| 92 | 92 | foreach($subscribedhooks as $key => $value){ |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | return $hooks; |
@@ -153,33 +153,33 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function updateHooks() { |
| 155 | 155 | |
| 156 | - if(Auth::isAdmin()){ |
|
| 157 | - $ihooks = self::getInstalledHooks(); |
|
| 158 | - $phooks = self::getPossibleHooks(); |
|
| 156 | + if(Auth::isAdmin()){ |
|
| 157 | + $ihooks = self::getInstalledHooks(); |
|
| 158 | + $phooks = self::getPossibleHooks(); |
|
| 159 | 159 | |
| 160 | - // Insert hooks not existing yet in the DB |
|
| 161 | - if($phooks !== null){ |
|
| 162 | - foreach($phooks as $phook => $priority){ |
|
| 163 | - $array_hook = explode('#', $phook); |
|
| 164 | - if($ihooks === null || !array_key_exists($phook, $ihooks)){ |
|
| 165 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
| 166 | - $chook->subscribe($array_hook[0]); |
|
| 167 | - $chook->setPriority($array_hook[0], $priority); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 160 | + // Insert hooks not existing yet in the DB |
|
| 161 | + if($phooks !== null){ |
|
| 162 | + foreach($phooks as $phook => $priority){ |
|
| 163 | + $array_hook = explode('#', $phook); |
|
| 164 | + if($ihooks === null || !array_key_exists($phook, $ihooks)){ |
|
| 165 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
| 166 | + $chook->subscribe($array_hook[0]); |
|
| 167 | + $chook->setPriority($array_hook[0], $priority); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - //Remove hooks not existing any more in the file system |
|
| 173 | - if($ihooks !== null){ |
|
| 174 | - foreach(array_keys($ihooks) as $ihook){ |
|
| 175 | - $array_hook = explode('#', $ihook); |
|
| 176 | - if($phooks === null || !array_key_exists($ihook, $phooks)){ |
|
| 177 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
| 178 | - $chook->remove($array_hook[0]); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 172 | + //Remove hooks not existing any more in the file system |
|
| 173 | + if($ihooks !== null){ |
|
| 174 | + foreach(array_keys($ihooks) as $ihook){ |
|
| 175 | + $array_hook = explode('#', $ihook); |
|
| 176 | + if($phooks === null || !array_key_exists($ihook, $phooks)){ |
|
| 177 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
| 178 | + $chook->remove($array_hook[0]); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | } |
| 186 | 186 | \ No newline at end of file |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getPossibleHooks() |
| 72 | 72 | */ |
| 73 | 73 | public function getPossibleHooks() { |
| 74 | - static $hooks=null; |
|
| 74 | + static $hooks = null; |
|
| 75 | 75 | if ($hooks === null) { |
| 76 | 76 | $hooks = array(); |
| 77 | 77 | |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | 'SELECT SQL_CACHE module_name FROM `##module`' |
| 84 | 84 | )->fetchOneColumn(); |
| 85 | 85 | |
| 86 | - foreach($module_names as $module_name) { |
|
| 86 | + foreach ($module_names as $module_name) { |
|
| 87 | 87 | $module = Module::getModuleByName($module_name); |
| 88 | 88 | |
| 89 | - if($module instanceof HookSubscriberInterface){ |
|
| 89 | + if ($module instanceof HookSubscriberInterface) { |
|
| 90 | 90 | $subscribedhooks = $module->getSubscribedHooks(); |
| 91 | - if(is_array($subscribedhooks)){ |
|
| 92 | - foreach($subscribedhooks as $key => $value){ |
|
| 93 | - if(is_int($key)) { |
|
| 91 | + if (is_array($subscribedhooks)) { |
|
| 92 | + foreach ($subscribedhooks as $key => $value) { |
|
| 93 | + if (is_int($key)) { |
|
| 94 | 94 | $hook_item = $value; |
| 95 | 95 | $priority = self::DEFAULT_PRIORITY; |
| 96 | 96 | } |
| 97 | - else{ |
|
| 97 | + else { |
|
| 98 | 98 | $hook_item = explode('#', $key, 2); |
| 99 | 99 | $priority = $value; |
| 100 | 100 | } |
| 101 | - if($hook_item && count($hook_item) == 2){ |
|
| 101 | + if ($hook_item && count($hook_item) == 2) { |
|
| 102 | 102 | $hook_func = $hook_item[0]; |
| 103 | 103 | $hook_cont = $hook_item[1]; |
| 104 | 104 | } |
| 105 | - else{ |
|
| 105 | + else { |
|
| 106 | 106 | $hook_func = $hook_item[0]; |
| 107 | 107 | $hook_cont = 'all'; |
| 108 | 108 | } |
| 109 | - if(method_exists($module, $hook_func)){ |
|
| 110 | - $hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont]=$priority; |
|
| 109 | + if (method_exists($module, $hook_func)) { |
|
| 110 | + $hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont] = $priority; |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | * {@inheritDoc} |
| 122 | 122 | * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getRawInstalledHooks() |
| 123 | 123 | */ |
| 124 | - public function getRawInstalledHooks(){ |
|
| 125 | - if(self::isModuleOperational()){ |
|
| 124 | + public function getRawInstalledHooks() { |
|
| 125 | + if (self::isModuleOperational()) { |
|
| 126 | 126 | return Database::prepare( |
| 127 | 127 | "SELECT majh_id AS id, majh_module_name AS module, majh_hook_function AS hook, majh_hook_context as context, majh_module_priority AS priority, majh_status AS status". |
| 128 | 128 | " FROM `##maj_hooks`". |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | * {@inheritDoc} |
| 137 | 137 | * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getInstalledHooks() |
| 138 | 138 | */ |
| 139 | - public function getInstalledHooks(){ |
|
| 140 | - static $installedhooks =null; |
|
| 141 | - if($installedhooks===null){ |
|
| 142 | - $dbhooks=self::getRawInstalledHooks(); |
|
| 143 | - foreach($dbhooks as $dbhook){ |
|
| 139 | + public function getInstalledHooks() { |
|
| 140 | + static $installedhooks = null; |
|
| 141 | + if ($installedhooks === null) { |
|
| 142 | + $dbhooks = self::getRawInstalledHooks(); |
|
| 143 | + foreach ($dbhooks as $dbhook) { |
|
| 144 | 144 | $installedhooks[($dbhook->module).'#'.($dbhook->hook).'#'.($dbhook->context)] = array('id' => $dbhook->id, 'status' => $dbhook->status, 'priority' => $dbhook->priority); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -153,15 +153,15 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function updateHooks() { |
| 155 | 155 | |
| 156 | - if(Auth::isAdmin()){ |
|
| 156 | + if (Auth::isAdmin()) { |
|
| 157 | 157 | $ihooks = self::getInstalledHooks(); |
| 158 | 158 | $phooks = self::getPossibleHooks(); |
| 159 | 159 | |
| 160 | 160 | // Insert hooks not existing yet in the DB |
| 161 | - if($phooks !== null){ |
|
| 162 | - foreach($phooks as $phook => $priority){ |
|
| 161 | + if ($phooks !== null) { |
|
| 162 | + foreach ($phooks as $phook => $priority) { |
|
| 163 | 163 | $array_hook = explode('#', $phook); |
| 164 | - if($ihooks === null || !array_key_exists($phook, $ihooks)){ |
|
| 164 | + if ($ihooks === null || !array_key_exists($phook, $ihooks)) { |
|
| 165 | 165 | $chook = new Hook($array_hook[1], $array_hook[2]); |
| 166 | 166 | $chook->subscribe($array_hook[0]); |
| 167 | 167 | $chook->setPriority($array_hook[0], $priority); |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | //Remove hooks not existing any more in the file system |
| 173 | - if($ihooks !== null){ |
|
| 174 | - foreach(array_keys($ihooks) as $ihook){ |
|
| 173 | + if ($ihooks !== null) { |
|
| 174 | + foreach (array_keys($ihooks) as $ihook) { |
|
| 175 | 175 | $array_hook = explode('#', $ihook); |
| 176 | - if($phooks === null || !array_key_exists($ihook, $phooks)){ |
|
| 176 | + if ($phooks === null || !array_key_exists($ihook, $phooks)) { |
|
| 177 | 177 | $chook = new Hook($array_hook[1], $array_hook[2]); |
| 178 | 178 | $chook->remove($array_hook[0]); |
| 179 | 179 | } |
@@ -93,16 +93,14 @@ |
||
| 93 | 93 | if(is_int($key)) { |
| 94 | 94 | $hook_item = $value; |
| 95 | 95 | $priority = self::DEFAULT_PRIORITY; |
| 96 | - } |
|
| 97 | - else{ |
|
| 96 | + } else{ |
|
| 98 | 97 | $hook_item = explode('#', $key, 2); |
| 99 | 98 | $priority = $value; |
| 100 | 99 | } |
| 101 | 100 | if($hook_item && count($hook_item) == 2){ |
| 102 | 101 | $hook_func = $hook_item[0]; |
| 103 | 102 | $hook_cont = $hook_item[1]; |
| 104 | - } |
|
| 105 | - else{ |
|
| 103 | + } else{ |
|
| 106 | 104 | $hook_func = $hook_item[0]; |
| 107 | 105 | $hook_cont = 'all'; |
| 108 | 106 | } |