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..991effa6 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -1688,16 +1688,26 @@ 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) + ) { + $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']; + } + + // 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'] = [$normalized_value]; } else { - $toinject["_groups_id"] = [$value]; + $toinject['_groups_id'] = [$normalized_value]; } unset($toinject[$key]); }