From 4e707af0fd371387ae2acf72b51cf8acb63e5638 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 23 May 2016 09:16:47 +0200 Subject: [PATCH] Add demo information and transsaction management --- .../interface_90_all_Demo.class.php-NORUN | 4 ++ htdocs/expedition/class/expedition.class.php | 47 ++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index f25a99f3b59..717ef6585f5 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -119,6 +119,7 @@ class InterfaceDemo extends DolibarrTriggers case 'ORDER_CANCEL': case 'ORDER_SENTBYMAIL': case 'ORDER_CLASSIFY_BILLED': + case 'ORDER_SETDRAFT': case 'LINEORDER_INSERT': case 'LINEORDER_UPDATE': case 'LINEORDER_DELETE': @@ -258,6 +259,9 @@ class InterfaceDemo extends DolibarrTriggers case 'SHIPPING_MODIFY': case 'SHIPPING_VALIDATE': case 'SHIPPING_SENTBYMAIL': + case 'SHIPPING_BILLED': + case 'SHIPPING_CLOSED': + case 'SHIPPING_REOPEN': case 'SHIPPING_DELETE': dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); break; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index b9aaa01b667..b2f5d4bde40 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1798,6 +1798,10 @@ class Expedition extends CommonObject function setClosed() { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1810,15 +1814,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_CLOSED',$user); if ($result < 0) { - return -1; + $error++; } - // End call triggers + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } } @@ -1830,6 +1842,9 @@ class Expedition extends CommonObject */ function set_billed() { + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1843,16 +1858,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_BILLED',$user); if ($result < 0) { - return -1; + $error++; } - // End call triggers - + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } } @@ -1865,6 +1887,10 @@ class Expedition extends CommonObject function reOpen() { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1877,14 +1903,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_REOPEN',$user); if ($result < 0) { - return -1; + $error++; } + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } }