/** * write execution result to DB * * @param resource &$db reference to database handler * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id * * @internal Revisions: * * * 20100522 - BUGID 3479 - Bulk Execution - Custom Fields Bulk Assignment */ function write_execution(&$db, &$exec_signature, &$exec_data, $map_last_exec) { $executions_table = DB_TABLE_PREFIX . 'executions'; $resultsCfg = config_get('results'); // $bugInterfaceOn = config_get('bugInterfaceOn'); $db_now = $db->db_now(); $cfield_mgr = new cfield_mgr($db); $cf_prefix = $cfield_mgr->get_name_prefix(); $len_cfp = tlStringLen($cf_prefix); $cf_nodeid_pos = 4; $bulk_notes = ''; $ENABLED = 1; $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase'); $has_custom_fields = is_null($cf_map) ? 0 : 1; // extract custom fields id. $map_nodeid_array_cfnames = null; foreach ($exec_data as $input_name => $value) { if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) { $dummy = explode('_', $input_name); $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name; } } if (isset($exec_data['do_bulk_save'])) { // create structure to use common algoritm $item2loop = $exec_data['status']; $is_bulk_save = 1; $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes'])); } else { $item2loop = $exec_data['save_results']; $is_bulk_save = 0; } foreach ($item2loop as $tcversion_id => $val) { $tcase_id = $exec_data['tc_version'][$tcversion_id]; $current_status = $exec_data['status'][$tcversion_id]; $version_number = $exec_data['version_number'][$tcversion_id]; $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE; if ($has_been_executed) { $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id])); $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data['status'][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}" . ")"; $db->exec_query($sql); // at least for Postgres DBMS table name is needed. $execution_id = $db->insert_id($executions_table); if ($has_custom_fields) { // test useful when doing bulk update, because some type of custom fields // like checkbox can not exist on exec_data. => why ?? // $hash_cf = null; $access_key = $is_bulk_save ? 0 : $tcase_id; if (isset($map_nodeid_array_cfnames[$access_key])) { foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) { $hash_cf[$cf_v] = $exec_data[$cf_v]; } } $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map); } } } }
/** * write execution result to DB * * @param resource &$db reference to database handler * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id * * @internal revisions * */ function write_execution(&$db, &$exec_signature, &$exec_data) { $executions_table = DB_TABLE_PREFIX . 'executions'; $resultsCfg = config_get('results'); $execCfg = config_get('exec_cfg'); $db_now = $db->db_now(); $cfield_mgr = new cfield_mgr($db); $cf_prefix = $cfield_mgr->get_name_prefix(); $len_cfp = tlStringLen($cf_prefix); $cf_nodeid_pos = 4; $bulk_notes = ''; $ENABLED = 1; $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase'); $has_custom_fields = is_null($cf_map) ? 0 : 1; // extract custom fields id. $map_nodeid_array_cfnames = null; foreach ($exec_data as $input_name => $value) { if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) { $dummy = explode('_', $input_name); $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name; } } if (isset($exec_data['do_bulk_save'])) { // create structure to use common algoritm $item2loop = $exec_data['status']; $is_bulk_save = 1; $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes'])); } else { $item2loop = $exec_data['save_results']; $is_bulk_save = 0; } foreach ($item2loop as $tcversion_id => $val) { $tcase_id = $exec_data['tc_version'][$tcversion_id]; $current_status = $exec_data['status'][$tcversion_id]; $version_number = $exec_data['version_number'][$tcversion_id]; $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE; if ($has_been_executed) { $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id])); $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id,execution_duration)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data['status'][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}"; if (trim($exec_data['execution_duration']) == '') { $dura = 'NULL '; } else { $dura = floatval($exec_data['execution_duration']); } $sql .= ',' . $dura . ")"; $db->exec_query($sql); // at least for Postgres DBMS table name is needed. $execution_id = $db->insert_id($executions_table); if ($has_custom_fields) { // test useful when doing bulk update, because some type of custom fields // like checkbox can not exist on exec_data. => why ?? // $hash_cf = null; $access_key = $is_bulk_save ? 0 : $tcase_id; if (isset($map_nodeid_array_cfnames[$access_key])) { foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) { $hash_cf[$cf_v] = $exec_data[$cf_v]; } } $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map); } // 20140412 $hasMoreData = new stdClass(); $hasMoreData->step_notes = isset($exec_data['step_notes']); $hasMoreData->step_status = isset($exec_data['step_status']); $hasMoreData->nike = $execCfg->steps_exec && ($hasMoreData->step_notes || $hasMoreData->step_status); if ($hasMoreData->nike) { $target = DB_TABLE_PREFIX . 'execution_tcsteps'; $key2loop = array_keys($exec_data['step_notes']); foreach ($key2loop as $step_id) { $doIt = !is_null($exec_data['step_notes'][$step_id]) && trim($exec_data['step_notes'][$step_id]) != '' || $exec_data['step_status'][$step_id] != $resultsCfg['status_code']['not_run']; if ($doIt) { $sql = " INSERT INTO {$target} (execution_id,tcstep_id,notes"; $values = " VALUES ( {$execution_id}, {$step_id}," . "'" . $db->prepare_string($exec_data['step_notes'][$step_id]) . "'"; $status = strtolower(trim($exec_data['step_status'][$step_id])); $status = $status[0]; if ($status != $resultsCfg['status_code']['not_run']) { $sql .= ",status"; $values .= ",'" . $db->prepare_string($status) . "'"; } $sql .= ") " . $values . ")"; $db->exec_query($sql); } } } } } }
/** * write execution result to DB * * @param resource &$db reference to database handler * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id * * @internal revisions * */ function write_execution(&$db, &$exec_signature, &$exec_data, &$issueTracker) { static $docRepo; if (is_null($docRepo)) { $docRepo = tlAttachmentRepository::create($db); } $executions_table = DB_TABLE_PREFIX . 'executions'; $resultsCfg = config_get('results'); $execCfg = config_get('exec_cfg'); $db_now = $db->db_now(); $cfield_mgr = new cfield_mgr($db); $cf_prefix = $cfield_mgr->get_name_prefix(); $len_cfp = tlStringLen($cf_prefix); $cf_nodeid_pos = 4; $bulk_notes = ''; $ENABLED = 1; $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase'); $has_custom_fields = is_null($cf_map) ? 0 : 1; // extract custom fields id. $map_nodeid_array_cfnames = null; foreach ($exec_data as $input_name => $value) { if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) { $dummy = explode('_', $input_name); $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name; } } if (isset($exec_data['do_bulk_save'])) { // create structure to use common algoritm $item2loop = $exec_data['status']; $is_bulk_save = 1; $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes'])); $execStatusKey = 'status'; } else { $item2loop = $exec_data['save_results']; $is_bulk_save = 0; $execStatusKey = 'statusSingle'; } $addIssueOp = array('createIssue' => null, 'issueForStep' => null); foreach ($item2loop as $tcversion_id => $val) { $tcase_id = $exec_data['tc_version'][$tcversion_id]; $current_status = $exec_data[$execStatusKey][$tcversion_id]; $version_number = $exec_data['version_number'][$tcversion_id]; $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE; if ($has_been_executed) { $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id])); $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id,execution_duration)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data[$execStatusKey][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}"; $dura = 'NULL '; if (isset($exec_data['execution_duration'])) { if (trim($exec_data['execution_duration']) == '') { $dura = 'NULL '; } else { $dura = floatval($exec_data['execution_duration']); } } $sql .= ',' . $dura . ")"; $db->exec_query($sql); // at least for Postgres DBMS table name is needed. $execution_id = $db->insert_id($executions_table); $execSet[$tcversion_id] = $execution_id; if ($has_custom_fields) { // test useful when doing bulk update, because some type of custom fields // like checkbox can not exist on exec_data. => why ?? // $hash_cf = null; $access_key = $is_bulk_save ? 0 : $tcase_id; if (isset($map_nodeid_array_cfnames[$access_key])) { foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) { $hash_cf[$cf_v] = $exec_data[$cf_v]; } } $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map); } $hasMoreData = new stdClass(); $hasMoreData->step_notes = isset($exec_data['step_notes']); $hasMoreData->step_status = isset($exec_data['step_status']); $hasMoreData->nike = $execCfg->steps_exec && ($hasMoreData->step_notes || $hasMoreData->step_status); if ($hasMoreData->nike) { $target = DB_TABLE_PREFIX . 'execution_tcsteps'; $key2loop = array_keys($exec_data['step_notes']); foreach ($key2loop as $step_id) { $doIt = !is_null($exec_data['step_notes'][$step_id]) && trim($exec_data['step_notes'][$step_id]) != '' || $exec_data['step_status'][$step_id] != $resultsCfg['status_code']['not_run']; if ($doIt) { $sql = " INSERT INTO {$target} (execution_id,tcstep_id,notes"; $values = " VALUES ( {$execution_id}, {$step_id}," . "'" . $db->prepare_string($exec_data['step_notes'][$step_id]) . "'"; $status = strtolower(trim($exec_data['step_status'][$step_id])); $status = $status[0]; if ($status != $resultsCfg['status_code']['not_run']) { $sql .= ",status"; $values .= ",'" . $db->prepare_string($status) . "'"; } $sql .= ") " . $values . ")"; $db->exec_query($sql); $execution_tcsteps_id = $db->insert_id($target); // NOW MANAGE attachments if (isset($_FILES['uploadedFile']['name'][$step_id]) && !is_null($_FILES['uploadedFile']['name'][$step_id])) { $repOpt = array('allow_empty_title' => TRUE); // May be we have enabled MULTIPLE on file upload if (is_array($_FILES['uploadedFile']['name'][$step_id])) { $curly = count($_FILES['uploadedFile']['name'][$step_id]); for ($moe = 0; $moe < $curly; $moe++) { $fSize = isset($_FILES['uploadedFile']['size'][$step_id][$moe]) ? $_FILES['uploadedFile']['size'][$step_id][$moe] : 0; $fTmpName = isset($_FILES['uploadedFile']['tmp_name'][$step_id][$moe]) ? $_FILES['uploadedFile']['tmp_name'][$step_id][$moe] : ''; if ($fSize && $fTmpName != "") { $fk2loop = array_keys($_FILES['uploadedFile']); foreach ($fk2loop as $tk) { $fInfo[$tk] = $_FILES['uploadedFile'][$tk][$step_id][$moe]; } $uploaded = $docRepo->insertAttachment($execution_tcsteps_id, $target, '', $fInfo, $repOpt); } } } else { $fSize = isset($_FILES['uploadedFile']['size'][$step_id]) ? $_FILES['uploadedFile']['size'][$step_id] : 0; $fTmpName = isset($_FILES['uploadedFile']['tmp_name'][$step_id]) ? $_FILES['uploadedFile']['tmp_name'][$step_id] : ''; if ($fSize && $fTmpName != "") { $fk2loop = array_keys($_FILES['uploadedFile']); foreach ($fk2loop as $tk) { $fInfo[$tk] = $_FILES['uploadedFile'][$tk][$step_id]; } $uploaded = $docRepo->insertAttachment($execution_tcsteps_id, $target, '', $fInfo); } } } } } } $itCheckOK = !is_null($issueTracker) && method_exists($issueTracker, 'addIssue'); // re-init $addIssueOp = array('createIssue' => null, 'issueForStep' => null); if ($itCheckOK) { $execContext = new stdClass(); $execContext->exec_id = $execution_id; $execContext->tcversion_id = $tcversion_id; $execContext->user = $exec_signature->user; $execContext->basehref = $exec_signature->basehref; $execContext->tplan_apikey = $exec_signature->tplan_apikey; // Issue on Test Case if (isset($exec_data['createIssue'])) { completeCreateIssue($execContext, $exec_signature); $addIssueOp['createIssue'] = addIssue($db, $execContext, $issueTracker); } // Issues at step level if (isset($exec_data['issueForStep'])) { foreach ($exec_data['issueForStep'] as $stepID => $val) { completeIssueForStep($execContext, $exec_signature, $exec_data, $stepID); $addIssueOp['issueForStep'][$stepID] = addIssue($db, $execContext, $issueTracker, $stepID); } } } // $itCheckOK } } return array($execSet, $addIssueOp); }