Skip to content

Commit

Permalink
NEW: Create a DB static function to check deprecated table names
Browse files Browse the repository at this point in the history
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);`
  • Loading branch information
omogenot authored Nov 17, 2024
1 parent b2bad15 commit cefafc6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions htdocs/core/db/DoliDB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,20 @@ public function getRows($sql)

return false;
}
static $_deprecated_table_names = array(

Check failure on line 443 in htdocs/core/db/DoliDB.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Property DoliDB::$_deprecated_table_names has no type specified.
'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;

Check failure on line 457 in htdocs/core/db/DoliDB.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

DoliDB.class.php: PhanUndeclaredStaticProperty: Static property '_deprecated_table_names' on \CommonObject is undeclared

Check failure on line 457 in htdocs/core/db/DoliDB.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Access to an undefined static property CommonObject::$_deprecated_table_names.
}
}

0 comments on commit cefafc6

Please sign in to comment.