Add error log to warn when module does not match specifications.
This commit is contained in:
parent
0743521b6b
commit
ad6bd5047f
@ -131,12 +131,12 @@ class HookManager
|
||||
// Define type of hook ('output', 'returnvalue' or 'addreplace'). 'addreplace' should be type for all hooks. 'output' and 'returnvalue' are deprecated.
|
||||
$hooktype='output';
|
||||
if (preg_match('/^pdf_/',$method)) $hooktype='returnvalue'; // pdf_xxx except pdf_writelinedesc are returnvalue hooks. When there is 2 hooks of this type, only last one win.
|
||||
if (in_array($method,array('addStatisticLine','doActions','formObjectOptions','moveUploadedFile','pdf_writelinedesc','paymentsupplierinvoices',
|
||||
'printSearchForm', 'formattachOptions', 'formBuilddocLineOptions'))) $hooktype='addreplace';
|
||||
if (in_array($method,array('addStatisticLine','doActions','formObjectOptions','formattachOptions','formBuilddocLineOptions','moveUploadedFile','pdf_writelinedesc','paymentsupplierinvoices',
|
||||
'printSearchForm'))) $hooktype='addreplace';
|
||||
|
||||
// Loop on each hook to qualify modules that declared context
|
||||
$modulealreadyexecuted=array();
|
||||
$resaction=0; $error=0;
|
||||
$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
|
||||
{
|
||||
@ -144,7 +144,7 @@ class HookManager
|
||||
{
|
||||
foreach($modules as $module => $actionclassinstance)
|
||||
{
|
||||
//print "Before hook ".get_class($actionclassinstance)." method=".$method." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." result=".$result." resaction=".$resaction."<br>\n";
|
||||
//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
|
||||
@ -160,7 +160,7 @@ class HookManager
|
||||
{
|
||||
$error++;
|
||||
$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
|
||||
// TODO remove this.
|
||||
// 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')
|
||||
{
|
||||
@ -172,7 +172,7 @@ class HookManager
|
||||
if (is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
|
||||
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
|
||||
}
|
||||
// Generic hooks that return a string or array (printSearchForm, printLeftBlock, printTopRightMenu, formAddObjectLine, formBuilddocOptions, ...)
|
||||
// Generic hooks that return a string or array (printSearchForm, printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
|
||||
else
|
||||
{
|
||||
// TODO. this should be done into the method of hook by returning nothing
|
||||
@ -182,13 +182,18 @@ class HookManager
|
||||
|
||||
if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
|
||||
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
|
||||
// TODO. remove this. array result must be set into $actionclassinstance->results
|
||||
// TODO dead code to remove (do not enable this, but fix hook instead)
|
||||
//if (is_array($result)) $this->resArray = array_merge($this->resArray, $result);
|
||||
// TODO. remove this. result must not be a string. we must use $actionclassinstance->resprints to return a string
|
||||
//if (! is_array($result) && ! is_numeric($result)) $this->resPrint.=$result;
|
||||
// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string. we must use $actionclassinstance->resprints to return a string
|
||||
if (! is_array($result) && ! is_numeric($result))
|
||||
{
|
||||
//print 'Error: Bug into module '.get_class($actionclassinstance).' hook must not return a string but an int and set string into ->resprints';
|
||||
dol_syslog('Error: Bug into module '.get_class($actionclassinstance).' hook must not return a string but an int and set string into ->resprints', LOG_ERR);
|
||||
if (empty($actionclassinstance->resprints)) { $this->resPrint.=$result; $result=0; }
|
||||
}
|
||||
}
|
||||
|
||||
//print "After hook ".get_class($actionclassinstance)." method=".$method." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." result=".$result." resaction=".$resaction."<br>\n";
|
||||
//print "After hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
|
||||
|
||||
unset($actionclassinstance->results);
|
||||
unset($actionclassinstance->resprints);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user