Fix: Avoid duplicate hooks
This commit is contained in:
parent
d60bb77fea
commit
5f8fc30121
@ -37,7 +37,7 @@ class HookManager
|
||||
|
||||
// Array with instantiated classes
|
||||
var $hooks=array();
|
||||
|
||||
|
||||
// Array result
|
||||
var $resArray=array();
|
||||
|
||||
@ -75,7 +75,7 @@ class HookManager
|
||||
// For backward compatibility
|
||||
if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
|
||||
|
||||
$this->contextarray=array_merge($arraycontext,$this->contextarray); // All contexts are concatenated
|
||||
$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray)); // All contexts are concatenated
|
||||
|
||||
foreach($conf->hooks_modules as $module => $hooks)
|
||||
{
|
||||
@ -108,7 +108,7 @@ class HookManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute hooks (if the were initialized) for the given method
|
||||
* Execute hooks (if they were initialized) for the given method
|
||||
*
|
||||
* @param string $method Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...)
|
||||
* @param array $parameters Array of parameters
|
||||
@ -127,23 +127,28 @@ class HookManager
|
||||
$parameters['context']=join(':',$this->contextarray);
|
||||
dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
|
||||
|
||||
// Loop on each hook
|
||||
// Loop on each hook to qualify modules that declared context
|
||||
$modulealreadyexecuted=array();
|
||||
$resaction=0; $resprint='';
|
||||
foreach($this->hooks as $modules)
|
||||
foreach($this->hooks as $modules) // this->hooks is an array with context as key and value is an array of modules that handle this context
|
||||
{
|
||||
if (! empty($modules))
|
||||
{
|
||||
foreach($modules as $actioninstance)
|
||||
foreach($modules as $module => $actionclassinstance)
|
||||
{
|
||||
// test to avoid to run twice a hook, when a module implements several active contexts
|
||||
if (in_array($module,$modulealreadyexecuted)) continue;
|
||||
$modulealreadyexecuted[$module]=$module;
|
||||
|
||||
$var=!$var;
|
||||
|
||||
// Hooks that return int
|
||||
if (($method == 'doActions' || $method == 'formObjectOptions') && method_exists($actioninstance,$method))
|
||||
if (($method == 'doActions' || $method == 'formObjectOptions') && method_exists($actionclassinstance,$method))
|
||||
{
|
||||
$resaction+=$actioninstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
|
||||
if ($resaction < 0 || ! empty($actioninstance->error) || (! empty($actioninstance->errors) && count($actioninstance->errors) > 0))
|
||||
$resaction+=$actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
|
||||
if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
|
||||
{
|
||||
$this->error=$actioninstance->error; $this->errors=$actioninstance->errors;
|
||||
$this->error=$actionclassinstance->error; $this->errors=$actionclassinstance->errors;
|
||||
if ($method == 'doActions')
|
||||
{
|
||||
if ($action=='add') $action='create'; // TODO this change must be inside the doActions
|
||||
@ -152,10 +157,10 @@ class HookManager
|
||||
}
|
||||
}
|
||||
// Generic hooks that return a string (printSearchForm, printLeftBlock, formBuilddocOptions, ...)
|
||||
else if (method_exists($actioninstance,$method))
|
||||
else if (method_exists($actionclassinstance,$method))
|
||||
{
|
||||
if (is_array($parameters) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actioninstance->module_number) continue;
|
||||
$result = $actioninstance->$method($parameters, $object, $action, $this);
|
||||
if (is_array($parameters) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
|
||||
$result = $actionclassinstance->$method($parameters, $object, $action, $this);
|
||||
if (is_array($result)) $this->resArray = array_merge($this->resArray, $result);
|
||||
else $resprint.=$result;
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ class FormCompany
|
||||
{
|
||||
global $conf,$langs,$user;
|
||||
|
||||
dol_syslog("FormCompany::select_departement selected=$selected, country_codeid=$country_codeid",LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
|
||||
|
||||
$langs->load("dict");
|
||||
|
||||
@ -226,7 +226,7 @@ class FormCompany
|
||||
if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND p.code = '".$country_codeid."'";
|
||||
$sql .= " ORDER BY p.code, d.code_departement";
|
||||
|
||||
dol_syslog("FormCompany::select_departement sql=".$sql);
|
||||
dol_syslog(get_class($this)."::select_departement sql=".$sql);
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
|
||||
@ -215,8 +215,8 @@ CustomerRelativeDiscountShort=Relative discount
|
||||
CustomerAbsoluteDiscountShort=Absolute discount
|
||||
CompanyHasRelativeDiscount=This customer has a default discount of <b>%s%%</b>
|
||||
CompanyHasNoRelativeDiscount=This customer has no relative discount by default
|
||||
CompanyHasAbsoluteDiscount=This customer still has discount credits or deposits for <b>%s %s</b>
|
||||
CompanyHasCreditNote=This customer still has credit notes for <b>%s %s</b>
|
||||
CompanyHasAbsoluteDiscount=This customer still has discount credits or deposits for <b>%s</b> %s
|
||||
CompanyHasCreditNote=This customer still has credit notes for <b>%s</b> %s
|
||||
CompanyHasNoAbsoluteDiscount=This customer has no discount credit available
|
||||
CustomerAbsoluteDiscountAllUsers=Absolute discounts (granted by all users)
|
||||
CustomerAbsoluteDiscountMy=Absolute discounts (granted by yourself)
|
||||
|
||||
@ -217,8 +217,8 @@ CustomerRelativeDiscountShort=Remise relative
|
||||
CustomerAbsoluteDiscountShort=Remise fixe
|
||||
CompanyHasRelativeDiscount=Ce client a une remise par défaut de <b>%s%%</b>
|
||||
CompanyHasNoRelativeDiscount=Ce client n'a pas de remise relative par défaut
|
||||
CompanyHasAbsoluteDiscount=Ce client a <b>%s %s</b> de lignes de déduction disponibles (remises, acomptes...)
|
||||
CompanyHasCreditNote=Ce client a <b>%s %s</b> d'avoirs disponibles
|
||||
CompanyHasAbsoluteDiscount=Ce client a <b>%s</b> %s de lignes de déduction disponibles (remises, acomptes...)
|
||||
CompanyHasCreditNote=Ce client a <b>%s</b> %s d'avoirs disponibles
|
||||
CompanyHasNoAbsoluteDiscount=Ce client n'a pas ou plus de remise fixe disponible
|
||||
CustomerAbsoluteDiscountAllUsers=Remises fixes en cours (accordées par tout utilisateur)
|
||||
CustomerAbsoluteDiscountMy=Remises fixes en cours (accordées personnellement)
|
||||
|
||||
@ -1310,7 +1310,7 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
|
||||
include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
|
||||
$hookmanager=new HookManager($db);
|
||||
}
|
||||
$hookmanager->initHooks(array('searchform','leftblock','toprightmenu'));
|
||||
$hookmanager->initHooks(array('searchform','leftblock'));
|
||||
|
||||
if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print "\n".'<div class="ui-layout-west"> <!-- Begin left layout -->'."\n";
|
||||
else print '<td class="vmenu" valign="top">';
|
||||
|
||||
@ -702,7 +702,7 @@ class Societe extends CommonObject
|
||||
|
||||
$this->state_id = $obj->fk_departement;
|
||||
$this->state_code = $obj->state_code;
|
||||
$this->state = $obj->state;
|
||||
$this->state = ($obj->state!='-'?$obj->state:'');
|
||||
|
||||
$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
|
||||
$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
|
||||
|
||||
@ -791,7 +791,7 @@ else
|
||||
if (empty($conf->global->SOCIETE_DISABLE_STATE))
|
||||
{
|
||||
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
|
||||
if ($object->country_id) $formcompany->select_departement($object->state_id,$object->country_code,'departement_id');
|
||||
if ($object->country_id) print $formcompany->select_state($object->state_id,$object->country_code,'departement_id');
|
||||
else print $countrynotdefined;
|
||||
print '</td></tr>';
|
||||
}
|
||||
@ -1246,7 +1246,7 @@ else
|
||||
if (empty($conf->global->SOCIETE_DISABLE_STATE))
|
||||
{
|
||||
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
|
||||
$formcompany->select_departement($object->state_id,$object->country_code);
|
||||
print $formcompany->select_state($object->state_id,$object->country_code);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -1918,7 +1918,7 @@ else
|
||||
{
|
||||
$result=show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
|
||||
}
|
||||
|
||||
|
||||
// Addresses list
|
||||
if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user