From b4f31d61fa85af43224103cbcde9910e257ccb75 Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Mon, 23 Sep 2019 17:36:18 +0200 Subject: [PATCH 1/6] allow to remove one custom referent in the project. Allow to remove one custom referent from the project. When we develop one module that supports the custom referent in a project and if you don't follow the same naming convention as in the other table (in french). You cannot remove the element. This fix support now the property 'project_field'. And thus set this column to null. [see: #11881] --- htdocs/projet/class/project.class.php | 10 +++++----- htdocs/projet/element.php | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 2261e06219b..cbed549ac29 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1676,9 +1676,11 @@ class Project extends CommonObject * * @param string $tableName Table of the element to update * @param int $elementSelectId Key-rowid of the line of the element to update + * @param string $projectfield The column name that stores the link with the project + * * @return int 1 if OK or < 0 if KO */ - public function remove_element($tableName, $elementSelectId) + public function remove_element($tableName, $elementSelectId, $projectfield = 'fk_projet') { // phpcs:enable $sql="UPDATE ".MAIN_DB_PREFIX.$tableName; @@ -1687,11 +1689,9 @@ class Project extends CommonObject { $sql.= " SET fk_project=NULL"; $sql.= " WHERE id=".$elementSelectId; - } - else + }else { - $sql.= " SET fk_projet=NULL"; - $sql.= " WHERE rowid=".$elementSelectId; + $sql.= sprintf(" SET %s=NULL WHERE rowid=%s", $projectfield, $elementSelectId); } dol_syslog(get_class($this)."::remove_element", LOG_DEBUG); diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 4f5af0ca94f..aea1626e67b 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -513,9 +513,10 @@ elseif ($action == "unlink") { $tablename = GETPOST("tablename"); + $projectField = GETPOST("projectfield"); $elementselectid = GETPOST("elementselect"); - $result = $object->remove_element($tablename, $elementselectid); + $result = $object->remove_element($tablename, $elementselectid, $projectField); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -889,7 +890,7 @@ foreach ($listofreferent as $key => $value) { if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true { - print ''; + print sprintf('', $_SERVER["PHP_SELF"], $projectid, $tablename, $element->id, $project_field?: 'fk_projet'); print img_picto($langs->trans('Unlink'), 'unlink'); print ''; } From 089392618931a14ebf75f66295d2dec7c51518f2 Mon Sep 17 00:00:00 2001 From: JC Prieto Date: Wed, 25 Sep 2019 12:49:19 +0200 Subject: [PATCH 2/6] Update expedition.class.php Clear lines before fech them. --- htdocs/expedition/class/expedition.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 7fc4def441b..13ddccdd896 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -603,6 +603,8 @@ class Expedition extends CommonObject $this->location_incoterms = $obj->location_incoterms; $this->libelle_incoterms = $obj->libelle_incoterms; + $this->lines = array(); + $this->db->free($result); if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; From cdb6e7f9a652bd89e26c5175b64e6a1114ff34ed Mon Sep 17 00:00:00 2001 From: JC Prieto Date: Thu, 26 Sep 2019 20:34:28 +0200 Subject: [PATCH 3/6] Fix moved to fetch_line() Fix moved to fetch_line() --- htdocs/expedition/class/expedition.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 13ddccdd896..915177164ac 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -602,9 +602,7 @@ class Expedition extends CommonObject $this->fk_incoterms = $obj->fk_incoterms; $this->location_incoterms = $obj->location_incoterms; $this->libelle_incoterms = $obj->libelle_incoterms; - - $this->lines = array(); - + $this->db->free($result); if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; @@ -1381,6 +1379,7 @@ class Expedition extends CommonObject // phpcs:enable global $conf, $mysoc; // TODO: recuperer les champs du document associe a part + $this->lines=array(); $sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type"; $sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva"; From 2eaa9103367a9838cf148747f049a92eff75be96 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 Sep 2019 12:32:27 +0200 Subject: [PATCH 4/6] Update project.class.php --- htdocs/projet/class/project.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index cbed549ac29..7e64f9a5011 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1691,7 +1691,8 @@ class Project extends CommonObject $sql.= " WHERE id=".$elementSelectId; }else { - $sql.= sprintf(" SET %s=NULL WHERE rowid=%s", $projectfield, $elementSelectId); + $sql.= " SET ".$projectfield."=NULL"; + $sql.= " WHERE rowid=".$elementSelectId; } dol_syslog(get_class($this)."::remove_element", LOG_DEBUG); From 34aa64bae21e92d215bcf88b38f3c9ef467911b6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 Sep 2019 12:36:15 +0200 Subject: [PATCH 5/6] Update element.php --- htdocs/projet/element.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index aea1626e67b..1b1ca30f161 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -512,9 +512,9 @@ if ($action=="addelement") elseif ($action == "unlink") { - $tablename = GETPOST("tablename"); - $projectField = GETPOST("projectfield"); - $elementselectid = GETPOST("elementselect"); + $tablename = GETPOST("tablename", "aZ09"); + $projectField = GETPOST("projectfield", "aZ09"); + $elementselectid = GETPOST("elementselect", "int"); $result = $object->remove_element($tablename, $elementselectid, $projectField); if ($result < 0) @@ -890,7 +890,7 @@ foreach ($listofreferent as $key => $value) { if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true { - print sprintf('', $_SERVER["PHP_SELF"], $projectid, $tablename, $element->id, $project_field?: 'fk_projet'); + print ''; print img_picto($langs->trans('Unlink'), 'unlink'); print ''; } From 412e0f193be724c131a8720aa31ebc95f03660b3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 Sep 2019 12:36:53 +0200 Subject: [PATCH 6/6] Update element.php --- htdocs/projet/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 1b1ca30f161..97e99c93370 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -890,7 +890,7 @@ foreach ($listofreferent as $key => $value) { if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true { - print ''; + print ''; print img_picto($langs->trans('Unlink'), 'unlink'); print ''; }