diff --git a/ChangeLog b/ChangeLog index 3f30b2a2f99..1a3e96b18ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,8 +11,9 @@ NEW: PHP 8.2 compatibility: WARNING: Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: -* The deprecated method escapeunderscore() of database handlers has been removed. You must use escapeforlike instead. -* The method nb_expedition() has been renamed into countNbOfShipments() +* The deprecated method "escapeunderscore()" of database handlers has been removed. You must use "escapeforlike()" instead. +* The method "nb_expedition()" has been renamed into "countNbOfShipments()" +* Revert default type of hooks. Default is now 'addreplace' hooks (and exception become 'output' hooks, that become deprecated). diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 0659240c8c7..7a6af7b88ec 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -162,84 +162,44 @@ class HookManager //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']); // Define type of hook ('output' or 'addreplace'). - // TODO Remove hooks with type 'output' (exemple getNomUrl). All hooks must be converted into 'addreplace' hooks. - $hooktype = 'output'; - if (in_array( - $method, - array( - 'addCalendarChoice', - 'addCalendarView', - 'addMoreActionsButtons', - 'addMoreMassActions', - 'addSearchEntry', - 'addStatisticLine', - 'addSectionECMAuto', - 'checkSecureAccess', - 'createDictionaryFieldlist', - 'editDictionaryFieldlist', - 'getFormMail', - 'deleteFile', - 'doActions', - 'doMassActions', - 'formatEvent', - 'formConfirm', - 'formCreateThirdpartyOptions', - 'formObjectOptions', - 'formattachOptions', - 'formBuilddocLineOptions', - 'formatNotificationMessage', - 'formConfirm', - 'getAccessForbiddenMessage', - 'getDirList', - 'hookGetEntity', - 'getFormMail', - 'getFormatedCustomerRef', - 'getFormatedSupplierRef', - 'getIdProfUrl', - 'getInputIdProf', - 'isPaymentOK', - 'llxFooter', - 'menuDropdownQuickaddItems', - 'menuLeftMenuItems', - 'moveUploadedFile', - 'moreHtmlStatus', - 'pdf_build_address', - 'pdf_writelinedesc', - 'pdf_getlinenum', - 'pdf_getlineref', - 'pdf_getlineref_supplier', - 'pdf_getlinevatrate', - 'pdf_getlineupexcltax', - 'pdf_getlineupwithtax', - 'pdf_getlineqty', - 'pdf_getlineqty_asked', - 'pdf_getlineqty_shipped', - 'pdf_getlineqty_keeptoship', - 'pdf_getlineunit', - 'pdf_getlineremisepercent', - 'pdf_getlineprogress', - 'pdf_getlinetotalexcltax', - 'pdf_getlinetotalwithtax', - 'paymentsupplierinvoices', - 'printAddress', - 'printEmail', - 'printSearchForm', - 'printTabsHead', - 'printObjectLine', - 'printObjectSubLine', - 'restrictedArea', - 'sendMail', - 'sendMailAfter', - 'showOptionals', - 'showLinkToObjectBlock', - 'setContentSecurityPolicy', - 'setHtmlTitle', - 'completeTabsHead', - 'formDolBanner', - 'displayMarginInfos', - ) - )) { - $hooktype = 'addreplace'; + $hooktype = 'addreplace'; + // TODO Remove hooks with type 'output' (exemple createFrom). All hooks must be converted into 'addreplace' hooks. + if (!in_array($method, array( + 'createFrom', + 'dashboardMembers', + 'dashboardEmailings', + 'dashboardPropals', + 'dashboardPropals', + 'dashboardCommercials', + 'dashboardOrders', + 'dashboardSpecialBills', + 'dashboardAccountancy', + 'dashboardContracts', + 'dashboardDonation', + 'dashboardWarehouseSendings', + 'dashboardExpenseReport', + 'dashboardInterventions', + 'dashboardOrdersSuppliers', + 'dashboardHRM', + 'dashboardMRP', + 'dashboardOpensurvey', + 'dashboardWarehouse', + 'dashboardProductServices', + 'dashboardActivities', + 'dashboardProjects', + 'dashboardWarehouseReceptions', + 'dashboardThirdparties', + 'dashboardSupplierProposal', + 'dashboardTickets', + 'dashboardUsersGroups', + 'insertExtraHeader', + 'insertExtraFooter', + 'printLeftBlock', + 'formAddObjectLine', + 'formBuilddocOption', + 'showSocinfoOnPrint' + ))) { + $hooktype = 'output'; } // Init return properties diff --git a/htdocs/document.php b/htdocs/document.php index 4f6652fafda..eccf49de0be 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -286,9 +286,10 @@ $hookmanager->initHooks(array('document')); $parameters = array('ecmfile' => $ecmfile, 'modulepart' => $modulepart, 'original_file' => $original_file, 'entity' => $entity, 'refname' => $refname, 'fullpath_original_file' => $fullpath_original_file, 'filename' => $filename, 'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded); -$reshook = $hookmanager->executeHooks('downloadDocument', $parameters); // Note that $action and $object may have been +$object = new stdClass(); +$reshook = $hookmanager->executeHooks('downloadDocument', $parameters, $object, $action); // Note that $action and $object may have been if ($reshook < 0) { - $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ? ', ' : '').join($separator, $hookmanager->errors) : ''); + $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ? ', ' : '').join(', ', $hookmanager->errors) : ''); dol_syslog("document.php - Errors when executing the hook 'downloadDocument' : ".$errors); print "ErrorDownloadDocumentHooks: ".$errors; exit; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 9fec72e2e86..549c72157a6 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -2603,11 +2603,11 @@ function printDropdownQuickadd() $parameters = array(); $hook_items = $items; $reshook = $hookmanager->executeHooks('menuDropdownQuickaddItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks - if (is_numeric($reshook) && !empty($hookmanager->results) && is_array($hookmanager->results)) { + if (is_numeric($reshook) && !empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { if ($reshook == 0) { - $items['items'] = array_merge($items['items'], $hookmanager->results); // add + $items['items'] = array_merge($items['items'], $hookmanager->resArray); // add } else { - $items = $hookmanager->results; // replace + $items = $hookmanager->resArray; // replace } // Sort menu items by 'position' value diff --git a/htdocs/mrp/index.php b/htdocs/mrp/index.php index d7929ce1422..835a06cc7c6 100644 --- a/htdocs/mrp/index.php +++ b/htdocs/mrp/index.php @@ -249,11 +249,12 @@ if ($resql) { print ''; +$object = new stdClass(); $parameters = array( //'type' => $type, 'user' => $user, ); -$reshook = $hookmanager->executeHooks('dashboardMRP', $parameters); +$reshook = $hookmanager->executeHooks('dashboardMRP', $parameters, $object); // End of page llxFooter(); diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index f89adcce0f8..74ff3fe238c 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -919,7 +919,7 @@ class ProductAttribute extends CommonObject $parameters = array('rowid' => $rowid, 'position' => $position); $action = ''; $reshook = $hookmanager->executeHooks('afterPositionOfAttributeUpdate', $parameters, $this, $action); - return 1; + return ($reshook >= 0 ? 1 : -1); } } diff --git a/htdocs/variants/tpl/productattributevalueline_edit.tpl.php b/htdocs/variants/tpl/productattributevalueline_edit.tpl.php index 3b842962258..60fc81c7418 100644 --- a/htdocs/variants/tpl/productattributevalueline_edit.tpl.php +++ b/htdocs/variants/tpl/productattributevalueline_edit.tpl.php @@ -54,7 +54,7 @@ $coldisplay++; ref); ?>"> $line); + $parameters = array('line' => $line); $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $object, $action); if (!empty($hookmanager->resPrint)) { print $hookmanager->resPrint; diff --git a/htdocs/webhook/target_card.php b/htdocs/webhook/target_card.php index 83f2008703f..a35f04d0138 100644 --- a/htdocs/webhook/target_card.php +++ b/htdocs/webhook/target_card.php @@ -430,7 +430,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $parameters = array(); $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } if (empty($reshook)) $object->formAddObjectLine(1, $mysoc, $soc); }