Skip to content

Commit 4f7d9ee

Browse files
PR : Fix responsible group visibility after injection (#607)
* Fix responsible group visibility after injection * Use normalized group value in payload
1 parent 873b0f9 commit 4f7d9ee

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fix crash when injection model has no mandatory fields defined
1313
- Fix models created on parent entities can't be used on child entites
14+
- Fix responsible group injection payload normalization so group remains visible in GLPI after import
1415

1516
## [2.15.4] - 2026-03-16
1617

inc/commoninjectionlib.class.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,16 +1688,26 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr
16881688
$toinject[$key] = $value;
16891689
}
16901690

1691-
// handle new format for group type specification
1692-
// restricting to group_item relations only
1693-
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'])) {
1694-
$group_type = $option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'];
1695-
// depending on the type, set the correct field (_groups_id_tech => array or _groups_id => array)
1696-
// and unset the old one (groups_id_tech => int or groups_id => int or groups_id_normal => int)
1697-
if ($group_type == Group_Item::GROUP_TYPE_TECH) {
1698-
$toinject["_groups_id_tech"] = [$value];
1691+
// Normalize group assignment fields to GLPI relation payload keys.
1692+
// Some search options do not expose a stable joinparams shape, but GLPI
1693+
// still expects _groups_id/_groups_id_tech arrays when saving equipment groups.
1694+
if (
1695+
in_array($key, ['groups_id_tech', 'groups_id', 'groups_id_normal'], true)
1696+
&& !empty($option)
1697+
&& isset($option['table'])
1698+
&& $option['table'] === getTableForItemType(Group::class)
1699+
) {
1700+
$normalized_value = $toinject[$key];
1701+
$group_type = null;
1702+
if (isset($option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'])) {
1703+
$group_type = $option['joinparams']['beforejoin']['joinparams']['condition']['NEWTABLE.type'];
1704+
}
1705+
1706+
// Keep explicit technical group semantics from key or metadata.
1707+
if ($key === 'groups_id_tech' || $group_type == Group_Item::GROUP_TYPE_TECH) {
1708+
$toinject['_groups_id_tech'] = [$normalized_value];
16991709
} else {
1700-
$toinject["_groups_id"] = [$value];
1710+
$toinject['_groups_id'] = [$normalized_value];
17011711
}
17021712
unset($toinject[$key]);
17031713
}

0 commit comments

Comments
 (0)