From b4f31d61fa85af43224103cbcde9910e257ccb75 Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Mon, 23 Sep 2019 17:36:18 +0200 Subject: [PATCH] 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 2261e06219b61..cbed549ac2908 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1676,9 +1676,11 @@ public function update_element($tableName, $elementSelectId) * * @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 @@ public function remove_element($tableName, $elementSelectId) { $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 4f5af0ca94f92..aea1626e67bfb 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -513,9 +513,10 @@ { $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 @@ { 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 ''; }