Skip to content

Commit

Permalink
allow to remove one custom referent in the project.
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
laudeco committed Sep 23, 2019
1 parent 9bf387d commit b4f31d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions htdocs/projet/class/project.class.php
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/projet/element.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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 '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . '&action=unlink&tablename=' . $tablename . '&elementselect=' . $element->id . '" class="reposition">';
print sprintf('<a href="%s?id=%s&action=unlink&tablename=%s&elementselect=%s&projectfield=%s" class="reposition">', $_SERVER["PHP_SELF"], $projectid, $tablename, $element->id, $project_field?: 'fk_projet');
print img_picto($langs->trans('Unlink'), 'unlink');
print '</a>';
}
Expand Down

0 comments on commit b4f31d6

Please sign in to comment.