diff options
Diffstat (limited to 'ui/include/classes/api/managers/CHttpTestManager.php')
-rw-r--r-- | ui/include/classes/api/managers/CHttpTestManager.php | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/ui/include/classes/api/managers/CHttpTestManager.php b/ui/include/classes/api/managers/CHttpTestManager.php index 96c99232e26..d301b476a54 100644 --- a/ui/include/classes/api/managers/CHttpTestManager.php +++ b/ui/include/classes/api/managers/CHttpTestManager.php @@ -117,8 +117,6 @@ class CHttpTestManager { } unset($httptest); - self::getItemIds($httptests, true); - self::createItems($httptests); self::updateFields($httptests); self::updateSteps($httptests); @@ -163,8 +161,6 @@ class CHttpTestManager { DB::update('httptest', $upd_httptests); } - self::getItemIds($httptests, true); - self::updateItems($httptests, $db_httptests); self::updateFields($httptests, $db_httptests); self::updateSteps($httptests, $db_httptests); @@ -932,8 +928,6 @@ class CHttpTestManager { } unset($httptest); - self::getItemIds($httptests, true); - self::createStepItems($httptests, $stepids, $db_httptests); } @@ -1080,7 +1074,7 @@ class CHttpTestManager { 'status' => $item_status, 'tags' => $item_tags, 'delay' => $httptest['delay'], - 'templateid' => array_key_exists('templateid', $httptest) && $httptest['templateid'] != 0 + 'templateid' => array_key_exists('templateid', $httptest) ? self::$parent_itemids[$httptest['templateid']][$item_key] : 0 ] + $type_item; @@ -1363,11 +1357,10 @@ class CHttpTestManager { } } - self::getItemIds($httptests); - - $prepared_httptests = $this->prepareInheritedHttpTests($httptests, $template_hosts); - $inherited_httptests = $this->save($prepared_httptests); - $this->inherit($inherited_httptests); + self::$parent_itemids = self::getItemIds($httptests); + $preparedHttpTests = $this->prepareInheritedHttpTests($httptests, $template_hosts); + $inheritedHttpTests = $this->save($preparedHttpTests); + $this->inherit($inheritedHttpTests); return true; } @@ -1401,21 +1394,16 @@ class CHttpTestManager { } /** - * Index given web scenarios and their steps by httptest ID and item key. + * Get item IDs array of the given web scenarios and their steps indexed by httptest ID and item key. * * @param array $httptests - * @param bool $parents Index the parent httptests. + * + * @return array */ - private static function getItemIds(array $httptests, $parents = false): void { - $httptestids = $parents - ? array_column($httptests, 'templateid', 'templateid') - : array_column($httptests, 'httptestid'); + private static function getItemIds(array $httptests): array { + $httptest_itemids = []; - $httptestids = array_diff($httptestids, array_keys(self::$parent_itemids)); - - if (!$httptestids) { - return; - } + $httptestids = array_column($httptests, 'httptestid'); $result = DBselect( 'SELECT hti.httptestid,hti.itemid,i.key_'. @@ -1425,7 +1413,7 @@ class CHttpTestManager { ); while ($row = DBfetch($result)) { - self::$parent_itemids[$row['httptestid']][$row['key_']] = $row['itemid']; + $httptest_itemids[$row['httptestid']][$row['key_']] = $row['itemid']; } $result = DBselect( @@ -1437,8 +1425,10 @@ class CHttpTestManager { ); while ($row = DBfetch($result)) { - self::$parent_itemids[$row['httptestid']][$row['key_']] = $row['itemid']; + $httptest_itemids[$row['httptestid']][$row['key_']] = $row['itemid']; } + + return $httptest_itemids; } /** @@ -1642,8 +1632,9 @@ class CHttpTestManager { } /* - * Unset $http_tests and later put them back with actual httptestid as key right after creating/updating, - * since initially the array holds items with incremental keys. + * Unset $http_tests and (later) put it back with actual httptestid as a key right after creating/updating + * it. This is done in such a way because $http_tests array holds items with incremental keys which are not + * a real httptestids. */ unset($http_tests[$num]); } |