New: Apply DolDeprecatedHandler to Conf

# New: Apply DolDeprecatedHandler to Conf

Improve detection of deprecated values, avoid duplicating assignments,
alias deprecated property names to new properties.
This commit is contained in:
MDW 2024-02-14 02:34:30 +01:00
parent 8f3b245dbd
commit 925e1db907
No known key found for this signature in database

View file

@ -4,6 +4,7 @@
* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* 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,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/doldeprecationhandler.class.php';
/**
* \file htdocs/core/class/conf.class.php
* \ingroup core
@ -28,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
*/
@ -128,48 +139,180 @@ class Conf extends stdClass
// TODO Remove this part.
/**
* @var stdClass Supplier
*/
public $fournisseur;
/**
* @var stdClass
*/
public $product;
/**
* @deprecated Use product
* @var stdClass
* @deprecated Use $product
* @see $product
*/
private $produit;
/**
* @var stdClass
*/
public $produit;
public $service;
/**
* @deprecated Use contract
* @var stdClass
* @deprecated Use $contract
* @see $contract
*/
private $contrat;
/**
* @var stdClass
*/
public $contrat;
public $contract;
/**
* @var stdClass
*/
public $actions;
/**
* @var stdClass
*/
public $agenda;
public $commande;
/**
* @var stdClass
* @deprecated Use $order
* @see $order
*/
private $commande;
/**
* @var stdClass
*/
public $propal;
/**
* @var stdClass
*/
public $order;
/**
* @deprecated Use invoice
* @var stdClass
* @deprecated Use $invoice
* @see $invoice
*/
private $facture;
/**
* @var stdClass
*/
public $facture;
public $invoice;
/**
* @var stdClass
*/
public $user;
/**
* @deprecated Use member
* @var stdClass
* @deprecated Use $member
* @see $member
*/
private $adherent;
/**
* @var stdClass
*/
public $adherent;
public $member;
public $bank;
public $notification;
public $expensereport;
public $productbatch;
/**
* @deprecated Use project
* @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;
/**
* @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
@ -221,20 +364,46 @@ class Conf extends stdClass
$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<string,string>
*/
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
* Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setEntityValues is called.
@ -288,14 +457,14 @@ class Conf extends stdClass
$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();
@ -396,11 +565,9 @@ class Conf extends stdClass
} 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';
$mapping = $this->deprecatedProperties();
if (array_key_exists($modulename, $mapping)) {
$modulename = $mapping[$modulename];
}
$this->modules[$modulename] = $modulename; // Add this module in list of enabled modules
@ -630,12 +797,12 @@ class Conf extends stdClass
$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");
@ -918,23 +1085,23 @@ class Conf extends stdClass
// 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();
@ -942,20 +1109,20 @@ class Conf extends stdClass
$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;
@ -1057,35 +1224,6 @@ class Conf extends stdClass
unset($this->global->MAIN_NO_CONCAT_DESCRIPTION);
}
// 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')) {