From ecb412849646fc75b1b17b129e4ad29e93c44db6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 1 Oct 2008 19:37:54 +0000 Subject: [PATCH] Fix: http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html --- htdocs/categories/categorie.class.php | 6 +++++- htdocs/societe.class.php | 29 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 897e41f48ec..4ed340c86c1 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -854,7 +854,11 @@ class Categorie } /** - * Retourne les catégories contenant le produit $id + * Return list of categories linked to element of type $type with id $typeid + * @param id Id of element + * @param type Type of link ('customer','fournisseur','societe'...) + * @param typeid Type id of link (0,1,2...) + * @return array List of category objects */ function containing ($id,$type,$typeid) { diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 2aff452f8f3..87f17b36050 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -700,8 +700,35 @@ class Societe extends CommonObject - if ( $this->db->begin()) + if ($this->db->begin()) { + // Added by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html) + // Removing every "categorie" link with this company + require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); + + $static_cat = new Categorie($this->db); + $toute_categs = array(); + + // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) + if ($this->client || $this->prospect) + { + $toute_categs ['societe'] = $static_cat->containing($this->id,'societe',2); + } + if ($this->fournisseur) + { + $toute_categs ['fournisseur'] = $static_cat->containing($this->id,'fournisseur',1); + } + + // Remove each "Categorie" + foreach ($toute_categs as $type => $categs_type) + { + foreach ($categs_type as $cat) + { + $cat->del_type($this, $type); + } + } + + // Remove contacts $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = " . $id; if ($this->db->query($sql))