Index: include/classes/api/services/CItemGeneral.php =================================================================== --- include/classes/api/services/CItemGeneral.php (revision 59866) +++ include/classes/api/services/CItemGeneral.php (working copy) @@ -566,53 +566,16 @@ * @param type $checkMax */ protected function checkUseInGraphAxis(array $itemids, $checkMax = false) { - if ($checkMax) { - $filter = array('ymax_itemid' => $itemids); - $itemIdColumn = 'ymax_itemid'; - $typeColumn = 'ymax_type'; - } - else { - $filter = array('ymin_itemid' => $itemids); - $itemIdColumn = 'ymin_itemid'; - $typeColumn = 'ymin_type'; - } + $itemIdColumn = $checkMax ? 'ymax_itemid' : 'ymin_itemid'; + $error = $checkMax + ? 'Could not delete these items because some of them are used as MAX values for graphs.' + : 'Could not delete these items because some of them are used as MIN values for graphs.'; - // make it work for both graphs and graph prototypes - $filter['flags'] = array( - ZBX_FLAG_DISCOVERY_PROTOTYPE, - ZBX_FLAG_DISCOVERY_NORMAL, - ZBX_FLAG_DISCOVERY_CREATED - ); + $result = DBselect('SELECT NULL FROM graphs WHERE '.dbConditionInt($itemIdColumn, $itemids), 1); - // check if the items are used in Y axis min/max values in any graphs - $graphs = API::Graph()->get(array( - 'output' => array($itemIdColumn, $typeColumn, 'graphtype'), - 'filter' => $filter - )); - - $updateGraphs = array(); - foreach ($graphs as &$graph) { - // check if Y type is actually set to GRAPH_YAXIS_TYPE_ITEM_VALUE - if ($graph[$typeColumn] == GRAPH_YAXIS_TYPE_ITEM_VALUE) { - if ($checkMax) { - self::exception(ZBX_API_ERROR_PARAMETERS, 'Could not delete these items because some of them are used as MAX values for graphs.'); - } - else { - self::exception(ZBX_API_ERROR_PARAMETERS, 'Could not delete these items because some of them are used as MIN values for graphs.'); - } - } - else { - $graph[$itemIdColumn] = null; - $updateGraphs[] = $graph; - } + if (DBfetch($result)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); } - - // if there are graphs, that have an y*_itemid column set, but the - // y*_type column is not set to GRAPH_YAXIS_TYPE_ITEM_VALUE, set y*_itemid to NULL. - // Otherwise we won't be able to delete them. - if ($updateGraphs) { - API::Graph()->update($updateGraphs); - } } /**