From b7b18e3355aaecb52c64cafc1aa03775d2c90af4 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 7 Oct 2016 10:12:25 +0200 Subject: [PATCH 1/4] FIX: Error when CATEGORIE_RECURSIV_ADD is enabled and new category is daughter of an already linked to object --- htdocs/categories/class/categorie.class.php | 31 +++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index e1e44a475ed..6202fe6eb0a 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2006-2012 Regis Houssin * Copyright (C) 2006-2012 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin - * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2013-2016 Juanjo Menent * Copyright (C) 2013 Philippe Grand * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud @@ -642,17 +642,24 @@ class Categorie extends CommonObject } else { - $this->db->rollback(); - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $this->error=$this->db->lasterrno(); - return -3; - } - else - { - $this->error=$this->db->lasterror(); - } - return -1; + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + if (empty($conf->global->CATEGORIE_RECURSIV_ADD)) { + $this->db->rollback(); + $this->error = $this->db->lasterrno(); + return -3; + } + else { + $this->db->commit(); + return 1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } } } From 298e5cee61bc2ccc8a8def653f8a2415433e9d3b Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 7 Oct 2016 22:21:50 +0200 Subject: [PATCH 2/4] Fix #5843 best way fixing --- htdocs/categories/class/categorie.class.php | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 6202fe6eb0a..410f0f80682 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -558,6 +558,7 @@ class Categorie extends CommonObject global $user,$langs,$conf; $error=0; + $trigger=true; if ($this->id == -1) return -2; @@ -598,12 +599,16 @@ class Categorie extends CommonObject { $cat = new Categorie($this->db); $cat->id=$objparent->fk_parent; - $result=$cat->add_type($obj, $type); - if ($result < 0) - { - $this->error=$cat->error; - $error++; - } + + if (! $cat->containsObject($type,$obj->id)) { + $result=$cat->add_type($obj, $type); + if ($result < 0) { + $this->error=$cat->error; + $error++; + } + } else { + $trigger=false; + } } } } @@ -624,10 +629,13 @@ class Categorie extends CommonObject $this->linkto=$obj; // Call trigger - $result=$this->call_trigger('CATEGORY_LINK',$user); - if ($result < 0) { $error++; } - // End call triggers - + if ($trigger) { + $result = $this->call_trigger('CATEGORY_LINK', $user); + if ($result < 0) { + $error++; + } + // End call triggers + } if (! $error) { $this->db->commit(); From 45dfb8ca628ee3e18fa782b4ef4962b3adb0f8ca Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 7 Oct 2016 22:32:11 +0200 Subject: [PATCH 3/4] Fix #5843 best way fixing --- htdocs/categories/class/categorie.class.php | 72 +++++++++------------ 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 410f0f80682..2b88eaae209 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -558,7 +558,6 @@ class Categorie extends CommonObject global $user,$langs,$conf; $error=0; - $trigger=true; if ($this->id == -1) return -2; @@ -591,26 +590,23 @@ class Categorie extends CommonObject $resql=$this->db->query($sql); if ($resql) { - if ($this->db->num_rows($resql) > 0) - { - $objparent = $this->db->fetch_object($resql); + if ($this->db->num_rows($resql) > 0) { + $objparent = $this->db->fetch_object($resql); - if (!empty($objparent->fk_parent)) - { - $cat = new Categorie($this->db); - $cat->id=$objparent->fk_parent; + if (!empty($objparent->fk_parent)) { + $cat = new Categorie($this->db); + $cat->id = $objparent->fk_parent; + + if (!$cat->containsObject($type, $obj->id)) { + $result = $cat->add_type($obj, $type); + if ($result < 0) { + $this->error = $cat->error; + $error++; + } - if (! $cat->containsObject($type,$obj->id)) { - $result=$cat->add_type($obj, $type); - if ($result < 0) { - $this->error=$cat->error; - $error++; - } - } else { - $trigger=false; } - } - } + } + } } else { @@ -629,13 +625,10 @@ class Categorie extends CommonObject $this->linkto=$obj; // Call trigger - if ($trigger) { - $result = $this->call_trigger('CATEGORY_LINK', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } + $result=$this->call_trigger('CATEGORY_LINK',$user); + if ($result < 0) { $error++; } + // End call triggers + if (! $error) { $this->db->commit(); @@ -650,24 +643,17 @@ class Categorie extends CommonObject } else { - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - if (empty($conf->global->CATEGORIE_RECURSIV_ADD)) { - $this->db->rollback(); - $this->error = $this->db->lasterrno(); - return -3; - } - else { - $this->db->commit(); - return 1; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } + $this->db->rollback(); + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->lasterrno(); + return -3; + } + else + { + $this->error=$this->db->lasterror(); + } + return -1; } } From ffd486e3d65067845b5be2d4de026a1382820216 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 7 Oct 2016 22:54:08 +0200 Subject: [PATCH 4/4] Fix #5843 best way fixing --- htdocs/categories/class/categorie.class.php | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 2b88eaae209..b3cb3d9cc52 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -590,23 +590,24 @@ class Categorie extends CommonObject $resql=$this->db->query($sql); if ($resql) { - if ($this->db->num_rows($resql) > 0) { + if ($this->db->num_rows($resql) > 0) + { $objparent = $this->db->fetch_object($resql); - if (!empty($objparent->fk_parent)) { - $cat = new Categorie($this->db); - $cat->id = $objparent->fk_parent; - - if (!$cat->containsObject($type, $obj->id)) { - $result = $cat->add_type($obj, $type); - if ($result < 0) { - $this->error = $cat->error; - $error++; - } - - } - } - } + if (!empty($objparent->fk_parent)) + { + $cat = new Categorie($this->db); + $cat->id = $objparent->fk_parent; + if (!$cat->containsObject($type, $obj->id)) { + $result = $cat->add_type($obj, $type); + if ($result < 0) + { + $this->error = $cat->error; + $error++; + } + } + } + } } else {