Skip to content
Snippets Groups Projects
Commit ad6bd504 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Add error log to warn when module does not match specifications.

parent 0743521b
No related branches found
No related tags found
No related merge requests found
...@@ -131,12 +131,12 @@ class HookManager ...@@ -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. // Define type of hook ('output', 'returnvalue' or 'addreplace'). 'addreplace' should be type for all hooks. 'output' and 'returnvalue' are deprecated.
$hooktype='output'; $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 (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', if (in_array($method,array('addStatisticLine','doActions','formObjectOptions','formattachOptions','formBuilddocLineOptions','moveUploadedFile','pdf_writelinedesc','paymentsupplierinvoices',
'printSearchForm', 'formattachOptions', 'formBuilddocLineOptions'))) $hooktype='addreplace'; 'printSearchForm'))) $hooktype='addreplace';
// Loop on each hook to qualify modules that declared context // Loop on each hook to qualify modules that declared context
$modulealreadyexecuted=array(); $modulealreadyexecuted=array();
$resaction=0; $error=0; $resaction=0; $error=0; $result='';
$this->resPrint=''; $this->resArray=array(); $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 $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 ...@@ -144,7 +144,7 @@ class HookManager
{ {
foreach($modules as $module => $actionclassinstance) 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; //print 'class='.get_class($actionclassinstance).' method='.$method.' action='.$action;
// jump to next class if method does not exists // jump to next class if method does not exists
...@@ -160,7 +160,7 @@ class HookManager ...@@ -160,7 +160,7 @@ class HookManager
{ {
$error++; $error++;
$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors); $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. /* 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 ($method == 'doActions')
{ {
...@@ -172,7 +172,7 @@ class HookManager ...@@ -172,7 +172,7 @@ class HookManager
if (is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; 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 else
{ {
// TODO. this should be done into the method of hook by returning nothing // TODO. this should be done into the method of hook by returning nothing
...@@ -182,13 +182,18 @@ class HookManager ...@@ -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->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; 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); //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 // 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)) $this->resPrint.=$result; 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->results);
unset($actionclassinstance->resprints); unset($actionclassinstance->resprints);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment