diff options
Diffstat (limited to 'ui/include/classes/api/services/CHostGeneral.php')
-rw-r--r-- | ui/include/classes/api/services/CHostGeneral.php | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/ui/include/classes/api/services/CHostGeneral.php b/ui/include/classes/api/services/CHostGeneral.php index ea88a89932a..7fb4847e1bf 100644 --- a/ui/include/classes/api/services/CHostGeneral.php +++ b/ui/include/classes/api/services/CHostGeneral.php @@ -93,12 +93,32 @@ abstract class CHostGeneral extends CHostBase { $allHostIds = array_merge($hostIds, $templateIds); // add groups - if (!empty($data['groups'])) { - API::HostGroup()->massAdd([ - 'hosts' => $data['hosts'], - 'templates' => $data['templates'], - 'groups' => $data['groups'] - ]); + if (array_key_exists('groups', $data) && $data['groups']) { + $options = ['groups' => $data['groups']]; + + if ($data['hosts']) { + $options += [ + 'hosts' => array_map( + static function($host) { + return array_intersect_key($host, array_flip(['hostid'])); + }, + $data['hosts'] + ) + ]; + } + + if ($data['templates']) { + $options += [ + 'templates' => array_map( + static function($template) { + return array_intersect_key($template, array_flip(['templateid'])); + }, + $data['templates'] + ) + ]; + } + + API::HostGroup()->massAdd($options); } // link templates @@ -178,7 +198,17 @@ abstract class CHostGeneral extends CHostBase { } if (isset($data['groupids'])) { - API::HostGroup()->massRemove($data); + $options = ['groupids' => $data['groupids']]; + + if ($data['hostids']) { + $options['hostids'] = $data['hostids']; + } + + if ($data['templateids']) { + $options['templateids'] = $data['templateids']; + } + + API::HostGroup()->massRemove($options); } return [$this->pkOption() => $data[$this->pkOption()]]; |