/** Process CVS file contents with requirements into TL * and creates an array with reports * @return array_of_strings list of particular REQ data with resolution comment * * **/ function executeImportedReqs(&$db, $arrImportSource, $map_cur_reqdoc_id, $conflictSolution, $emptyScope, $idSRS, $tprojectID, $userID) { define('SKIP_CONTROLS', 1); $req_mgr = new requirement_mgr($db); $import_status = null; $field_size = config_get('field_size'); foreach ($arrImportSource as $data) { $docID = trim_and_limit($data['docid'], $field_size->req_docid); $title = trim_and_limit($data['title'], $field_size->req_title); $scope = $data['description']; $type = $data['type']; $status = $data['status']; $expected_coverage = $data['expected_coverage']; $node_order = $data['node_order']; if ($emptyScope == 'on' && empty($scope)) { // skip rows with empty scope $import_status = lang_get('req_import_result_skipped'); } else { $crash = $map_cur_reqdoc_id && array_search($docID, $map_cur_reqdoc_id); if ($crash) { // process conflict according to choosen solution tLog('Conflict found. solution: ' . $conflictSolution); $import_status['msg'] = 'Error'; if ($conflictSolution == 'overwrite') { $item = current($req_mgr->getByDocID($docID, $tprojectID)); $last_version = $req_mgr->get_last_version_info($item['id']); // BUGID 0003745: CSV Requirements Import Updates Frozen Requirement if ($last_version['is_open'] == 1) { $op = $req_mgr->update($item['id'], $last_version['id'], $docID, $title, $scope, $userID, $status, $type, $expected_coverage, $node_order, SKIP_CONTROLS); if ($op['status_ok']) { $import_status['msg'] = lang_get('req_import_result_overwritten'); } } else { $import_status['msg'] = lang_get('req_import_result_skipped_is_frozen'); } } elseif ($conflictSolution == 'skip') { // no work $import_status['msg'] = lang_get('req_import_result_skipped'); } } else { // no conflict - just add requirement $import_status = $req_mgr->create($idSRS, $docID, $title, $scope, $userID, $status, $type, $expected_coverage, $node_order); } $arrImport[] = array('doc_id' => $docID, 'title' => $title, 'import_status' => $import_status['msg']); } } return $arrImport; }
/** * create a req spec tree on system from $xml data * * * */ function createFromXML($xml, $tproject_id, $parent_id, $author_id, $filters = null, $options = null) { $user_feedback = null; $items = $this->xmlToMapReqSpec($xml); $req_mgr = new requirement_mgr($this->db); $copy_reqspec = null; $copy_req = null; $getOptions = array('output' => 'minimun'); $has_filters = !is_null($filters); $my['options'] = array('actionOnDuplicate' => "update"); $my['options'] = array_merge($my['options'], (array) $options); $labels = array('import_req_spec_created' => '', 'import_req_spec_skipped' => '', 'import_req_spec_updated' => '', 'import_req_spec_ancestor_skipped' => '', 'import_req_created' => '', 'import_req_skipped' => '', 'import_req_updated' => ''); foreach ($labels as $key => $dummy) { $labels[$key] = lang_get($key); } if ($has_filters) { if (!is_null($filters['requirements'])) { foreach ($filters['requirements'] as $reqspec_pos => $requirements_pos) { $copy_req[$reqspec_pos] = is_null($requirements_pos) ? null : array_keys($requirements_pos); } } } $loop2do = count($items); $container_id[0] = is_null($parent_id) || $parent_id == 0 ? $tproject_id : $parent_id; // items is an array of req. specs $skip_level = -1; for ($idx = 0; $idx < $loop2do; $idx++) { $rspec = $items[$idx]['req_spec']; $depth = $rspec['level']; if ($skip_level > 0 && $depth >= $skip_level) { $msgID = 'import_req_spec_ancestor_skipped'; $user_feedback[] = array('doc_id' => $rspec['doc_id'], 'title' => $rspec['title'], 'import_status' => sprintf($labels[$msgID], $rspec['doc_id'])); continue; } $req_spec_order = isset($rspec['node_order']) ? $rspec['node_order'] : 0; // 20100320 - // Check if req spec with same DOCID exists, inside container_id // If there is a hit // We will go in update // If Check fails, need to repeat check on WHOLE Testproject. // If now there is a HIT we can not import this branch // If Check fails => we can import creating a new one. // // Important thing: // Working in this way, i.e. doing check while walking the structure to import // we can end importing struct with 'holes'. // $check_in_container = $this->getByDocID($rspec['doc_id'], $tproject_id, $container_id[$depth], $getOptions); $skip_level = $depth + 1; $result['status_ok'] = 0; $msgID = 'import_req_spec_skipped'; if (is_null($check_in_container)) { $check_in_tproject = $this->getByDocID($rspec['doc_id'], $tproject_id, null, $getOptions); if (is_null($check_in_tproject)) { $msgID = 'import_req_spec_created'; $result = $this->create($tproject_id, $container_id[$depth], $rspec['doc_id'], $rspec['title'], $rspec['scope'], $rspec['total_req'], $author_id, $rspec['type'], $req_spec_order); } } else { $msgID = 'import_req_spec_updated'; $reqSpecID = key($check_in_container); $result = $this->update($reqSpecID, $rspec['doc_id'], $rspec['title'], $rspec['scope'], $rspec['total_req'], $author_id, $rspec['type'], $req_spec_order); $result['id'] = $reqSpecID; } $user_feedback[] = array('doc_id' => $rspec['doc_id'], 'title' => $rspec['title'], 'import_status' => sprintf($labels[$msgID], $rspec['doc_id'])); if ($result['status_ok']) { $skip_level = -1; $container_id[$depth + 1] = $reqSpecID = $result['id']; $reqSet = $items[$idx]['requirements']; $create_req = (!$has_filters || isset($copy_req[$idx])) && !is_null($reqSet); if ($create_req) { $items_qty = isset($copy_req[$idx]) ? count($copy_req[$idx]) : count($reqSet); $keys2insert = isset($copy_req[$idx]) ? $copy_req[$idx] : array_keys($reqSet); for ($jdx = 0; $jdx < $items_qty; $jdx++) { $req = $reqSet[$keys2insert[$jdx]]; // Check: // If item with SAME DOCID exists inside container // If there is a hit // We will follow user option: update,create new version // // If do not exist check must be repeated, but on WHOLE test project // If there is a hit -> we can not create // else => create // // // 20100321 - we do not manage yet user option $msgID = 'import_req_skipped'; $check_in_reqspec = $req_mgr->getByDocID($req['docid'], $tproject_id, $reqSpecID, $getOptions); if (is_null($check_in_reqspec)) { $check_in_tproject = $req_mgr->getByDocID($req['docid'], $tproject_id, null, $getOptions); if (is_null($check_in_tproject)) { $req_mgr->create($result['id'], $req['docid'], $req['title'], $req['description'], $author_id, $req['status'], $req['type'], $req['expected_coverage'], $req['node_order']); $msgID = 'import_req_created'; } } else { // function update($id,$version_id,$reqdoc_id,$title, $scope, $user_id, $status, $type, // $expected_coverage,$node_order=null,$skip_controls=0) // // Need to get Last Version no matter active or not. // What to do if is Frozen ??? -> now ignore and update anyway $reqID = key($check_in_reqspec); $last_version = $req_mgr->get_last_version_info($reqID); $result = $req_mgr->update($reqID, $last_version['id'], $req['docid'], $req['title'], $req['description'], $author_id, $req['status'], $req['type'], $req['expected_coverage'], $req['node_order']); $msgID = 'import_req_updated'; } } $user_feedback[] = array('doc_id' => $req['docid'], 'title' => $req['title'], 'import_status' => sprintf($labels[$msgID], $req['docid'])); } // if($create_req) } // if($result['status_ok']) } return $user_feedback; }