From 04d3c7f43b7a700badd812a9d2f4bf6d6d7bec84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 12 Sep 2018 21:07:54 +0200 Subject: [PATCH 1/2] Update categorie.class.php --- htdocs/categories/class/categorie.class.php | 126 ++++---------------- 1 file changed, 21 insertions(+), 105 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index cddf26e343d..32a3de7f2f3 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -517,112 +517,28 @@ class Categorie extends CommonObject $error++; } } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_societe"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_fournisseur"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; - $sql .= " WHERE fk_categorie = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; - $sql .= " WHERE fk_categ = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); - $error++; - } - } - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang"; - $sql .= " WHERE fk_category = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); - $error++; - } - } - - // Delete category - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie"; - $sql .= " WHERE rowid = ".$this->id; - if (!$this->db->query($sql)) - { - $this->error=$this->db->lasterror(); - $error++; - } - } + $arraydelete = array( + 'categorie_societe' => 'fk_categorie', + 'categorie_fournisseur' => 'fk_categorie', + 'categorie_product' => 'fk_categorie', + 'categorie_member' => 'fk_categorie', + 'categorie_contact' => 'fk_categorie', + 'categorie_contact' => 'fk_categorie', + 'categorie_account' => 'fk_categorie', + 'bank_class' => 'fk_categ', + 'categorie_lang' => 'fk_category', + 'categorie' => 'rowid', + ); + foreach ($arraydelete as $key => $value) { + $sql = "DELETE FROM " . MAIN_DB_PREFIX . $key; + $sql .= " WHERE ".$value." = ".$this->id; + if (!$this->db->query($sql)) { + $this->errors[] = $this->db->lasterror(); + dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); + $error++; + } + } // Removed extrafields if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used From b5b4410e75bd7c20108e6bbc2bb67dd45cd17255 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Sep 2018 22:02:50 +0200 Subject: [PATCH 2/2] Duplicate delete --- htdocs/categories/class/categorie.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 32a3de7f2f3..087ab96567b 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -524,7 +524,6 @@ class Categorie extends CommonObject 'categorie_product' => 'fk_categorie', 'categorie_member' => 'fk_categorie', 'categorie_contact' => 'fk_categorie', - 'categorie_contact' => 'fk_categorie', 'categorie_account' => 'fk_categorie', 'bank_class' => 'fk_categ', 'categorie_lang' => 'fk_category',