From 3c182d4dee3a6670e974bcc1a113c4f7b4fb4e4d Mon Sep 17 00:00:00 2001 From: atm-florian Date: Thu, 11 Aug 2022 14:57:56 +0200 Subject: [PATCH 1/3] NEW: add oldcopy to Ticket so triggers intercepting TICKET_MODIFY have access to old values of the updated properties --- htdocs/ticket/class/ticket.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 496e6607bf7..d88fc15ade4 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -212,6 +212,11 @@ class Ticket extends CommonObject */ public $email_date; + /** + * @var Ticket $oldcopy State of this ticket as it was stored before an update operation (for triggers) + */ + public $oldcopy; + public $lines; @@ -974,6 +979,10 @@ class Ticket extends CommonObject if (!$error && !$notrigger) { // Call trigger + if (empty($this->oldcopy)) { + $this->oldcopy = new self($this->db); + $this->oldcopy->fetch($this->id); + } $result = $this->call_trigger('TICKET_MODIFY', $user); if ($result < 0) { $error++; From e247ec162ac896bac25fa30c30046f5ef6c4fe94 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Thu, 11 Aug 2022 15:23:53 +0200 Subject: [PATCH 2/3] oldcopy for TICKET_MODIFY: fetch the old ticket before the UPDATE query --- htdocs/ticket/class/ticket.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index d88fc15ade4..95c60480cfa 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -870,6 +870,11 @@ class Ticket extends CommonObject global $conf, $langs, $hookmanager; $error = 0; + if (empty($this->oldcopy) && empty($notrigger)) { + $this->oldcopy = new self($this->db); + $this->oldcopy->fetch($this->id); + } + // Clean parameters if (isset($this->ref)) { $this->ref = trim($this->ref); @@ -979,10 +984,6 @@ class Ticket extends CommonObject if (!$error && !$notrigger) { // Call trigger - if (empty($this->oldcopy)) { - $this->oldcopy = new self($this->db); - $this->oldcopy->fetch($this->id); - } $result = $this->call_trigger('TICKET_MODIFY', $user); if ($result < 0) { $error++; @@ -1463,6 +1464,10 @@ class Ticket extends CommonObject $error = 0; if ($this->statut != self::STATUS_CANCELED) { // no closed + if (empty($this->oldcopy) && empty($notrigger)) { + $this->oldcopy = new self($this->db); + $this->oldcopy->fetch($this->id); + } $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."ticket"; From d113cf3689ad3a579c0d723c42329bfaeff27617 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Fri, 12 Aug 2022 09:20:18 +0200 Subject: [PATCH 3/3] Ticket `oldcopy`: use dol_clone() instead of fetching; keep oldcopy up to date if the methods are called several times --- htdocs/ticket/class/ticket.class.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 95c60480cfa..f6a4773c58f 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -870,9 +870,8 @@ class Ticket extends CommonObject global $conf, $langs, $hookmanager; $error = 0; - if (empty($this->oldcopy) && empty($notrigger)) { - $this->oldcopy = new self($this->db); - $this->oldcopy->fetch($this->id); + if (empty($notrigger)) { + $this->oldcopy = dol_clone($this, 1); } // Clean parameters @@ -1464,9 +1463,8 @@ class Ticket extends CommonObject $error = 0; if ($this->statut != self::STATUS_CANCELED) { // no closed - if (empty($this->oldcopy) && empty($notrigger)) { - $this->oldcopy = new self($this->db); - $this->oldcopy->fetch($this->id); + if (empty($notrigger)) { + $this->oldcopy = dol_clone($this, 1); } $this->db->begin();