Source
* Update table "hosts_templates" and change objects of linked or unliked templates on target hosts or templates.
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Class containing methods for operations with hosts.
*/
abstract class CHostGeneral extends CHostBase {
public const ACCESS_RULES = [
'get' => ['min_user_type' => USER_TYPE_ZABBIX_USER],
'create' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN],
'update' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN],
'delete' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN],
'massadd' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN],
'massupdate' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN],
'massremove' => ['min_user_type' => USER_TYPE_ZABBIX_ADMIN]
];
protected function checkGroups(array $hosts, ?array $db_hosts = null, ?string $path = null,
?array $group_indexes = null): void {
$id_field_name = $this instanceof CTemplate ? 'templateid' : 'hostid';
$ins_group_indexes = [];
foreach ($hosts as $i1 => $host) {
if (!array_key_exists('groups', $host)) {
continue;
}
$db_groups = $db_hosts !== null
? array_column($db_hosts[$host[$id_field_name]]['groups'], null, 'groupid')
: [];
foreach ($host['groups'] as $i2 => $group) {
if (array_key_exists($group['groupid'], $db_groups)) {
unset($db_groups[$group['groupid']]);
}
else {
$ins_group_indexes[$group['groupid']][$i1] = $i2;
}
}
}
if (!$ins_group_indexes) {
return;
}
$entity = $this instanceof CTemplate ? API::TemplateGroup() : API::HostGroup();
$db_groups = $entity->get([
'output' => [],