Source
<?php declare(strict_types = 0);
/*
** 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/>.
**/
abstract class CControllerPopupMassupdateAbstract extends CController {
/**
* Apply mass update changes for value maps.
*
* @throws Exception
*/
protected function updateValueMaps(array $hostids) {
$db_valuemaps = API::ValueMap()->get([
'output' => ['valuemapid', 'name', 'hostid'],
'hostids' => $hostids,
'preservekeys' => true
]);
$action = $this->getInput('valuemap_massupdate');
$ins_valuemaps = [];
$upd_valuemaps = [];
$del_valuemapids = [];
switch ($action) {
case ZBX_ACTION_ADD:
case ZBX_ACTION_REPLACE:
$valuemaps = array_column($this->getInput('valuemaps', []), null, 'name');
if (!$valuemaps) {
break;
}
if ($action == ZBX_ACTION_REPLACE || $this->hasInput('valuemap_update_existing')) {
foreach ($db_valuemaps as $db_valuemap) {
if (!array_key_exists($db_valuemap['name'], $valuemaps)) {
continue;
}
$upd_valuemaps [] = [
'valuemapid' => $db_valuemap['valuemapid'],
'mappings' => $valuemaps[$db_valuemap['name']]['mappings']
];
}
}
if ($action == ZBX_ACTION_ADD || $this->hasInput('valuemap_add_missing')) {
$host_valuemaps = [];
foreach ($db_valuemaps as $db_valuemap) {
$host_valuemaps[$db_valuemap['name']][] = $db_valuemap['hostid'];
}