From 7b53d091ab076388c745d736d53c73895193a2ac Mon Sep 17 00:00:00 2001 From: heuj <58398276+heuj@users.noreply.github.com> Date: Sat, 24 Oct 2020 18:00:08 +0200 Subject: [PATCH] Ticket-8687: TC-Req assignment while proj copy updated Updated pull request #232 As explained in Ticket-8687: $mappings array consists out of subarrays (at least [0]), proposed approach uses LUT to store in which subarray $reqID can be found. Use this information to find req-tc mapping later. Tested with multiple reqSpecs at same level and w/ nested specs. --- lib/functions/testcase.class.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/functions/testcase.class.php b/lib/functions/testcase.class.php index f140b939db..067ba6616b 100644 --- a/lib/functions/testcase.class.php +++ b/lib/functions/testcase.class.php @@ -8656,11 +8656,20 @@ function copyReqVersionLinksTo($source,$dest,$mappings,$userID) { } $itemSet = $reqMgr->getGoodForTCVersion($source['version_id']); - if( !is_null($itemSet) ) { + //Ticket-8687 create LUT: in which subarray of $mappings can the $reqID be found? + $lut=array(); + foreach ($mappings as $key=>$value){ + if (isset($value['req'])) { + foreach ($value['req'] as $rkey=>$rvalue){ + $lut[$rkey]=$key; + } + } + } + $reqSet = null; - $reqVerSet = null; + $reqVerSet = null; $loop2do=count($itemSet); for($idx=0; $idx < $loop2do; $idx++) { @@ -8668,15 +8677,17 @@ function copyReqVersionLinksTo($source,$dest,$mappings,$userID) { $reqID = $itemSet[$idx]['req_id']; $reqVerID = $itemSet[$idx]['req_version_id']; - if( isset($mappings['req'][$reqID]) ) { - $reqSet[$idx] = $mappings['req'][$reqID]; - $reqVerSet[$idx] = $mappings['req_version'][$reqVerID]; + //Ticket-8687: check if $reqID is in LUT created above and make use of it in case + if( isset($lut[$reqID]) ) { + $ind=$lut[$reqID]; + $reqSet[$idx] = $mappings[$ind]['req'][$reqID]; + $reqVerSet[$idx] = $mappings[$ind]['req_version'][$reqVerID]; } else { $reqSet[$idx] = $reqID; - $reqVerSet[$idx] = $reqVerID; + $reqVerSet[$idx] = $reqVerID; } - $reqIdCard = array('id' => $reqSet[$idx], + $reqIdCard = array('id' => $reqSet[$idx], 'version_id' => $reqVerSet[$idx]); $reqMgr->assignReqVerToTCVer($reqIdCard, $dest, $userID); }