@@ -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