Source
xxxxxxxxxx
protected function compareByStructure(array $structure, array $before, array $after, array $options): array {
<?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/>.
**/
/**
* Class for preparing difference between import file and system.
*/
class CConfigurationImportcompare {
/**
* @var array
*/
protected $options;
/**
* @var array shows which elements in import array tree contains uuid
*/
protected $uuid_structure;
/**
* @var array contains unique fields path for import entities
*/
protected $unique_fields_keys_by_type;
/**
* CConfigurationImportcompare constructor.
*
* @param array $options import options "createMissing", "updateExisting" and "deleteMissing"
*/
public function __construct(array $options) {
$this->uuid_structure = [
'template_groups' => [],
'host_groups' => [],
'templates' => [
'items' => [
'triggers' => []
],
'discovery_rules' => [
'item_prototypes' => [
'trigger_prototypes' => []
],
'trigger_prototypes' => [],
'graph_prototypes' => [],
'host_prototypes' => []
],
'dashboards' => [],
'httptests' => [],
'valuemaps' => []
],
'triggers' => [],
'graphs' => []
];
$this->unique_fields_keys_by_type = [
'template_groups' => ['name'],
'host_groups' => ['name'],
'templates' => ['template'],
'items' => ['name', 'key'],
'triggers' => ['name', 'expression', 'recovery_expression'],
'dashboards' => ['name'],
'httptests' => ['name'],
'valuemaps' => ['name'],
'discovery_rules' => ['name', 'key'],
'item_prototypes' => ['name', 'key'],
'trigger_prototypes' => ['name', 'expression', 'recovery_expression'],
'graph_prototypes' => ['name', ['graph_items' => ['numeric_keys' => ['item' => 'host']]]],
'host_prototypes' => ['host'],
'graphs' => ['name', ['graph_items' => ['numeric_keys' => ['item' => 'host']]]]
];
$this->options = $options;
}
/**
* Performs comparison of import and export arrays and returns combined array that shows what was changed.
*
* @param array $export data exported from current system
* @param array $import data from import file
*
* @return array