Make CommonObject::cloneCategories() generic (#36758)

It was working only for products

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
spsolauv 2026-01-05 23:45:26 +01:00 committed by GitHub
parent b957f768cb
commit d6abd9305f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11529,9 +11529,12 @@ abstract class CommonObject
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$categorystatic = new Categorie($this->db);
$sql = "INSERT INTO ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)";
$sql .= " SELECT fk_categorie, $toId FROM ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
$sql .= " WHERE fk_product = ".((int) $fromId);
$tablename = $this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
$fkname = 'fk_' . (empty($categorystatic->MAP_CAT_FK[$type]) ? $type : $categorystatic->MAP_CAT_FK[$type]);
$sql = "INSERT INTO ".$tablename." (fk_categorie, ".$fkname.")";
$sql .= " SELECT fk_categorie, $toId FROM ".$tablename;
$sql .= " WHERE ".$fkname." = ".((int) $fromId);
if (!$this->db->query($sql)) {
$this->error = $this->db->lasterror();