From a4797a0e4a5f5b7c68359b7748944dd58f22663d Mon Sep 17 00:00:00 2001
From: Cedric <c.gross@kreiz-it.fr>
Date: Tue, 1 Apr 2014 16:21:20 +0200
Subject: [PATCH] FIX : [ bug #1317 ] Removing a category does not remove all
 child categories

---
 htdocs/categories/class/categorie.class.php | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index 5a239f5eb21..a49ad862cac 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -290,6 +290,20 @@ class Categorie
 
 		$this->db->begin();
 
+		/* FIX #1317 : Check for child cat and move up 1 level*/
+		if (! $error)
+		{
+			$sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
+			$sql.= " SET fk_parent = ".$this->fk_parent; 
+			$sql.= " WHERE fk_parent = ".$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_societe";
-- 
GitLab