diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php
index 18b76188a4e..b43d477c885 100644
--- a/dev/skeletons/modMyModule.class.php
+++ b/dev/skeletons/modMyModule.class.php
@@ -93,7 +93,9 @@ class modMyModule extends DolibarrModules
// Constants
// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
- // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
+ // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0)
+ // 2=>array('MAIN_MODULE_MYMODULE_HOOKS','chaine','hookcontext1:hookcontext2','To say: This module manage hooks in hookcontext1 and hookcontext2',1,'current',1)
+ // );
$this->const = array();
// Array to add new pages in new tabs
diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index f332c0c5500..abd23ca85c2 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -436,7 +436,7 @@ class Adherent extends CommonObject
// Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('member_extrafields'));
+ $hookmanager->callHooks(array('memberdao'));
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 30e44201ca1..acf978600a5 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -82,7 +82,7 @@ if ($rowid)
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
-$hookmanager->callHooks(array('member_extrafields'));
+$hookmanager->callHooks(array('membercard'));
/*
@@ -1031,7 +1031,7 @@ if ($action == 'edit')
print '';
print '';
-
+
print '
';
print '';
print ' ';
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 6f33f315b6d..ba39d848325 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -859,10 +859,9 @@ class Commande extends CommonObject
* Load an object from a proposal and create a new order into database
*
* @param Object $object Object source
- * @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK
*/
- function createFromProposal($object,$hookmanager=false)
+ function createFromProposal($object)
{
global $conf,$user,$langs;
@@ -919,13 +918,14 @@ class Commande extends CommonObject
if ($ret > 0)
{
- // Hook of thirdparty module
- if (is_object($hookmanager))
- {
- $parameters=array('objFrom'=>$object);
- $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) $error++;
- }
+ // Actions hooked (by external module)
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+ $hookmanager=new HookManager($this->db);
+ $hookmanager->callHooks(array('orderdao'));
+
+ $parameters=array('objFrom'=>$object);
+ $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook < 0) $error++;
if (! $error)
{
@@ -2222,7 +2222,7 @@ class Commande extends CommonObject
$staticline=new OrderLine($this->db);
$staticline->fetch($rowid);
$this->line->oldline = $staticline;
-
+
// Reorder if fk_parent_line change
if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
{
@@ -2259,7 +2259,7 @@ class Commande extends CommonObject
{
// Reorder if child line
if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
-
+
// Mise a jour info denormalisees
$this->update_price(1);
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 9bcd64fd4e3..5db4b42a54e 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -599,10 +599,9 @@ class Facture extends CommonObject
* Load an object from an order and create a new invoice into database
*
* @param Object $object Object source
- * @param HookManager $hookmanager Hook manager instance
* @return int <0 if KO, 0 if nothing done, 1 if OK
*/
- function createFromOrder($object, $hookmanager=false)
+ function createFromOrder($object)
{
global $conf,$user,$langs;
@@ -660,13 +659,14 @@ class Facture extends CommonObject
if ($ret > 0)
{
- // Hook of thirdparty module
- if (is_object($hookmanager))
- {
- $parameters=array('objFrom'=>$object);
- $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) $error++;
- }
+ // Actions hooked (by external module)
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+ $hookmanager=new HookManager($this->db);
+ $hookmanager->callHooks(array('invoicedao'));
+
+ $parameters=array('objFrom'=>$object);
+ $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
+ if ($reshook < 0) $error++;
if (! $error)
{
@@ -2016,7 +2016,7 @@ class Facture extends CommonObject
$staticline=new FactureLigne($this->db);
$staticline->fetch($rowid);
$this->line->oldline = $staticline;
-
+
// Reorder if fk_parent_line change
if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
{
@@ -2053,7 +2053,7 @@ class Facture extends CommonObject
{
// Reorder if child line
if (! empty($fk_parent_line)) $this->line_order(true,'DESC');
-
+
// Mise a jour info denormalisees au niveau facture
$this->update_price(1);
$this->db->commit();
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 62051b58c37..e3167957336 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -967,7 +967,7 @@ abstract class CommonObject
{
$sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE rowid ='.$rowid;
-
+
dol_syslog(get_class($this)."::getRangOfLine sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
@@ -1010,7 +1010,7 @@ abstract class CommonObject
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
$sql.= ' AND fk_parent_line = '.$fk_parent_line;
-
+
dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
@@ -1031,7 +1031,7 @@ abstract class CommonObject
{
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
-
+
dol_syslog(get_class($this)."::line_max sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
@@ -1771,6 +1771,7 @@ abstract class CommonObject
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
+ *
* @param $action Action code
* @param $seller Object of seller third party
* @param $buyer Object of buyer third party
diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php
index 950a060428e..0750742408f 100755
--- a/htdocs/core/class/hookmanager.class.php
+++ b/htdocs/core/class/hookmanager.class.php
@@ -28,20 +28,20 @@
* \class HookManager
* \brief Class to manage hooks
*/
-
class HookManager
{
var $db;
- var $linkedObjectBlock;
- var $objectid;
+ // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
+ var $contextarray=array();
// Array with instantiated classes
var $hooks=array();
/**
- * Constructeur de la classe
- * @param DB Handler acces base de donnees
+ * Constructor
+ *
+ * @param DoliDB $DB Handler acces base de donnees
*/
function HookManager($DB)
{
@@ -50,27 +50,30 @@ class HookManager
/**
- * Init array this->hooks with instantiated controler
+ * Init array this->hooks with instantiated action controlers.
*
* First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS
- * with value nameofhookkey1:nameofhookkey2:...:nameofhookkeyn.
- * This add into conf->hooks_modules an entrie ('modulename'=>nameofhookkey)
- * Then, when this function is called, an array this->hooks is defined with instance of controler
- * classes that support the hook called
+ * with value 'nameofcontext1:nameofcontext2:...' or 'all' into $this->const of module descriptor file.
+ * This make conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
+ * When this function is called by callHooks(list_of_contexts), an array this->hooks is defined with instance of controler
+ * class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
+ * Then when a hook is executeHook('aMethod'...) is called, the method aMethod found into class will be executed.
*
- * @param arraytype Array list of searched hooks tab/features. For example: 'thirdpartytab', 'thirdparty',...
- * @return int Always 1
+ * @param array $arraytype Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
+ * @return int Always 1
*/
function callHooks($arraytype)
{
global $conf;
- // Test if ther is hooks to manage
+ // Test if there is hooks to manage
if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return;
// For backward compatibility
if (! is_array($arraytype)) $arraytype=array($arraytype);
+ $this->contextarray=array_merge($arraytype,$this->contextarray);
+
$i=0;
foreach($conf->hooks_modules as $module => $hooks)
{
@@ -78,7 +81,7 @@ class HookManager
{
foreach($arraytype as $type)
{
- if (in_array($type,$hooks))
+ if (in_array($type,$hooks)) // We instantiate action class only if hook is required
{
$path = '/'.$module.'/class/';
$actionfile = 'actions_'.$module.'.class.php';
@@ -116,13 +119,14 @@ class HookManager
/**
* Execute hooks (if the were initialized) for the given method
- * @param method Method name to hook ('doActions', 'printSearchForm', ...)
- * @param parameters Array of parameters
- * @param action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
- * @param object Object to use hooks on
- * @param string For doActions,showInputField,showOutputField: Return 0 if we want to keep doing standard actions, >0 if if want to stop standard actions, >0 means KO.
- * For printSearchForm,printLeftBlock: Return HTML string.
- * $this->error or this->errors are also defined with hooks errors.
+ *
+ * @param string $method Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
+ * @param array $parameters Array of parameters
+ * @param Object &$object Object to use hooks on
+ * @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
+ * @return mixed For doActions,showInputField,showOutputField: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO.
+ * For printSearchForm,printLeftBlock: Return HTML string.
+ * $this->error or this->errors are also defined by class called by this function if error.
*/
function executeHooks($method, $parameters=false, &$object='', &$action='')
{
@@ -130,7 +134,8 @@ class HookManager
if (! is_array($this->hooks) || empty($this->hooks)) return '';
- dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action);
+ $parameters['context']=join(':',$this->contextarray);
+ dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
// Loop on each hook
$resaction=0; $resprint='';
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index ed47ad963f6..7804c403b70 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -177,7 +177,7 @@ class FormFile
* @param title Title to show on top of form
* @param buttonlabel Label on submit button
* @param codelang Default language code to use on lang combo box if multilang is enabled
- * @param hooks Object hook of external modules
+ * @param hookmanager Object hookmanager with instance of external modules hook classes
* @return string Output string.
*/
function showdocuments($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$hookmanager=false)
diff --git a/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php b/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php
index 88f8773d35c..374096d4fb0 100755
--- a/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php
+++ b/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php
@@ -85,6 +85,7 @@ class InterfaceWorkflowManager
/**
* Function called when a Dolibarrr business event is done.
* All functions "run_trigger" are triggered if file is inside directory htdocs/includes/triggers
+ *
* @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...)
* @param object Object action is done on
* @param user Object user
@@ -103,15 +104,10 @@ class InterfaceWorkflowManager
if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER))
{
include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
- $order = new Commande($this->db);
-
- // Actions on extra fields (by external module or standard code)
- include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
- $hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('ordercard'));
-
- $ret=$order->createFromProposal($object,$hookmanager);
- if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; }
+ $newobject = new Commande($this->db);
+
+ $ret=$newobject->createFromProposal($object);
+ if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}
@@ -123,15 +119,10 @@ class InterfaceWorkflowManager
if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE))
{
include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
- $invoice = new Facture($this->db);
-
- // Actions on extra fields (by external module or standard code)
- include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
- $hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('invoicecard'));
-
- $ret=$invoice->createFromOrder($object,$hookmanager);
- if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; }
+ $newobject = new Facture($this->db);
+
+ $ret=$newobject->createFromOrder($object);
+ if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; }
return $ret;
}
}
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index c750ff7dfbe..792506f7ad9 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -582,7 +582,7 @@ class Product extends CommonObject
// Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('product'));
+ $hookmanager->callHooks(array('productdao'));
$parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteProduct',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (! empty($hookmanager->error))
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 0d3d0c9869c..439770dd687 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -73,7 +73,7 @@ $result=restrictedArea($user,'produit|service',$value,'product','','',$type, $ob
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
-$hookmanager->callHooks(array('product'));
+$hookmanager->callHooks(array('productcard'));
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 5e3ccc52321..8bbb93c8c18 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -546,7 +546,7 @@ class Societe extends CommonObject
// Actions on extra fields (by external module or standard code)
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('thirdparty_extrafields'));
+ $hookmanager->callHooks(array('thirdpartydao'));
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
@@ -951,7 +951,7 @@ class Societe extends CommonObject
// Additionnal action by hooks
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($this->db);
- $hookmanager->callHooks(array('thirdparty'));
+ $hookmanager->callHooks(array('thirdpartydao'));
$parameters=array(); $action='delete';
$reshook=$hookmanager->executeHooks('deleteThirdparty',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (! empty($hookmanager->error))
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 363f079456e..2a3f2eeb9de 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -71,8 +71,7 @@ $result = restrictedArea($user, 'societe', $socid, '', '', '', '', $objcanvas);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
$hookmanager=new HookManager($db);
-// TODO: Remove callHooks and add page into executeHooks
-$hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields'));
+$hookmanager->callHooks(array('thirdpartycard'));
/*