From 460f085fd3cd8afb3c468dc5d1eac2af963976a1 Mon Sep 17 00:00:00 2001 From: fSerny Date: Mon, 5 Dec 2011 17:20:40 +0000 Subject: [PATCH] [*] PROJECT - Dynamic hooks in ObjectModel retrieve object in param - Dynamic hooks have been added to AdminController --- classes/AdminController.php | 25 ++++++++++++++++++++++--- classes/ObjectModel.php | 12 ++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/classes/AdminController.php b/classes/AdminController.php index d8205eead..30b467f7d 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -466,10 +466,29 @@ class AdminControllerCore extends Controller $this->processFilter(); if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action)))) - return $this->{'process'.Tools::toCamelCase($this->action)}($token); - else if (method_exists($this, $this->action)) - return call_user_func(array($this, $this->action), $this->boxes); + { + /* Hook Before Action */ + Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this)); + $return = $this->{'process'.Tools::toCamelCase($this->action)}($token); + + /* Hook After Action */ + Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return)); + + return $return; + } + else if (method_exists($this, $this->action)) + { + /* Hook Before Action */ + Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this)); + + $return = call_user_func(array($this, $this->action), $this->boxes); + + /* Hook After Action */ + Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return)); + + return $return; + } } } diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 24ded5b09..5a29dd466 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -229,7 +229,7 @@ abstract class ObjectModelCore throw new PrestashopException('not table or identifier : '.$this->table); /* Hook */ - Hook::exec('actionObject'.get_class($this).'AddBefore'); + Hook::exec('actionObject'.get_class($this).'AddBefore', array('object' => $this)); /* Automatically fill dates */ if ($autodate AND key_exists('date_add', $this)) @@ -285,7 +285,7 @@ abstract class ObjectModelCore } /* Hook */ - Hook::exec('actionObject'.get_class($this).'AddAfter'); + Hook::exec('actionObject'.get_class($this).'AddAfter', array('object' => $this)); return $result; } @@ -301,7 +301,7 @@ abstract class ObjectModelCore throw new PrestashopException('wrong identifier or table:'.$this->identifier.', table: '.$this->table); /* Hook */ - Hook::exec('actionObject'.get_class($this).'UpdateBefore'); + Hook::exec('actionObject'.get_class($this).'UpdateBefore', array('object' => $this)); $this->clearCache(); /* Automatically fill dates */ @@ -360,7 +360,7 @@ abstract class ObjectModelCore } /* Hook */ - Hook::exec('actionObject'.get_class($this).'UpdateAfter'); + Hook::exec('actionObject'.get_class($this).'UpdateAfter', array('object' => $this)); return $result; } @@ -376,7 +376,7 @@ abstract class ObjectModelCore throw new PrestashopException('wrong identifier or table:'.$this->identifier.', table: '.$this->table); /* Hook */ - Hook::exec('actionObject'.get_class($this).'DeleteBefore'); + Hook::exec('actionObject'.get_class($this).'DeleteBefore', array('object' => $this)); $this->clearCache(); @@ -398,7 +398,7 @@ abstract class ObjectModelCore Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->table.'_group_shop` WHERE `'.$this->identifier.'`='.(int)$this->id); /* Hook */ - Hook::exec('actionObject'.get_class($this).'DeleteAfter'); + Hook::exec('actionObject'.get_class($this).'DeleteAfter', array('object' => $this)); return $result; }