From 9d0fe3c1da979751eb610d06a3531f6ef536acf8 Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Mon, 15 Jul 2013 09:33:26 +0200 Subject: [PATCH 1/2] Use reopen method to repoen proposal and fire trigger PROPAL_REOPEN --- htdocs/comm/propal.php | 2 +- htdocs/comm/propal/class/propal.class.php | 55 ++++++++++++++++++----- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 09afbe57c34..155e2cc0e78 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -408,7 +408,7 @@ else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GET // prevent browser refresh from reopening proposal several times if ($object->statut==2 || $object->statut==3) { - $object->setStatut(1); + $object->reopen($user,1); } } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f4c87387040..152ca164ed3 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1587,32 +1587,67 @@ class Propal extends CommonObject /** - * Close the commercial proposal + * Reopen the commercial proposal * * @param User $user Object user that close * @param int $statut Statut * @param text $note Comment + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function reopen($user, $statut, $note) + function reopen($user, $statut, $note, $notrigger=0) { global $langs,$conf; $this->statut = $statut; $error=0; - $now=dol_now(); - - $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture=".$this->db->idate($now).", fk_user_cloture=".$user->id; + $sql.= " SET fk_statut = ".$statut.","; + if (! empty ( $note )) { + $sql .= " note_private = '" . $this->db->escape ( $note ) . "',"; + } + $sql.= " date_cloture=NULL, fk_user_cloture=NULL"; $sql.= " WHERE rowid = ".$this->id; - $resql=$this->db->query($sql); - if ($resql) - { + $this->db->begin(); - } + dol_syslog(get_class($this)."::reopen sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { + $error++; $this->errors[]="Error ".$this->db->lasterror(); + } + if (! $error) + { + if (! $notrigger) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PROPAL_REOPEN',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } } From d09af2b18e2e0a06dc5ca132b662541a91509a6e Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Mon, 15 Jul 2013 09:37:55 +0200 Subject: [PATCH 2/2] Better use of reopen method --- htdocs/comm/propal/class/propal.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 152ca164ed3..e3160dc61c9 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1603,7 +1603,7 @@ class Propal extends CommonObject $error=0; $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET fk_statut = ".$statut.","; + $sql.= " SET fk_statut = ".$this->statut.","; if (! empty ( $note )) { $sql .= " note_private = '" . $this->db->escape ( $note ) . "',"; }