From 30ff358dbce214099ff687b0bfbfa5c123f3bf6d Mon Sep 17 00:00:00 2001 From: Maximilian Neu Date: Fri, 17 Apr 2026 10:11:35 +0200 Subject: [PATCH 1/2] Fix responsible group visibility after injection --- CHANGELOG.md | 1 + inc/commoninjectionlib.class.php | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4370626e..bb8567c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix crash when injection model has no mandatory fields defined - Fix models created on parent entities can't be used on child entites +- Fix responsible group injection payload normalization so group remains visible in GLPI after import ## [2.15.4] - 2026-03-16 diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index 8980b4c1..ba9c33cb 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -1688,16 +1688,25 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr $toinject[$key] = $value; } - // handle new format for group type specification - // restricting to group_item relations only - if (($key === "groups_id_tech" || $key === "groups_id" || $key === "groups_id_normal") && $option['table'] == getTableForItemType(Group::class) && !empty($option) && isset($option['joinparams']['beforejoin']['table']) && $option['joinparams']['beforejoin']['table'] === getTableForItemType(Group_Item::class) && isset($option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'])) { - $group_type = $option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type']; - // depending on the type, set the correct field (_groups_id_tech => array or _groups_id => array) - // and unset the old one (groups_id_tech => int or groups_id => int or groups_id_normal => int) - if ($group_type == Group_Item::GROUP_TYPE_TECH) { - $toinject["_groups_id_tech"] = [$value]; + // Normalize group assignment fields to GLPI relation payload keys. + // Some search options do not expose a stable joinparams shape, but GLPI + // still expects _groups_id/_groups_id_tech arrays when saving equipment groups. + if ( + in_array($key, ['groups_id_tech', 'groups_id', 'groups_id_normal'], true) + && !empty($option) + && isset($option['table']) + && $option['table'] === getTableForItemType(Group::class) + ) { + $group_type = null; + if (isset($option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'])) { + $group_type = $option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type']; + } + + // Keep explicit technical group semantics from key or metadata. + if ($key === 'groups_id_tech' || $group_type == Group_Item::GROUP_TYPE_TECH) { + $toinject['_groups_id_tech'] = [$value]; } else { - $toinject["_groups_id"] = [$value]; + $toinject['_groups_id'] = [$value]; } unset($toinject[$key]); } From 6d2fcae5b2544c3d9b726555515312ff3b3f0e7b Mon Sep 17 00:00:00 2001 From: Maximilian Neu Date: Fri, 17 Apr 2026 10:33:05 +0200 Subject: [PATCH 2/2] Use normalized group value in payload --- inc/commoninjectionlib.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index ba9c33cb..991effa6 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -1697,6 +1697,7 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr && isset($option['table']) && $option['table'] === getTableForItemType(Group::class) ) { + $normalized_value = $toinject[$key]; $group_type = null; if (isset($option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'])) { $group_type = $option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type']; @@ -1704,9 +1705,9 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr // Keep explicit technical group semantics from key or metadata. if ($key === 'groups_id_tech' || $group_type == Group_Item::GROUP_TYPE_TECH) { - $toinject['_groups_id_tech'] = [$value]; + $toinject['_groups_id_tech'] = [$normalized_value]; } else { - $toinject['_groups_id'] = [$value]; + $toinject['_groups_id'] = [$normalized_value]; } unset($toinject[$key]); }