diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index b725cafdacd..8c21b070d9f 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -37,7 +37,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index f56932d4985..7c71d073629 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -388,12 +388,6 @@ class AccountingJournal extends CommonObject if (empty($type)) $type = 'view'; if (empty($in_bookkeeping)) $in_bookkeeping = 'notyet'; - // Hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $data = array(); $hookmanager->initHooks(array('accountingjournaldao')); @@ -790,12 +784,6 @@ class AccountingJournal extends CommonObject global $conf, $langs, $hookmanager; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; - // Hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $error = 0; $hookmanager->initHooks(array('accountingjournaldao')); @@ -940,11 +928,6 @@ class AccountingJournal extends CommonObject $out = ''; // Hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('accountingjournaldao')); $parameters = array('journal_data' => &$journal_data, 'search_date_end' => &$search_date_end, 'sep' => &$sep, 'out' => &$out); $reshook = $hookmanager->executeHooks('exportCsv', $parameters, $this); // Note that $action and $object may have been diff --git a/htdocs/asset/class/assetaccountancycodes.class.php b/htdocs/asset/class/assetaccountancycodes.class.php index 720dd1e745d..60b545ba6ce 100644 --- a/htdocs/asset/class/assetaccountancycodes.class.php +++ b/htdocs/asset/class/assetaccountancycodes.class.php @@ -116,11 +116,6 @@ class AssetAccountancyCodes extends CommonObject $asset_id = $asset_id > 0 ? $asset_id : 0; $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0; - if (!is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('assetaccountancycodesdao')); $parameters = array('asset_id' => $asset_id, 'asset_model_id' => $asset_model_id); $reshook = $hookmanager->executeHooks('fetchAccountancyCodes', $parameters, $this); // Note that $action and $object may have been modified by some hooks @@ -188,11 +183,6 @@ class AssetAccountancyCodes extends CommonObject $asset_id = $asset_id > 0 ? $asset_id : 0; $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0; - if (!is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('assetaccountancycodesdao')); $parameters = array('user' => $user, 'asset_id' => $asset_id, 'asset_model_id' => $asset_model_id); $reshook = $hookmanager->executeHooks('updateAccountancyCodes', $parameters, $this); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/asset/class/assetdepreciationoptions.class.php b/htdocs/asset/class/assetdepreciationoptions.class.php index 49efadca869..f2411ea4494 100644 --- a/htdocs/asset/class/assetdepreciationoptions.class.php +++ b/htdocs/asset/class/assetdepreciationoptions.class.php @@ -319,11 +319,6 @@ class AssetDepreciationOptions extends CommonObject $asset_id = $asset_id > 0 ? $asset_id : 0; $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0; - if (!is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('assetdepreciationoptionsdao')); $parameters = array('asset_id' => $asset_id, 'asset_model_id' => $asset_model_id); $reshook = $hookmanager->executeHooks('fetchDepreciationOptions', $parameters, $this); // Note that $action and $object may have been modified by some hooks @@ -392,11 +387,6 @@ class AssetDepreciationOptions extends CommonObject // Clean parameters $mode = strtolower(trim($mode)); - if (!is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('assetdepreciationoptionsdao')); $parameters = array('mode' => $mode); $reshook = $hookmanager->executeHooks('getGeneralDepreciationInfoForMode', $parameters, $this); // Note that $action and $object may have been modified by some hooks @@ -437,11 +427,6 @@ class AssetDepreciationOptions extends CommonObject $asset_id = $asset_id > 0 ? $asset_id : 0; $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0; - if (!is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } - $hookmanager->initHooks(array('assetdepreciationoptionsdao')); $parameters = array('user' => $user, 'asset_id' => $asset_id, 'asset_model_id' => $asset_model_id); $reshook = $hookmanager->executeHooks('updateDepreciationOptions', $parameters, $this); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c39e432e535..591601dbf52 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1733,12 +1733,6 @@ class Facture extends CommonInvoice } } - - if (! is_object($hookmanager)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($origin->db); - } - $hookmanager->initHooks(array('invoicedao')); $parameters = array('objFrom' => $origin); diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php index 6152b167863..17544d90299 100644 --- a/htdocs/core/boxes/box_dolibarr_state_board.php +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -25,7 +25,6 @@ */ include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; -include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; /** diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index ab56e80b4b5..ba767993e6a 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1545,8 +1545,6 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql = ''; if (isModEnabled('agenda')) { - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($db); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agendadao')); diff --git a/htdocs/core/tpl/advtarget.tpl.php b/htdocs/core/tpl/advtarget.tpl.php index 55d5c5ed24a..2e0b800e022 100644 --- a/htdocs/core/tpl/advtarget.tpl.php +++ b/htdocs/core/tpl/advtarget.tpl.php @@ -336,12 +336,7 @@ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $std_soc = new Societe($db); $action_search = 'query'; - // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($db); - $hookmanager->initHooks(array('thirdpartycard')); - - $parameters = array(); + $parameters = array('advtarget'=>1); if (!empty($advTarget->id)) { $parameters = array('array_query' => $advTarget->filtervalue); } diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index bc10b6cf0ee..39f0e37c206 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -94,7 +94,6 @@ class InterfaceNotification extends DolibarrTriggers global $conf, $action; global $hookmanager; - if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); diff --git a/htdocs/document.php b/htdocs/document.php index eccf49de0be..21ab1b8b054 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -278,10 +278,6 @@ if (!file_exists($fullpath_original_file_osencoded)) { } // Hooks -if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); -} $hookmanager->initHooks(array('document')); $parameters = array('ecmfile' => $ecmfile, 'modulepart' => $modulepart, 'original_file' => $original_file, 'entity' => $entity, 'refname' => $refname, 'fullpath_original_file' => $fullpath_original_file, diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index ab9d45a6a81..8f539c507b4 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -354,7 +354,7 @@ if (!defined('NOSESSION')) { } -// Init the 5 global objects, this include will make the 'new Xxx()' and set properties for: $conf, $db, $langs, $user, $mysoc +// Init the 6 global objects, this include will make the 'new Xxx()' and set properties for: $conf, $db, $langs, $user, $mysoc, $hookmanager require_once 'master.inc.php'; // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed. diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 2a90d1e1743..e7e532d666d 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -35,6 +35,8 @@ // Include the conf.php and functions.lib.php and security.lib.php. This defined the constants like DOL_DOCUMENT_ROOT, DOL_DATA_ROOT, DOL_URL_ROOT... // This file may have been already required by main.inc.php. But may not by scripts. So, here the require_once must be kept. require_once 'filefunc.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; if (!function_exists('is_countable')) { @@ -53,8 +55,6 @@ if (!function_exists('is_countable')) { * Create $conf object */ -require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php'; - $conf = new Conf(); // Set properties specific to database @@ -174,6 +174,11 @@ if (!defined('NOREQUIREUSER')) { $user = new User($db); } +/* + * Create the global $hookmanager object + */ +$hookmanager = new HookManager($db); + /* * Load object $conf @@ -241,10 +246,6 @@ if (!defined('NOREQUIRETRAN')) { } -// Create the global $hookmanager object -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager = new HookManager($db); - if (!defined('MAIN_LABEL_MENTION_NPR')) { define('MAIN_LABEL_MENTION_NPR', 'NPR'); diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php index bcd437ad21d..0da8c7b3150 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php @@ -225,6 +225,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject { // phpcs:enable global $user, $langs, $conf, $mysoc, $hookmanager; + global $action; if (empty($srctemplatepath)) { dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); @@ -232,12 +233,7 @@ class doc_generic_myobject_odt extends ModelePDFMyObject } // Add odtgeneration hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } $hookmanager->initHooks(array('odtgeneration')); - global $action; if (!is_object($outputlangs)) { $outputlangs = $langs; diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 21397085729..6b66dea857e 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -270,10 +270,6 @@ class pdf_standard_myobject extends ModelePDFMyObject if (file_exists($dir)) { // Add pdfgeneration hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); global $action; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 86b2abfa8f2..0d7b4675bcf 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5687,10 +5687,6 @@ class Product extends CommonObject $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur); } - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } $hookmanager->initHooks(array('productdao')); $parameters = array('id'=>$this->id, 'includedraftpoforvirtual' => $includedraftpoforvirtual); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php index a415cb5c940..1837d9a6839 100644 --- a/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php +++ b/htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php @@ -213,6 +213,7 @@ class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosi { // phpcs:enable global $user, $langs, $conf, $mysoc, $hookmanager; + global $action; if (empty($srctemplatepath)) { dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); @@ -220,12 +221,7 @@ class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosi } // Add odtgeneration hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } $hookmanager->initHooks(array('odtgeneration')); - global $action; if (!is_object($outputlangs)) { $outputlangs = $langs; diff --git a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php index 8ee6043f870..1c066112f45 100644 --- a/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php +++ b/htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php @@ -175,6 +175,7 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio { // phpcs:enable global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines; + global $action; dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')); @@ -281,13 +282,8 @@ class pdf_standard_recruitmentjobposition extends ModelePDFRecruitmentJobPositio if (file_exists($dir)) { // Add pdfgeneration hook - if (!is_object($hookmanager)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($this->db); - } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); - global $action; $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks // Set nblines with the new facture lines content after hook