diff -ru ../zabbix24/include/classes/api/managers/CApplicationManager.php ./include/classes/api/managers/CApplicationManager.php --- ../zabbix24/include/classes/api/managers/CApplicationManager.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/managers/CApplicationManager.php 2016-02-13 19:09:09.218402157 +0100 @@ -229,7 +229,9 @@ $this->delete($emptyIds); } - $this->inherit($inheritedApps); + foreach (array_chunk($inheritedApps,10) as $inheritedAppChunk) { + $this->inherit($inheritedAppChunk); + } return true; } diff -ru ../zabbix24/include/classes/api/services/CDiscoveryRule.php ./include/classes/api/services/CDiscoveryRule.php --- ../zabbix24/include/classes/api/services/CDiscoveryRule.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CDiscoveryRule.php 2016-02-16 15:21:28.955112895 +0100 @@ -393,59 +393,46 @@ } } - // get child discovery rules - $parentItemids = $ruleids; - $childTuleids = array(); - do { - $dbItems = DBselect('SELECT i.itemid FROM items i WHERE '.dbConditionInt('i.templateid', $parentItemids)); - $parentItemids = array(); - while ($dbItem = DBfetch($dbItems)) { - $parentItemids[$dbItem['itemid']] = $dbItem['itemid']; - $childTuleids[$dbItem['itemid']] = $dbItem['itemid']; - } - } while (!empty($parentItemids)); - - $delRulesChilds = $this->get(array( - 'output' => API_OUTPUT_EXTEND, - 'itemids' => $childTuleids, - 'nopermissions' => true, - 'preservekeys' => true, - 'selectHosts' => array('name') - )); - - $delRules = array_merge($delRules, $delRulesChilds); - $ruleids = array_merge($ruleids, $childTuleids); - - $iprototypeids = array(); - $dbItems = DBselect( - 'SELECT i.itemid'. - ' FROM item_discovery id,items i'. - ' WHERE i.itemid=id.itemid'. - ' AND '.dbConditionInt('parent_itemid', $ruleids) - ); - while ($item = DBfetch($dbItems)) { - $iprototypeids[$item['itemid']] = $item['itemid']; + $deletedRuleIds=$ruleids; + // recurse into child discovery rules + $dbItems = DBselect('SELECT i.itemid FROM items i WHERE '.dbConditionInt('i.templateid', $ruleids)); + $childItemids = DBfetchColumn($dbItems,'itemid'); + foreach (array_chunk($childItemids,10) as $childItemidsChunk) { + $deletedRuleIds=array_merge($deletedRuleIds,$this->delete($childItemidsChunk,true)); } - if (!empty($iprototypeids)) { - if (!API::Itemprototype()->delete($iprototypeids, true)) { - self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete discovery rule')); + + foreach (array_chunk($ruleids,10) as $ruleids) { + $iprototypeids = array(); + $dbItems = DBselect( + 'SELECT i.itemid'. + ' FROM item_discovery id,items i'. + ' WHERE i.itemid=id.itemid'. + ' AND '.dbConditionInt('parent_itemid', $ruleids) + ); + while ($item = DBfetch($dbItems)) { + $iprototypeids[$item['itemid']] = $item['itemid']; + } + if (!empty($iprototypeids)) { + if (!API::Itemprototype()->delete($iprototypeids, true)) { + self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete discovery rule')); + } } - } - // delete host prototypes - $hostPrototypeIds = DBfetchColumn(DBselect( - 'SELECT hd.hostid'. - ' FROM host_discovery hd'. - ' WHERE '.dbConditionInt('hd.parent_itemid', $ruleids) - ), 'hostid'); - if ($hostPrototypeIds) { - if (!API::HostPrototype()->delete($hostPrototypeIds, true)) { - self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete host prototype.')); + // delete host prototypes + $hostPrototypeIds = DBfetchColumn(DBselect( + 'SELECT hd.hostid'. + ' FROM host_discovery hd'. + ' WHERE '.dbConditionInt('hd.parent_itemid', $ruleids) + ), 'hostid'); + if ($hostPrototypeIds) { + if (!API::HostPrototype()->delete($hostPrototypeIds, true)) { + self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete host prototype.')); + } } - } - // delete LLD rules - DB::delete('items', array('itemid' => $ruleids)); + // delete LLD rules + DB::delete('items', array('itemid' => $ruleids)); + } // TODO: remove info from API foreach ($delRules as $item) { @@ -453,7 +440,7 @@ info(_s('Deleted: Discovery rule "%1$s" on "%2$s".', $item['name'], $host['name'])); } - return array('ruleids' => $ruleids); + return array('ruleids' => $deletedRuleIds); } /** @@ -920,7 +907,8 @@ $insertItems = array(); $updateItems = array(); - foreach ($newItems as $newItem) { +// if order does not matter, array_shift can be replaced by array_pop which is faster, but reverses the order + while (($newItem=array_shift($newItems))!==null) { if (isset($newItem['itemid'])) { $updateItems[] = $newItem; } @@ -930,12 +918,19 @@ } } + $chunkedInsertItems=array_chunk($insertItems,10); unset($insertItems); + $chunkedUpdateItems=array_chunk($updateItems,10); unset($updateItems); + // save the new items - $this->createReal($insertItems); - $this->updateReal($updateItems); + foreach ($chunkedInsertItems as &$itemsChunk) { $this->createReal($itemsChunk); } unset($itemsChunk); + foreach ($chunkedUpdateItems as $itemsChunk) { $this->updateReal($itemsChunk); } // propagate the inheritance to the children - return $this->inherit(array_merge($updateItems, $insertItems)); + foreach ($chunkedInsertItems as $itemsChunk) { $this->inherit($itemsChunk); } + foreach ($chunkedUpdateItems as $itemsChunk) { $this->inherit($itemsChunk); } + + // inherit always returns true; + return true; } /** diff -ru ../zabbix24/include/classes/api/services/CHostPrototype.php ./include/classes/api/services/CHostPrototype.php --- ../zabbix24/include/classes/api/services/CHostPrototype.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CHostPrototype.php 2016-02-14 17:42:11.770416739 +0100 @@ -640,7 +640,7 @@ $insertHostPrototypes = array(); $updateHostPrototypes = array(); - foreach ($newHostPrototypes as $newHostPrototype) { + while (($newHostPrototype=array_shift($newHostPrototypes))!==null) { if (isset($newHostPrototype['hostid'])) { $updateHostPrototypes[] = $newHostPrototype; } @@ -649,17 +649,17 @@ } } + $chunkedInsertHostPrototypes=array_chunk($insertHostPrototypes,10); unset($insertHostPrototypes); + $chunkedUpdateHostPrototypes=array_chunk($updateHostPrototypes,10); unset($updateHostPrototypes); // save the new host prototypes - if (!zbx_empty($insertHostPrototypes)) { - $insertHostPrototypes = $this->createReal($insertHostPrototypes); - } + foreach ($chunkedInsertHostPrototypes as &$hostPrototypesChunk) { $this->createReal($hostPrototypesChunk); } unset($hostPrototypesChunk); + foreach ($chunkedUpdateHostPrototypes as $hostPrototypesChunk) { $this->updateReal($hostPrototypesChunk); } - if (!zbx_empty($updateHostPrototypes)) { - $updateHostPrototypes = $this->updateReal($updateHostPrototypes); - } + // propagate the inheritance to the children + foreach ($chunkedInsertHostPrototypes as $itemsChunk) { $this->inherit($itemsChunk); } + foreach ($chunkedUpdateHostPrototypes as $itemsChunk) { $this->inherit($itemsChunk); } - // propagate the inheritance to the children - return $this->inherit(array_merge($updateHostPrototypes, $insertHostPrototypes)); + return true; } @@ -924,18 +924,11 @@ $this->validateDelete($hostPrototypeIds, $nopermissions); // include child IDs - $parentHostPrototypeIds = $hostPrototypeIds; - $childHostPrototypeIds = array(); - do { - $query = DBselect('SELECT h.hostid FROM hosts h WHERE '.dbConditionInt('h.templateid', $parentHostPrototypeIds)); - $parentHostPrototypeIds = array(); - while ($hostPrototype = DBfetch($query)) { - $parentHostPrototypeIds[] = $hostPrototype['hostid']; - $childHostPrototypeIds[] = $hostPrototype['hostid']; - } - } while (!empty($parentHostPrototypeIds)); - - $hostPrototypeIds = array_merge($hostPrototypeIds, $childHostPrototypeIds); + $deletedHostPrototypeIds = $hostPrototypeIds; + $query = DBselect('SELECT h.hostid FROM hosts h WHERE '.dbConditionInt('h.templateid', $hostPrototypeIds)); + foreach (array_chunk(DBfetchColumn($query,'hostid'),10) as $chunk) { + $deletedHostPrototypeIds=array_merge($deletedHostPrototypeIds,$this->delete($chunk)); + } $deleteHostPrototypes = $this->get(array( 'hostids' => $hostPrototypeIds, @@ -970,7 +963,7 @@ info(_s('Deleted: Host prototype "%1$s" on "%2$s".', $hostProtototype['host'], $hostProtototype['parentHost']['host'])); } - return array('hostids' => $hostPrototypeIds); + return array('hostids' => $deletedHostPrototypeIds); } /** diff -ru ../zabbix24/include/classes/api/services/CHttpTest.php ./include/classes/api/services/CHttpTest.php --- ../zabbix24/include/classes/api/services/CHttpTest.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CHttpTest.php 2016-02-14 17:43:35.894410678 +0100 @@ -371,16 +371,11 @@ } } - $parentHttpTestIds = $httpTestIds; - $childHttpTestIds = array(); - do { - $dbTests = DBselect('SELECT ht.httptestid FROM httptest ht WHERE '.dbConditionInt('ht.templateid', $parentHttpTestIds)); - $parentHttpTestIds = array(); - while ($dbTest = DBfetch($dbTests)) { - $parentHttpTestIds[] = $dbTest['httptestid']; - $childHttpTestIds[$dbTest['httptestid']] = $dbTest['httptestid']; - } - } while (!empty($parentHttpTestIds)); + $deletedHttpTestIds = $httpTestIds; + $dbTests = DBselect('SELECT ht.httptestid FROM httptest ht WHERE '.dbConditionInt('ht.templateid', $httpTestIds)); + foreach (array_chunk(DBfetchColumn($dbTests,'httptestid'),10) as $chunk) { + $deletedTestIds=array_merge($deletedTestIds,$this->delete($chunk)); + } $options = array( 'httptestids' => $childHttpTestIds, @@ -429,7 +424,7 @@ ); } - return array('httptestids' => $httpTestIds); + return array('httptestids' => $deletedTestIds); } /** diff -ru ../zabbix24/include/classes/api/services/CItem.php ./include/classes/api/services/CItem.php --- ../zabbix24/include/classes/api/services/CItem.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CItem.php 2016-02-16 15:35:53.939030153 +0100 @@ -641,15 +641,12 @@ } // first delete child items - $parentItemIds = $itemIds; - do { - $dbItems = DBselect('SELECT i.itemid FROM items i WHERE '.dbConditionInt('i.templateid', $parentItemIds)); - $parentItemIds = array(); - while ($dbItem = DBfetch($dbItems)) { - $parentItemIds[] = $dbItem['itemid']; - $itemIds[$dbItem['itemid']] = $dbItem['itemid']; - } - } while ($parentItemIds); + $deletedItemIds = $itemIds; + $dbItems = DBselect('SELECT i.itemid FROM items i WHERE '.dbConditionInt('i.templateid', $itemIds)); + foreach (array_chunk(DBfetchColumn($dbItems,'itemid'),10) as $chunk) { + $deletedItemIds=array_merge($deletedItemIds,$this->delete($chunk)); + } + // delete graphs, leave if graph still have item $delGraphs = array(); @@ -734,7 +731,7 @@ info(_s('Deleted: Item "%1$s" on "%2$s".', $item['name'], $host['name'])); } - return array('itemids' => $itemIds); + return array('itemids' => $deletedItemIds); } public function syncTemplates($data) { @@ -778,7 +775,7 @@ $insertItems = array(); $updateItems = array(); - foreach ($newItems as $newItem) { + while (($newItem=array_shift($newItems))!==null) { if (isset($newItem['itemid'])) { $updateItems[] = $newItem; } @@ -788,19 +785,25 @@ } } + $chunkedInsertItems=array_chunk($insertItems,10); unset($insertItems); + $chunkedUpdateItems=array_chunk($updateItems,10); unset($updateItems); + // save the new items - if (!zbx_empty($insertItems)) { - self::validateInventoryLinks($insertItems, false); // false means 'create' - $this->createReal($insertItems); + foreach ($chunkedInsertItems as &$itemsChunk) { + self::validateInventoryLinks($itemsChunk, false); // false means 'create' + $this->createReal($itemsChunk); + } unset($itemsChunk); + + foreach ($chunkedUpdateItems as $itemsChunk) { + self::validateInventoryLinks($itemsChunk, true); // true means 'update' + $this->updateReal($itemsChunk); } - if (!zbx_empty($updateItems)) { - self::validateInventoryLinks($updateItems, true); // true means 'update' - $this->updateReal($updateItems); - } + // propagate the inheritance to the children + foreach ($chunkedInsertItems as $itemsChunk) { $this->inherit($itemsChunk); } + foreach ($chunkedUpdateItems as $itemsChunk) { $this->inherit($itemsChunk); } - // propagate the inheritance to the children - return $this->inherit(array_merge($updateItems, $insertItems)); + return true; } /** diff -ru ../zabbix24/include/classes/api/services/CItemPrototype.php ./include/classes/api/services/CItemPrototype.php --- ../zabbix24/include/classes/api/services/CItemPrototype.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CItemPrototype.php 2016-02-16 15:33:39.071194092 +0100 @@ -480,28 +480,11 @@ } // first delete child items - $parentItemids = $prototypeids; - $childPrototypeids = array(); - do { - $dbItems = DBselect('SELECT itemid FROM items WHERE '.dbConditionInt('templateid', $parentItemids)); - $parentItemids = array(); - while ($dbItem = DBfetch($dbItems)) { - $parentItemids[$dbItem['itemid']] = $dbItem['itemid']; - $childPrototypeids[$dbItem['itemid']] = $dbItem['itemid']; - } - } while ($parentItemids); - - $options = array( - 'output' => API_OUTPUT_EXTEND, - 'itemids' => $childPrototypeids, - 'nopermissions' => true, - 'preservekeys' => true, - 'selectHosts' => array('name') - ); - $delItemPrototypesChilds = $this->get($options); - - $delItemPrototypes = array_merge($delItemPrototypes, $delItemPrototypesChilds); - $prototypeids = array_merge($prototypeids, $childPrototypeids); + $deletedItemids = $prototypeids; + $dbItems = DBselect('SELECT itemid FROM items WHERE '.dbConditionInt('templateid', $prototypeids)); + foreach (array_chunk(DBfetchColumn($dbItems,'itemid'),10) as $chunk) { + $deletedItemids=array_merge($deletedItemids,$this->delete($chunk,true)); + } // delete graphs with this item prototype $delGraphPrototypes = API::GraphPrototype()->get(array( @@ -556,7 +539,7 @@ info(_s('Deleted: Item prototype "%1$s" on "%2$s".', $item['name'], $host['name'])); } - return array('prototypeids' => $prototypeids); + return array('prototypeids' => $deletedItemids); } public function syncTemplates($data) { @@ -608,13 +591,13 @@ // prepare the child items $newItems = $this->prepareInheritedItems($items, $hostids); - if (!$items) { + if (!$items || !$newItems) { return true; } $insertItems = array(); $updateItems = array(); - foreach ($newItems as $newItem) { + while (($newItem=array_shift($newItems))!==null) { if (isset($newItem['itemid'])) { unset($newItem['ruleid']); $updateItems[] = $newItem; @@ -627,12 +610,17 @@ } } + $chunkedInsertItems=array_chunk($insertItems,10); unset($insertItems); + $chunkedUpdateItems=array_chunk($updateItems,10); unset($updateItems); // save the new items - $this->createReal($insertItems); - $this->updateReal($updateItems); + foreach ($chunkedInsertItems as &$itemsChunk) { $this->createReal($itemsChunk); } unset($itemsChunk); + foreach ($chunkedUpdateItems as $itemsChunk) { $this->updateReal($itemsChunk); } // propagate the inheritance to the children - $this->inherit(array_merge($insertItems, $updateItems)); + foreach ($chunkedInsertItems as $itemsChunk) { $this->inherit($itemsChunk); } + foreach ($chunkedUpdateItems as $itemsChunk) { $this->inherit($itemsChunk); } + + return true; } protected function applyQueryOutputOptions($tableName, $tableAlias, array $options, array $sqlParts) { diff -ru ../zabbix24/include/classes/api/services/CTrigger.php ./include/classes/api/services/CTrigger.php --- ../zabbix24/include/classes/api/services/CTrigger.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CTrigger.php 2016-02-14 17:44:03.088409018 +0100 @@ -787,17 +787,12 @@ $this->validateDelete($triggerIds, $nopermissions); // get child triggers - $parentTriggerIds = $triggerIds; + $deletedTriggerIds = $triggerIds; - do { - $dbItems = DBselect('SELECT triggerid FROM triggers WHERE '.dbConditionInt('templateid', $parentTriggerIds)); - $parentTriggerIds = array(); - - while ($dbTrigger = DBfetch($dbItems)) { - $parentTriggerIds[] = $dbTrigger['triggerid']; - $triggerIds[] = $dbTrigger['triggerid']; - } - } while ($parentTriggerIds); + $dbItems = DBselect('SELECT triggerid FROM triggers WHERE '.dbConditionInt('templateid', $triggerIds)); + foreach (array_chunk(DBfetchColumn($dbItems,'triggerid'),10) as $chunk) { + $deletedTriggerIds=array_merge($deletedTriggerIds,$this->delete($chunk)); + } // select all triggers which are deleted (including children) $delTriggers = $this->get(array( @@ -819,7 +814,7 @@ // execute delete $this->deleteByIds($triggerIds); - return array('triggerids' => $triggerIds); + return array('triggerids' => $deletedTriggerIds); } /** diff -ru ../zabbix24/include/classes/api/services/CTriggerPrototype.php ./include/classes/api/services/CTriggerPrototype.php --- ../zabbix24/include/classes/api/services/CTriggerPrototype.php 2015-08-10 10:56:51.000000000 +0200 +++ ./include/classes/api/services/CTriggerPrototype.php 2016-02-14 17:44:31.225408261 +0100 @@ -587,19 +587,15 @@ } // get child trigger prototypes - $parentTriggerPrototypeIds = $triggerPrototypeIds; - do { - $dbTriggerPrototypes = DBselect( - 'SELECT triggerid'. - ' FROM triggers'. - ' WHERE '.dbConditionInt('templateid', $parentTriggerPrototypeIds) - ); - $parentTriggerPrototypeIds = array(); - while ($dbTriggerPrototype = DBfetch($dbTriggerPrototypes)) { - $parentTriggerPrototypeIds[] = $dbTriggerPrototype['triggerid']; - $triggerPrototypeIds[$dbTriggerPrototype['triggerid']] = $dbTriggerPrototype['triggerid']; - } - } while ($parentTriggerPrototypeIds); + $deletedTriggerPrototypeIds = $triggerPrototypeIds; + $dbTriggerPrototypes = DBselect( + 'SELECT triggerid'. + ' FROM triggers'. + ' WHERE '.dbConditionInt('templateid', $triggerPrototypeIds) + ); + foreach (array_chunk(DBfetchColumn($dbTriggerPrototypes,'triggerid'),10) as $chunk) { + $deletedTriggerPrototypeIds=array_merge($deletedTriggerPrototypeIds,$this->delete($chunk)); + } // delete triggers created from this prototype $createdTriggerIds = DBfetchColumn(DBselect( @@ -631,7 +627,7 @@ DB::delete('triggers', array('triggerid' => $triggerPrototypeIds)); - return array('triggerids' => $triggerPrototypeIds); + return array('triggerids' => $deletedTriggerPrototypeIds); } /** diff -ru ../zabbix24/include/func.inc.php ./include/func.inc.php --- ../zabbix24/include/func.inc.php 2015-08-10 10:56:50.000000000 +0200 +++ ./include/func.inc.php 2016-02-13 19:36:24.226899133 +0100 @@ -1903,6 +1903,9 @@ function info($msgs) { global $ZBX_MESSAGES; + static $messagecount=0; + + if ($messagecount>20) { return; } zbx_value2array($msgs); if (is_null($ZBX_MESSAGES)) { @@ -1910,7 +1913,9 @@ } foreach ($msgs as $msg) { array_push($ZBX_MESSAGES, array('type' => 'info', 'message' => $msg)); + $messagecount++; } + } function error($msgs) { diff -ru ../zabbix24/templates.php ./templates.php --- ../zabbix24/templates.php 2016-02-16 20:19:36.744856907 +0100 +++ ./templates.php 2016-02-16 16:09:54.236947698 +0100 @@ -695,4 +695,5 @@ $rusage['ru_utime.tv_sec'],$rusage['ru_utime.tv_usec'], $rusage['ru_stime.tv_sec'],$rusage['ru_stime.tv_usec'], $peakmem,$peakmem_real)); + require_once dirname(__FILE__).'/include/page_footer.php';