From 93ee9a7496d7e6a355d73d9c3623624c475c9a07 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Fri, 9 Dec 2022 12:56:35 +0100 Subject: [PATCH 1/4] Delete links when MO is deleted --- htdocs/mrp/class/mo.class.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index d186c6e533b..9aa1ef5bd8e 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -744,8 +744,31 @@ class Mo extends CommonObject */ public function delete(User $user, $notrigger = false) { - return $this->deleteCommon($user, $notrigger); - //return $this->deleteCommon($user, $notrigger, 1); + $this->db->begin(); + + $error = 0; + + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) { + $error++; + } + + if(!$error){ + $res = $this->deleteCommon($user, $notrigger); + if($res < 0){ + $error++; + } + } + + if(!$error){ + dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); + $this->db->commit(); + return $res; + } else { + $this->db->rollback(); + return -1; + } } /** From 488a434c8b031230e87980af561aa45321056ca0 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 9 Dec 2022 11:58:27 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/mrp/class/mo.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 9aa1ef5bd8e..5eeb387fc88 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -754,14 +754,14 @@ class Mo extends CommonObject $error++; } - if(!$error){ + if (!$error) { $res = $this->deleteCommon($user, $notrigger); - if($res < 0){ + if ($res < 0) { $error++; } } - if(!$error){ + if (!$error) { dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); $this->db->commit(); return $res; From 95f437b45c8103cb8a871e49939fd1cb81bbf238 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 12 Dec 2022 10:05:44 +0100 Subject: [PATCH 3/4] deleteObjectLinked() in deleteCommon() function --- htdocs/core/class/commonobject.class.php | 6 ++++++ htdocs/mrp/class/mo.class.php | 27 ++---------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3e10ea82eaa..de19d651ba2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9472,6 +9472,12 @@ abstract class CommonObject } } + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) { + $error++; + } + // Commit or rollback if ($error) { $this->db->rollback(); diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 9aa1ef5bd8e..d186c6e533b 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -744,31 +744,8 @@ class Mo extends CommonObject */ public function delete(User $user, $notrigger = false) { - $this->db->begin(); - - $error = 0; - - // Delete linked object - $res = $this->deleteObjectLinked(); - if ($res < 0) { - $error++; - } - - if(!$error){ - $res = $this->deleteCommon($user, $notrigger); - if($res < 0){ - $error++; - } - } - - if(!$error){ - dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); - $this->db->commit(); - return $res; - } else { - $this->db->rollback(); - return -1; - } + return $this->deleteCommon($user, $notrigger); + //return $this->deleteCommon($user, $notrigger, 1); } /** From eff01374b1163a8bf304f5c1a7a190bef44e5c43 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Thu, 15 Dec 2022 15:09:50 +0100 Subject: [PATCH 4/4] Change place of deleteobjectlinked in deletecommon function --- htdocs/core/class/commonobject.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index de19d651ba2..d7d41a545ef 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9455,6 +9455,12 @@ abstract class CommonObject } } + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) { + $error++; + } + if (!$error && !empty($this->isextrafieldmanaged)) { $result = $this->deleteExtraFields(); if ($result < 0) { @@ -9472,12 +9478,6 @@ abstract class CommonObject } } - // Delete linked object - $res = $this->deleteObjectLinked(); - if ($res < 0) { - $error++; - } - // Commit or rollback if ($error) { $this->db->rollback();