From 056ced75b568ccc85d6dd446f03ab02d10df03d8 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 24 Jul 2013 15:55:40 +0200 Subject: [PATCH] // Fixed double module call --- classes/Hook.php | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/classes/Hook.php b/classes/Hook.php index 069af7942..d3c2898ff 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -315,27 +315,21 @@ class HookCore extends ObjectModel $sql->orderBy('hm.`position`'); - // Store results per hook name - $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $list = array(); - - // Get all available payment module - $payment_modules = array(); + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + foreach ($result as $row) + { + $row['hook'] = strtolower($row['hook']); + if (!isset($list[$row['hook']])) + $list[$row['hook']] = array(); - if ($results) - foreach ($results as $row) - { - $row['hook'] = strtolower($row['hook']); - if (!isset($list[$row['hook']])) - $list[$row['hook']] = array(); - - $list[$row['hook']][] = array( - 'id_hook' => $row['id_hook'], - 'module' => $row['module'], - 'id_module' => $row['id_module'], - 'live_edit' => $row['live_edit'], - ); - } + $list[$row['hook']][] = array( + 'id_hook' => $row['id_hook'], + 'module' => $row['module'], + 'id_module' => $row['id_module'], + 'live_edit' => $row['live_edit'], + ); + } if ($hook_name != 'displayPayment') { Cache::store($cache_id, $list); @@ -353,14 +347,17 @@ class HookCore extends ObjectModel $hook_name = strtolower($hook_name); $return = array(); + $inserted_modules = array(); if (isset($list[$hook_name])) $return = $list[$hook_name]; + foreach ($return as $module) + $inserted_modules[] = $module['id_module']; if (isset($list[$retro_hook_name])) - $return = array_merge($return, $list[$retro_hook_name]); + foreach ($list[$retro_hook_name] as $retro_module_call) + if (!in_array($retro_module_call['id_module'], $inserted_modules)) + $return[] = $retro_module_call; - if (count($return) > 0) - return $return; - return false; + return (count($return) > 0 ? $return : false); } else return $list; @@ -417,7 +414,7 @@ class HookCore extends ObjectModel { $exceptions = $moduleInstance->getExceptions($array['id_hook']); $controller = Dispatcher::getInstance()->getController(); - + if (in_array($controller, $exceptions)) continue; @@ -425,7 +422,7 @@ class HookCore extends ObjectModel $matching_name = array( 'authentication' => 'auth', 'compare' => 'products-comparison', - ); + ); if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) continue; if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee))