From c9b3193c44b0662c7b3aada430ff28a3dc09e779 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2013 13:18:24 +0200 Subject: [PATCH] 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. --- htdocs/core/class/hookmanager.class.php | 9 ++++++--- htdocs/core/lib/files.lib.php | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 72b49af418e..64d35cf004b 100755 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -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 diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index d847bd2df71..53726f39460 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -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; } /**