Source
xxxxxxxxxx
$table_names = ['trends', 'trends_uint', 'history_text', 'history_log', 'history_uint', 'history_str',
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* Class to perform low level item related actions.
*/
class CItemManager {
/**
* Deletes items and related entities without permission check.
*
* @param array $itemids
*/
public static function delete(array $itemids) {
global $DB;
$del_itemids = [];
$del_ruleids = [];
$del_item_prototypeids = [];
// Selecting all inherited items.
$parent_itemids = array_flip($itemids);
do {
$db_items = DBselect(
'SELECT i.itemid FROM items i WHERE '.dbConditionInt('i.templateid', array_keys($parent_itemids))
);
$del_itemids += $parent_itemids;
$parent_itemids = [];
while ($db_item = DBfetch($db_items)) {
if (!array_key_exists($db_item['itemid'], $del_itemids)) {
$parent_itemids[$db_item['itemid']] = true;
}
}
} while ($parent_itemids);
// Selecting all dependent items.
// Note: We are not separating normal from discovered items at this point.
$dep_itemids = [
ZBX_FLAG_DISCOVERY_NORMAL => $del_itemids,
ZBX_FLAG_DISCOVERY_RULE => [],
ZBX_FLAG_DISCOVERY_CREATED => [],
ZBX_FLAG_DISCOVERY_PROTOTYPE => []
];