From 74080c142f14a8b1f6128d52b9e4be75e49acbfe Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 3 Apr 2024 23:09:39 +0200 Subject: [PATCH] Reintroduce Conf/DeprecationHandler --- htdocs/core/class/conf.class.php | 293 +++++++++++++++++++++---------- 1 file changed, 204 insertions(+), 89 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 94611852d22f0..711a0bb499ded 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2004-2020 Laurent Destailleur * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2006 Jean Heimburger + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +20,7 @@ * along with this program. If not, see . */ +require_once DOL_DOCUMENT_ROOT.'/core/class/doldeprecationhandler.class.php'; /** * \file htdocs/core/class/conf.class.php @@ -29,9 +31,17 @@ /** * Class to stock current configuration + * */ class Conf extends stdClass { + use DolDeprecationHandler; + /** + * When true, indicates to the DeprecationHandler that this + * class supports dynamic properties. + */ + protected $enableDynamicProperties = true; + /** * @var Object Associative array with properties found in conf file */ @@ -85,7 +95,6 @@ class Conf extends stdClass //! Used to store current menu handler public $standard_menu; - /** * @var array List of activated modules */ @@ -154,53 +163,173 @@ class Conf extends stdClass public $fournisseur; /** - * @var stdClass Product + * @var stdClass */ public $product; /** - * @deprecated Use product + * @var stdClass + * @deprecated Use $product + * @see $product + */ + private $produit; + + /** + * @var stdClass */ - public $produit; public $service; + + /** + * @var stdClass + * @deprecated Use $contract + * @see $contract + */ + private $contrat; + /** - * @deprecated Use contract + * @var stdClass */ - public $contrat; public $contract; + + /** + * @var stdClass + */ public $actions; + + /** + * @var stdClass + */ public $agenda; + + /** + * @var stdClass + * @deprecated Use $order + * @see $order + */ + private $commande; + + /** + * @var stdClass + */ public $propal; + /** - * @deprecated Use order + * @var stdClass */ - public $commande; public $order; + + /** + * @var stdClass + * @deprecated Use $invoice + * @see $invoice + */ + private $facture; + + /** - * @deprecated Use invoice + * @var stdClass */ - public $facture; public $invoice; + + /** + * @var stdClass + */ public $user; + + /** + * @var stdClass + * @deprecated Use $member + * @see $member + */ + private $adherent; + + /** - * @deprecated Use member + * @var stdClass */ - public $adherent; public $member; + + /** + * @var stdClass + */ public $bank; + + /** + * @var stdClass + */ public $notification; + + /** + * @var stdClass + */ public $expensereport; + + /** + * @var stdClass + */ public $productbatch; + + /** + * @var stdClass + * @deprecated Use $project + * @see $project + */ + private $projet; + + /** - * @deprecated Use project + * @var stdClass */ - public $projet; public $project; + + /** + * @var stdClass + */ public $supplier_proposal; + + /** + * @var stdClass + */ public $supplier_order; + + /** + * @var stdClass + */ public $supplier_invoice; + + /** + * @var stdClass + */ public $category; + /** + * @var stdClass + * @deprecated Use $category + * @see $category + */ + private $categorie; + + /** + * @var stdClass + * @deprecated Use $supplier_proposal + * @see $supplier_proposal + */ + private $supplierproposal; + + /** + * @var stdClass + * @deprecated Use $delivery_note + * @see $delivery_note + */ + private $expedition; + + /** + * @var stdClass + * @deprecated Use $bank + * @see $bank + */ + private $banque; + /** * Constructor @@ -252,20 +381,45 @@ public function __construct() $this->fournisseur = new stdClass(); $this->product = new stdClass(); $this->service = new stdClass(); - $this->contrat = new stdClass(); + $this->contract = new stdClass(); $this->actions = new stdClass(); $this->agenda = new stdClass(); - $this->commande = new stdClass(); + $this->order = new stdClass(); $this->propal = new stdClass(); - $this->facture = new stdClass(); + $this->invoice = new stdClass(); $this->user = new stdClass(); - $this->adherent = new stdClass(); + $this->member = new stdClass(); $this->bank = new stdClass(); $this->notification = new stdClass(); $this->expensereport = new stdClass(); $this->productbatch = new stdClass(); } + /** + * Provide list of deprecated properties and replacements + * + * @return array + */ + protected function deprecatedProperties() + { + return MODULE_MAPPING + + array( + // Previously detected module names, already in mapping + //'adherent' => 'member', + //'banque' => 'bank', + //'categorie' => 'category', + //'commande' => 'order', + //'contrat' => 'contract', + //'expedition' => 'delivery_note', + //'facture' => 'invoice', + //'projet' => 'project', + + // Other, not deprecated module names + 'produit' => 'product', + 'supplierproposal' => 'supplier_proposal', + ); + } + /** * Load setup values into conf object (read llx_const) for a specified entity @@ -320,14 +474,14 @@ public function setValues($db) $this->fournisseur = new stdClass(); $this->product = new stdClass(); $this->service = new stdClass(); - $this->contrat = new stdClass(); + $this->contract = new stdClass(); $this->actions = new stdClass(); $this->agenda = new stdClass(); - $this->commande = new stdClass(); + $this->order = new stdClass(); $this->propal = new stdClass(); - $this->facture = new stdClass(); + $this->invoice = new stdClass(); $this->user = new stdClass(); - $this->adherent = new stdClass(); + $this->member = new stdClass(); $this->bank = new stdClass(); $this->notification = new stdClass(); $this->expensereport = new stdClass(); @@ -428,12 +582,6 @@ public function setValues($db) } elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg)) { // If this is a module constant (must be at end) $modulename = strtolower($reg[1]); - if ($modulename == 'propale') { - $modulename = 'propal'; - } - if ($modulename == 'supplierproposal') { - $modulename = 'supplier_proposal'; - } $this->modules[$modulename] = $modulename; // Add this module in list of enabled modules // deprecated in php 8.2 @@ -444,7 +592,6 @@ public function setValues($db) $this->$modulename->enabled = true; // TODO Remove this // Duplicate entry with the new name - /* $mapping = $this->deprecatedProperties(); if (array_key_exists($modulename, $mapping)) { $newmodulename = $mapping[$modulename]; @@ -455,7 +602,6 @@ public function setValues($db) } $this->$newmodulename->enabled = true; // TODO Remove this } - */ } } } @@ -675,12 +821,12 @@ public function setValues($db) $this->productbatch->multidir_output = array($this->entity => $rootfordata."/productlot"); $this->productbatch->multidir_temp = array($this->entity => $rootfortemp."/productlot/temp"); - // Module contrat - $this->contrat->multidir_output = array($this->entity => $rootfordata."/contract"); - $this->contrat->multidir_temp = array($this->entity => $rootfortemp."/contract/temp"); + // Module contract + $this->contract->multidir_output = array($this->entity => $rootfordata."/contract"); + $this->contract->multidir_temp = array($this->entity => $rootfortemp."/contract/temp"); // For backward compatibility - $this->contrat->dir_output = $rootfordata."/contract"; - $this->contrat->dir_temp = $rootfortemp."/contract/temp"; + $this->contract->dir_output = $rootfordata."/contract"; + $this->contract->dir_temp = $rootfortemp."/contract/temp"; // Module bank $this->bank->multidir_output = array($this->entity => $rootfordata."/bank"); @@ -963,23 +1109,23 @@ public function setValues($db) // Delay before warnings // Avoid strict errors. TODO: Replace xxx->warning_delay with a property ->warning_delay_xxx if (isset($this->agenda)) { - $this->adherent->subscription = new stdClass(); - $this->adherent->subscription->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? (int) $this->global->MAIN_DELAY_MEMBERS : 0) * 86400; + $this->member->subscription = new stdClass(); + $this->member->subscription->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? (int) $this->global->MAIN_DELAY_MEMBERS : 0) * 86400; } if (isset($this->agenda)) { $this->agenda->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? (int) $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 86400; } - if (isset($this->projet)) { - $this->projet->warning_delay = (getDolGlobalInt('MAIN_DELAY_PROJECT_TO_CLOSE', 7) * 86400); - $this->projet->task = new StdClass(); - $this->projet->task->warning_delay = (getDolGlobalInt('MAIN_DELAY_TASKS_TODO', 7) * 86400); + if (isset($this->project)) { + $this->project->warning_delay = (getDolGlobalInt('MAIN_DELAY_PROJECT_TO_CLOSE', 7) * 86400); + $this->project->task = new StdClass(); + $this->project->task->warning_delay = (getDolGlobalInt('MAIN_DELAY_TASKS_TODO', 7) * 86400); } - if (isset($this->commande)) { - $this->commande->client = new stdClass(); - $this->commande->fournisseur = new stdClass(); - $this->commande->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? (int) $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 86400; - $this->commande->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? (int) $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 86400; + if (isset($this->order)) { + $this->order->client = new stdClass(); + $this->order->fournisseur = new stdClass(); + $this->order->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? (int) $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 86400; + $this->order->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? (int) $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 86400; } if (isset($this->propal)) { $this->propal->cloture = new stdClass(); @@ -987,20 +1133,20 @@ public function setValues($db) $this->propal->cloture->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE) ? (int) $this->global->MAIN_DELAY_PROPALS_TO_CLOSE : 0) * 86400; $this->propal->facturation->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_BILL) ? (int) $this->global->MAIN_DELAY_PROPALS_TO_BILL : 0) * 86400; } - if (isset($this->facture)) { - $this->facture->client = new stdClass(); - $this->facture->fournisseur = new stdClass(); - $this->facture->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? (int) $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 86400; - $this->facture->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? (int) $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 86400; + if (isset($this->invoice)) { + $this->invoice->client = new stdClass(); + $this->invoice->fournisseur = new stdClass(); + $this->invoice->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? (int) $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 86400; + $this->invoice->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? (int) $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 86400; } - if (isset($this->contrat)) { - $this->contrat->services = new stdClass(); - $this->contrat->services->inactifs = new stdClass(); - $this->contrat->services->expires = new stdClass(); - $this->contrat->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? (int) $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 86400; - $this->contrat->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? (int) $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 86400; + if (isset($this->contract)) { + $this->contract->services = new stdClass(); + $this->contract->services->inactifs = new stdClass(); + $this->contract->services->expires = new stdClass(); + $this->contract->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? (int) $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 86400; + $this->contract->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? (int) $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 86400; } - if (isset($this->commande)) { + if (isset($this->order)) { $this->bank->rappro = new stdClass(); $this->bank->cheque = new stdClass(); $this->bank->rappro->warning_delay = (isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE) ? (int) $this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE : 0) * 86400; @@ -1102,37 +1248,6 @@ public function setValues($db) unset($this->global->MAIN_NO_CONCAT_DESCRIPTION); } - // Simple deprecation management. We do not use DolDeprecationHandlet for $conf. - - // product is new use - if (isset($this->product)) { - // For backward compatibility - $this->produit = $this->product; - } - // invoice is new use, facture is old use still initialised - if (isset($this->facture)) { - $this->invoice = $this->facture; - } - // order is new use, commande is old use still initialised - if (isset($this->commande)) { - $this->order = $this->commande; - } - // contract is new use, contrat is old use still initialised - if (isset($this->contrat)) { - $this->contract = $this->contrat; - } - // category is new use, categorie is old use still initialised - if (isset($this->categorie)) { - $this->category = $this->categorie; - } - // project is new use, projet is old use still initialised - if (isset($this->projet) && !isset($this->project)) { - $this->project = $this->projet; - } - // member is new use, adherent is old use still initialised - if (isset($this->adherent) && !isset($this->member)) { - $this->member = $this->adherent; - } // Object $mc if (!defined('NOREQUIREMC') && isModEnabled('multicompany')) {