forked from Wavyzz/dolibarr
Merge remote-tracking branch 'origin/3.6' into 3.7
Conflicts: htdocs/core/class/commonobject.class.php htdocs/product/liste.php
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2010-2014 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -114,8 +114,8 @@ class HookManager
|
||||
*
|
||||
* @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'...)
|
||||
* @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,formObjectOptions,pdf_xxx: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO.
|
||||
* For printSearchForm,printLeftBlock,printTopRightMenu,formAddObjectLine,...: Return HTML string. TODO Deprecated. Must always return an int and things to print into ->resprints.
|
||||
* Can also return some values into an array ->results.
|
||||
@@ -145,7 +145,8 @@ class HookManager
|
||||
'moveUploadedFile',
|
||||
'pdf_writelinedesc',
|
||||
'paymentsupplierinvoices',
|
||||
'printSearchForm'
|
||||
'printSearchForm',
|
||||
'formatEvent'
|
||||
)
|
||||
)) $hooktype='addreplace';
|
||||
|
||||
@@ -153,7 +154,7 @@ class HookManager
|
||||
$modulealreadyexecuted=array();
|
||||
$resaction=0; $error=0; $result='';
|
||||
$this->resPrint=''; $this->resArray=array();
|
||||
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
|
||||
foreach($this->hooks as $context => $modules) // this->hooks is an array with context as key and value is an array of modules that handle this context
|
||||
{
|
||||
if (! empty($modules))
|
||||
{
|
||||
@@ -161,27 +162,29 @@ class HookManager
|
||||
{
|
||||
//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
|
||||
|
||||
//print 'class='.get_class($actionclassinstance).' method='.$method.' action='.$action;
|
||||
// jump to next class if method does not exists
|
||||
// jump to next module/class if method does not exists
|
||||
if (! method_exists($actionclassinstance,$method)) continue;
|
||||
// test to avoid to run twice a hook, when a module implements several active contexts
|
||||
|
||||
// test to avoid to run twice a hook, when a module implements several active contexts
|
||||
if (in_array($module,$modulealreadyexecuted)) continue;
|
||||
$modulealreadyexecuted[$module]=$module;
|
||||
$modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method for avoid to run twice
|
||||
|
||||
// Clean class (an error may have been set into a previous call of another method for same module/hook)
|
||||
$actionclassinstance->error=0;
|
||||
$actionclassinstance->errors=array();
|
||||
|
||||
// Add current context for avoid method execution in bad context, you can add this test in your method : eg if($currentcontext != 'formfile') return;
|
||||
$parameters['currentcontext'] = $context;
|
||||
// Hooks that must return int (hooks with type 'addreplace')
|
||||
if ($hooktype == 'addreplace')
|
||||
{
|
||||
dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
|
||||
$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))
|
||||
{
|
||||
$error++;
|
||||
$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
|
||||
// TODO dead code to remove (do not enable this, but fix hook instead)
|
||||
/* Change must be inside the method of hook if required. Only hook must decide if $action must be modified or not.
|
||||
if ($method == 'doActions')
|
||||
{
|
||||
if ($action=='add') $action='create';
|
||||
if ($action=='update') $action='edit';
|
||||
}*/
|
||||
dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
|
||||
}
|
||||
|
||||
if (is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
|
||||
@@ -193,6 +196,7 @@ class HookManager
|
||||
// TODO. this should be done into the method of hook by returning nothing
|
||||
if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
|
||||
|
||||
//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
|
||||
$result = $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 (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
|
||||
|
||||
Reference in New Issue
Block a user