diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 65fd69a9a8b..03a78a95f9f 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 @@ -898,23 +898,27 @@ class ActionComm extends CommonObject $error = 0; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; - $sql .= " WHERE id=".$this->id; + // remove categorie association + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm"; + $sql .= " WHERE fk_actioncomm=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $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"; $sql .= " WHERE fk_actioncomm=".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); $res = $this->db->query($sql); if (!$res) { $this->error=$this->db->lasterror(); @@ -924,7 +928,7 @@ class ActionComm extends CommonObject // Removed extrafields if (!$error) { - $result = $this->deleteExtraFields(); + $result = $this->deleteExtraFields(); if ($result < 0) { $error++; @@ -932,6 +936,18 @@ class ActionComm extends CommonObject } } + // remove actioncomm + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; + $sql .= " WHERE id=".$this->id; + + $res = $this->db->query($sql); + if (!$res) { + $this->error = $this->db->lasterror(); + $error++; + } + } + if (!$error) { if (!$notrigger)