From 941a8e5e2bca02a80142e26d9d802d6de27b98fc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 Feb 2018 20:12:29 +0100 Subject: [PATCH] FIX: Properties updated if update successfull. --- htdocs/contrat/class/contrat.class.php | 95 ++++++++++++-------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 0d5262ac66b..64ffd794453 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -262,9 +262,10 @@ class Contrat extends CommonObject * @param User $user Object User making action * @param int|string $date_start Date start (now if empty) * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @param string $comment Comment * @return int <0 if KO, >0 if OK */ - function activateAll($user, $date_start='', $notrigger=0) + function activateAll($user, $date_start='', $notrigger=0, $comment='') { if (empty($date_start)) $date_start = dol_now(); @@ -282,7 +283,7 @@ class Contrat extends CommonObject { $contratline->context = $this->context; - $result = $contratline->active_line($user, $date_start, -1); + $result = $contratline->active_line($user, $date_start, -1, $comment); if ($result < 0) { $error++; @@ -1468,49 +1469,39 @@ class Contrat extends CommonObject { $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet"); - $result=$this->update_statut($user); - if ($result > 0) + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used { - - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used + $contractline = new ContratLigne($this->db); + $contractline->array_options=$array_options; + $contractline->id=$contractlineid; + $result=$contractline->insertExtraFields(); + if ($result < 0) { - $contractline = new ContratLigne($this->db); - $contractline->array_options=$array_options; - $contractline->id=$contractlineid; - $result=$contractline->insertExtraFields(); - if ($result < 0) - { - $this->error[]=$contractline->error; - $error++; - } - } - - if (empty($error)) { - // Call trigger - $result=$this->call_trigger('LINECONTRACT_INSERT',$user); - if ($result < 0) - { - $error++; - } - // End call triggers - } - - if ($error) - { - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return $contractlineid; + $this->error[]=$contractline->error; + $error++; } } - else + + if (empty($error)) { + // Call trigger + $result=$this->call_trigger('LINECONTRACT_INSERT',$user); + if ($result < 0) + { + $error++; + } + // End call triggers + } + + if ($error) { $this->db->rollback(); return -1; } + else + { + $this->db->commit(); + return $contractlineid; + } } else { @@ -3095,13 +3086,6 @@ class ContratLigne extends CommonObjectLine { global $langs, $conf; - // Update object - $this->date_ouverture = $date; - $this->date_fin_validite = $date_end; - $this->fk_user_ouverture = $user->id; - $this->date_cloture = null; - $this->commentaire = $comment; - $error = 0; $this->db->begin(); @@ -3119,15 +3103,26 @@ class ContratLigne extends CommonObjectLine if ($resql) { // Call trigger $result = $this->call_trigger('LINECONTRACT_ACTIVATE', $user); - if ($result < 0) { - $error++; + if ($result < 0) $error++; + // End call triggers + + if (! $error) + { + $this->statut = 4; + $this->date_ouverture = $date; + $this->date_fin_validite = $date_end; + $this->fk_user_ouverture = $user->id; + $this->date_cloture = null; + $this->commentaire = $comment; + + $this->db->commit(); + return 1; + } + else + { $this->db->rollback(); return -1; } - // End call triggers - - $this->db->commit(); - return 1; } else { $this->error = $this->db->lasterror(); $this->db->rollback();