// same for unregister hook

This commit is contained in:
Rémi Gaillard
2013-07-01 16:30:53 +02:00
parent 09359d011f
commit c5fc26ed0b
5 changed files with 44 additions and 2 deletions

View File

@@ -128,6 +128,22 @@ class HookCore extends ObjectModel
return Cache::retrieve($cache_id);
}
/**
* Return hook ID from name
*/
public static function getNameById($hook_id)
{
$cache_id = 'hook_namebyid_'.$hook_id;
if (!Cache::isStored($cache_id))
Cache::store($cache_id, Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'hook`
WHERE `id_hook` = '.(int)$hook_id)
);
return Cache::retrieve($cache_id);
}
/**
* Get list of hook alias
*

View File

@@ -731,11 +731,16 @@ abstract class ModuleCore
// Get hook id if a name is given as argument
if (!is_numeric($hook_id))
{
$hook_name = (int)$hook_id;
// Retrocompatibility
$hook_id = Hook::getIdByName($hook_id);
if (!$hook_id)
return false;
}
else
$hook_name = Hook::getNameById((int)$hook_id);
Hook::exec('actionModuleUnRegisterHookBefore', array('object' => $this, 'hook_name' => $hook_name));
// Unregister module on hook by id
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module`
@@ -746,6 +751,8 @@ abstract class ModuleCore
// Clean modules position
$this->cleanPositions($hook_id, $shop_list);
Hook::exec('actionModuleUnRegisterHookAfter', array('object' => $this, 'hook_name' => $hook_name));
return $result;
}

View File

@@ -17,3 +17,5 @@ CHANGE `module_name` `module_name` VARCHAR(64) NULL DEFAULT NULL;
/* PHP:fix_download_product_feature_active(); */;
/* PHP:add_module_to_hook(blockmyaccount, actionModuleRegisterHookAfter); */;
/* PHP:add_module_to_hook(blockmyaccountfooter, actionModuleRegisterHookAfter); */;
/* PHP:add_module_to_hook(blockmyaccount, actionModuleUnRegisterHookAfter); */;
/* PHP:add_module_to_hook(blockmyaccountfooter, actionModuleUnRegisterHookAfter); */;

View File

@@ -49,7 +49,8 @@ class BlockMyAccount extends Module
|| !parent::install()
|| !$this->registerHook('displayLeftColumn')
|| !$this->registerHook('displayHeader')
|| !$this->registerHook('actionModuleRegisterHookAfter'))
|| !$this->registerHook('actionModuleRegisterHookAfter')
|| !$this->registerHook('actionModuleUnRegisterUnHookAfter'))
return false;
return true;
}
@@ -59,6 +60,11 @@ class BlockMyAccount extends Module
return (parent::uninstall() && $this->removeMyAccountBlockHook());
}
public function hookActionUnModuleRegisterHookAfter($params)
{
return $this->hookActionModuleRegisterHookAfter($params);
}
public function hookActionModuleRegisterHookAfter($params)
{
if ($params['hook_name'] == 'displayMyAccountBlock')

View File

@@ -45,11 +45,22 @@ class Blockmyaccountfooter extends Module
public function install()
{
if (!$this->addMyAccountBlockHook() || !parent::install() || !$this->registerHook('footer') || !$this->registerHook('header') || !$this->registerHook('actionModuleRegisterHookAfter'))
if (!$this->addMyAccountBlockHook()
|| !parent::install()
|| !$this->registerHook('footer')
|| !$this->registerHook('header')
|| !$this->registerHook('actionModuleRegisterHookAfter')
|| !$this->registerHook('actionModuleUnRegisterHookAfter')
)
return false;
return true;
}
public function hookActionUnModuleRegisterHookAfter($params)
{
return $this->hookActionModuleRegisterHookAfter($params);
}
public function uninstall()
{
return parent::uninstall() && $this->removeMyAccountBlockHook();