From a4edaf4f4399b29bac510a46a21b611a86c2d2d0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Jan 2017 10:18:47 +0100 Subject: [PATCH 1/5] Fix sql to get next ref on expense report --- htdocs/expensereport/class/expensereport.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 631d1ca548b..e4a37cb5f62 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1207,15 +1207,14 @@ class ExpenseReport extends CommonObject $expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR; $num_car = (empty($conf->global->NDF_NUM_CAR_REF))?"5":$conf->global->NDF_NUM_CAR_REF; - $sql = 'SELECT de.ref_number_int'; + $sql = 'SELECT MAX(de.ref_number_int) as max'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de'; - $sql.= ' ORDER BY de.ref_number_int DESC'; - + $result = $this->db->query($sql); if($this->db->num_rows($result) > 0): $objp = $this->db->fetch_object($result); - $this->ref = $objp->ref_number_int; + $this->ref = $objp->max; $this->ref++; while(strlen($this->ref) < $num_car): $this->ref = "0".$this->ref; From 53137e53fe31109b931d1a0c2d6f95054d44185e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Jan 2017 10:33:56 +0100 Subject: [PATCH 2/5] Fix prepare RC --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 2954b431708..bb739f58e86 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-beta'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc'); if (! defined('EURO')) define('EURO',chr(128)); From 466dfc85a3cc26148d159b8c936911f9f3b04577 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Jan 2017 10:36:27 +0100 Subject: [PATCH 3/5] Prepare RC1 --- htdocs/filefunc.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index bb739f58e86..5ce661278fc 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Xavier Dutoit - * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2011 Regis Houssin @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc1'); # a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c if (! defined('EURO')) define('EURO',chr(128)); From 212f2004540dcd5ce442df1a91512d02cb798518 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Jan 2017 11:38:31 +0100 Subject: [PATCH 4/5] Fix phpcs --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 5ce661278fc..9eefb515b4c 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc1'); # a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-rc1'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c if (! defined('EURO')) define('EURO',chr(128)); From 2aae4ea6ea1d26b041fddae1f45012da2fd2bc52 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Jan 2017 15:05:13 +0100 Subject: [PATCH 5/5] FIX We must not drop column if there is still record on other entities. --- htdocs/core/class/extrafields.class.php | 32 +++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index caaabdf7393..496a8f2e251 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -323,16 +323,40 @@ class ExtraFields $table=$elementtype.'_extrafields'; + $error=0; + if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); // This also drop the unique key + $result=$this->delete_label($attrname,$elementtype); if ($result < 0) { - $this->error=$this->db->lasterror(); + $this->error=$this->db->lasterror(); + $error++; } - $result=$this->delete_label($attrname,$elementtype); - + if (! $error) + { + $sql = "SELECT COUNT(rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql.= " WHERE elementtype = '".$elementtype."'"; + $sql.= " AND name = '".$attrname."'"; + //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj->nb <= 0) + { + $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); // This also drop the unique key + if ($result < 0) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } + } + return $result; } else