Fix: Hooks with version 3.4 must match specification defined here:

http://wiki.dolibarr.org/index.php/Hooks_system
So i try a better fix that implement correctly this. To have the
moveFileUpload trigger keeping dolibarr code, it must return 0.
This commit is contained in:
Laurent Destailleur 2013-04-12 13:18:24 +02:00
parent 2e9a8369a7
commit c9b3193c44
2 changed files with 10 additions and 7 deletions

View File

@ -128,10 +128,10 @@ class HookManager
$parameters['context']=join(':',$this->contextarray);
dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
// Define type of hook ('output', 'returnvalue' or 'addreplace')
// 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('doActions','formObjectOptions','pdf_writelinedesc','paymentsupplierinvoices'))) $hooktype='addreplace';
if (in_array($method,array('doActions','formObjectOptions','moveUploadedFile','pdf_writelinedesc','paymentsupplierinvoices'))) $hooktype='addreplace';
// Loop on each hook to qualify modules that declared context
$modulealreadyexecuted=array();
@ -166,8 +166,11 @@ class HookManager
if ($action=='update') $action='edit';
}
}
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 (printSearchForm, printLeftBlock, printTopRightMenu, formAddObjectLine, formBuilddocOptions, ...)
// Generic hooks that return a string or array (printSearchForm, printLeftBlock, printTopRightMenu, formAddObjectLine, formBuilddocOptions, ...)
else
{
// TODO. this should be done into the method of hook by returning nothing

View File

@ -647,13 +647,13 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
return -2;
}
$hookmanager->initHooks(array('fileslib'));
$reshook=$hookmanager->initHooks(array('fileslib'));
$parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
$hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
$reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
}
if (empty($hookmanager->resPrint))
if (empty($reshook))
{
// The file functions must be in OS filesystem encoding.
$src_file_osencoded=dol_osencode($src_file);
@ -687,7 +687,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
}
}
else
return $hookmanager->resPrint;
return $reshook;
}
/**