Clean code

This commit is contained in:
Laurent Destailleur 2023-03-19 15:12:56 +01:00
parent a50c0b8292
commit 76ab7136f2
17 changed files with 12 additions and 93 deletions

View File

@ -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';

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -25,7 +25,6 @@
*/
include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
/**

View File

@ -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'));

View File

@ -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);
}

View File

@ -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);

View File

@ -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,

View File

@ -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.

View File

@ -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');

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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