From e6846f5c01320c59ad24ea08fee987fb208338c0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Mar 2017 20:06:10 +0100 Subject: [PATCH] Fix error management when renaming a project with existing ref. --- htdocs/projet/card.php | 5 +++-- htdocs/projet/class/project.class.php | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index a9306bb9218..661272631bc 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -270,8 +270,9 @@ if (empty($reshook)) $result=$object->update($user); if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors,'errors'); + $error++; + if ($result == -4) setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors'); + else setEventMessages($object->error, $object->errors, 'errors'); }else { // Category association $categories = GETPOST('categories'); diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index b242f7d6b06..fc1eb7410e3 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -334,12 +334,19 @@ class Project extends CommonObject } else { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - $this->db->rollback(); - dol_syslog(get_class($this)."::update error -2 " . $this->error, LOG_ERR); - $result = -2; - } + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + $this->db->rollback(); + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $result = -4; + } + else + { + $result = -2; + } + dol_syslog(get_class($this)."::update error " . $result . " " . $this->error, LOG_ERR); + } } else {