From cefafc682c6e61a26f5842cabf85c95e3dc9285e Mon Sep 17 00:00:00 2001 From: omogenot Date: Sun, 17 Nov 2024 15:52:36 +0100 Subject: [PATCH] NEW: Create a DB static function to check deprecated table names It looks like in many places, there some code to change table name from old "french" names that are deprecated throughout version releases in favour of english names for internationalisation of Dolibarr. I propose to place this code as a common static function in the DoliDB class (which is generally contained in every other class). This would allow to continue to change table names without having to check every class for usage of old names and fix it. Usage: If object has no $db property; `$table_name = DoliDB::checkTableName($table_name);` if object has a $db property: `$table_name = $this->db->checkTableName($table_name);` --- htdocs/core/db/DoliDB.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index 1a898e9c61800..907c684a6a9d1 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -440,4 +440,20 @@ public function getRows($sql) return false; } + static $_deprecated_table_names = array( + 'thirdparty' => 'societe', + 'contact' => 'socpeople', + 'invoice' => 'facture', + 'order_supplier' => 'commande_fournisseur', + 'categorie_extrafields' => 'categories_extrafields' + ); + /** + * Check table name and change it to new version table name if table name is deprecated. + * + * @param string $table_name table name to check + * @return string new table name or original one if no change is required + */ + static public function checkTableName($table_name) { + return CommonObject::$_deprecated_table_names[$table_name] ?? $table_name; + } }