/** * remove Hosts from HostGroups. All Hosts are removed from all HostGroups. * * @param array $data * @param array $data['hostids'] * @param array $data['groupids'] * @param array $data['templateids'] * @param array $data['macroids'] * @return array */ public static function massRemove($data) { $hostids = zbx_toArray($data['hostids']); try { self::BeginTransaction(__METHOD__); $options = array('hostids' => $hostids, 'editable' => 1, 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $upd_hosts = self::get($options); foreach ($hostids as $hostid) { if (!isset($upd_hosts[$hostid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } if (isset($data['groupids'])) { $options = array('hostids' => $hostids, 'groupids' => zbx_toArray($data['groupids'])); $result = CHostGroup::massRemove($options); if (!$result) { self::exception(); } } if (isset($data['templateids'])) { $options = array('hostids' => $hostids, 'templateids' => zbx_toArray($data['templateids'])); $result = CTemplate::massRemove($options); if (!$result) { self::exception(); } } if (isset($data['macros'])) { $options = array('hostids' => $hostids, 'macros' => zbx_toArray($data['macros'])); $result = CUserMacro::massRemove($options); if (!$result) { self::exception(); } } self::EndTransaction(true, __METHOD__); return array('hostids' => $hostids); } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }