From 88f18ec3ced598869b2348161be15665aacdc201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 11 Apr 2020 22:24:50 +0200 Subject: [PATCH 1/3] can't remove actioncomm if there is a category --- htdocs/comm/action/class/actioncomm.class.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 9325b38cfb3..f451ab2e3bd 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2015 Marcos García * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2020 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -900,14 +900,27 @@ class ActionComm extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; - $sql .= " WHERE id=".$this->id; + // remove categorie association + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm"; + $sql .= " WHERE fk_actioncomm=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); + dol_syslog(get_class($this)."::delete categorie", LOG_DEBUG); $res = $this->db->query($sql); if ($res < 0) { - $this->error = $this->db->lasterror(); - $error++; + $this->error = $this->db->lasterror(); + $error++; + } + // remove actioncomm + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; + $sql .= " WHERE id=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $res = $this->db->query($sql); + if ($res < 0) { + $this->error = $this->db->lasterror(); + $error++; + } } if (!$error) { From fe4cd2e7bcd7f6bbedf8bb8c92dc12e353cd2d90 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 12 Apr 2020 17:05:12 +0200 Subject: [PATCH 2/3] Update actioncomm.class.php --- htdocs/comm/action/class/actioncomm.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f451ab2e3bd..1ca0c512815 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -898,13 +898,14 @@ class ActionComm extends CommonObject $error = 0; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $this->db->begin(); // remove categorie association $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm"; $sql .= " WHERE fk_actioncomm=".$this->id; - dol_syslog(get_class($this)."::delete categorie", LOG_DEBUG); $res = $this->db->query($sql); if ($res < 0) { $this->error = $this->db->lasterror(); @@ -915,7 +916,6 @@ class ActionComm extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; $sql .= " WHERE id=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); $res = $this->db->query($sql); if ($res < 0) { $this->error = $this->db->lasterror(); @@ -927,7 +927,6 @@ class ActionComm extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources"; $sql .= " WHERE fk_actioncomm=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); $res = $this->db->query($sql); if ($res < 0) { $this->error = $this->db->lasterror(); From a873afdad9b6524468f6e4205b6e7bd5c05a1db3 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 12 Apr 2020 15:08:44 +0000 Subject: [PATCH 3/3] Fixing style errors. --- htdocs/comm/action/class/actioncomm.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 31c280714b7..03a78a95f9f 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -904,16 +904,16 @@ class ActionComm extends CommonObject // remove categorie association if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm"; - $sql .= " WHERE fk_actioncomm=".$this->id; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm"; + $sql .= " WHERE fk_actioncomm=".$this->id; - $res = $this->db->query($sql); - if (!$res) { - $this->error = $this->db->lasterror(); - $error++; - } + $res = $this->db->query($sql); + if (!$res) { + $this->error = $this->db->lasterror(); + $error++; + } } - + // remove actioncomm_resources if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources";