Esempio n. 1
0
/**
 * @param object dbHandler reference to db handler
 *
 */
function doImport(&$dbHandler)
{
    $import_msg = array('ok' => array(), 'ko' => array());
    $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => '', 'filename' => '', 'import_msg' => $import_msg);
    $key = 'targetFilename';
    $dest = TL_TEMP_PATH . session_id() . "-import_cfields.tmp";
    $source = isset($_FILES[$key]['tmp_name']) ? $_FILES[$key]['tmp_name'] : null;
    if ($source != 'none' && $source != '') {
        $file_check['filename'] = $_FILES[$key]['name'];
        $file_check['status_ok'] = 1;
        if (move_uploaded_file($source, $dest)) {
            $file_check['status_ok'] = !(($xml = @simplexml_load_file($dest)) === FALSE);
        }
        if ($file_check['status_ok']) {
            $file_check['show_results'] = 1;
            $cfield_mgr = new cfield_mgr($dbHandler);
            foreach ($xml as $cf) {
                if (is_null($cfield_mgr->get_by_name($cf->name))) {
                    $cfield_mgr->create((array) $cf);
                    $import_msg['ok'][] = sprintf(lang_get('custom_field_imported'), $cf->name);
                } else {
                    $import_msg['ko'][] = sprintf(lang_get('custom_field_already_exists'), $cf->name);
                }
            }
        } else {
            $file_check['msg'] = lang_get('problems_loading_xml_content');
        }
    } else {
        $file_check = array('show_results' => 0, 'status_ok' => 0, 'msg' => lang_get('please_choose_file_to_import'));
    }
    $file_check['import_msg'] = $import_msg;
    return $file_check;
}
Esempio n. 2
0
/**
 * 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);
            }
        }
    }
}
 /**
  * Class constructor
  * 
  * @param resource &$db reference to the database handler
  * @param integer project identifier
  */
 function __construct(&$db, $tproject_id)
 {
     // you would think we could inherit the parent $db declaration
     // but it fails to work without this.
     $this->db =& $db;
     // instantiate the parent constructor.
     parent::__construct($this->db);
     $this->cf_map = $this->get_linked_cfields($tproject_id);
 }
Esempio n. 4
0
function writeCustomFieldsToDB(&$db, $tprojectID, $tsuiteID, &$hash)
{
    $ENABLED = 1;
    $NO_FILTERS = null;
    $cfield_mgr = new cfield_mgr($db);
    $cf_map = $cfield_mgr->get_linked_cfields_at_design($tprojectID, $ENABLED, $NO_FILTERS, 'testsuite');
    $cfield_mgr->design_values_to_db($hash, $tsuiteID, $cf_map);
}
Esempio n. 5
0
function do_remote_execution(&$dbHandler, $context)
{
    $debugMsg = "File:" . __FILE__ . " Function: " . __FUNCTION__;
    $tables = array();
    $tables['executions'] = DB_TABLE_PREFIX . 'executions';
    $resultsCfg = config_get('results');
    $tc_status = $resultsCfg['status_code'];
    $tree_mgr = new tree($dbHandler);
    $cfield_mgr = new cfield_mgr($dbHandler);
    $ret = null;
    $executionResults = array();
    $myResult = array();
    $sql = " /* {$debugMsg} */ INSERT INTO {$tables['executions']} " . " (testplan_id,platform_id,build_id,tester_id,execution_type," . "  tcversion_id,execution_ts,status,notes) " . " VALUES ({$context['tplan_id']}, {$context['platform_id']}, {$context['build_id']}," . " {$context['user_id']}," . testcase::EXECUTION_TYPE_AUTO . ",";
    // have we got multiple test cases to execute ?
    $target =& $context['target'];
    foreach ($target['tc_versions'] as $version_id => $tcase_id) {
        $ret[$version_id] = array("verboseID" => null, "status" => null, "notes" => null, "system" => null, "scheduled" => null, "timestamp" => null);
        $tcaseInfo = $tree_mgr->get_node_hierarchy_info($tcase_id);
        $tcaseInfo['version_id'] = $version_id;
        // For each test case version we can have a different server config
        $serverCfg = $cfield_mgr->getXMLRPCServerParams($version_id, $target['feature_id'][$version_id]);
        $execResult[$version_id] = executeTestCase($tcaseInfo, $serverCfg, $context['context']);
        // RPC call
        $tryWrite = false;
        switch ($execResult[$version_id]['system']['status']) {
            case 'configProblems':
                $tryWrite = false;
                break;
            case 'connectionFailure':
                $tryWrite = false;
                break;
            case 'ok':
                $tryWrite = true;
                break;
        }
        if ($tryWrite) {
            $trun =& $execResult[$version_id]['execution'];
            if ($trun['scheduled'] == 'now') {
                $ret[$version_id]["status"] = strtolower($trun['result']);
                $ret[$version_id]["notes"] = trim($trun['notes']);
                $notes = $dbHandler->prepare_string($ret[$version_id]["notes"]);
                if ($ret[$version_id]["status"] != $tc_status['passed'] && $ret[$version_id]["status"] != $tc_status['failed'] && $ret[$version_id]["status"] != $tc_status['blocked']) {
                    $ret[$version_id]["status"] = $tc_status['blocked'];
                }
                //
                $sql2exec = $sql . $version_id . "," . $dbHandler->db_now() . ", '{$ret[$version_id]["status"]}', '{$notes}' )";
                $dbHandler->exec_query($sql2exec);
            } else {
                $ret[$version_id]["notes"] = trim($execResult[$version_id]['notes']);
                $ret[$version_id]["scheduled"] = $execResult[$version_id]['scheduled'];
                $ret[$version_id]["timestamp"] = $execResult[$version_id]['timestampISO'];
            }
        } else {
            $ret[$version_id]["system"] = $execResult[$version_id]['system'];
        }
    }
    return $ret;
}
 /**
  * Update value of Custom Field with scope='design' 
  * for a given Test Suite
  *
  * @param struct $args
  * @param string $args["devKey"]: used to check if operation can be done.
  *                                if devKey is not valid => abort.
  *
  * @param string $args["testsuiteid"]:  
  * @param string $args["testprojectid"]: 
  * @param string $args["customfields"]
  *               contains an map with key:Custom Field Name, value: value for CF.
  *               VERY IMPORTANT: value must be formatted in the way it's written to db,
  *               this is important for types like:
  *
  *               DATE: strtotime()
  *               DATETIME: mktime()
  *               MULTISELECTION LIST / CHECKBOX / RADIO: se multipli selezione ! come separatore
  *
  *
  *               these custom fields must be configured to be writte during execution.
  *               If custom field do not meet condition value will not be written
  *
  * @return mixed null if everything ok, else array of IXR_Error objects
  *         
  * @access public
  */
 public function updateTestSuiteCustomFieldDesignValue($args)
 {
     $msg_prefix = "(" . __FUNCTION__ . ") - ";
     $this->_setArgs($args);
     $checkFunctions = array('authenticate', 'checkTestProjectID', 'checkTestSuiteID');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix);
     if ($status_ok) {
         if (!$this->_isParamPresent(self::$customFieldsParamName)) {
             $status_ok = false;
             $msg = sprintf(MISSING_REQUIRED_PARAMETER_STR, self::$customFieldsParamName);
             $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg);
         }
     }
     if ($status_ok) {
         // now check if custom fields are ok
         // For each custom field need to check if:
         // 1. is linked to test project
         // 2. is available for Test Suite at design time
         $cfieldMgr = new cfield_mgr($this->dbObj);
         // Just ENABLED
         $linkedSet = $cfieldMgr->get_linked_cfields_at_design($this->args[self::$testProjectIDParamName], cfield_mgr::ENABLED, null, 'testsuite', null, 'name');
         if (is_null($linkedSet)) {
             $status_ok = false;
             $msg = NO_CUSTOMFIELDS_DT_LINKED_TO_TESTSUITES_STR;
             $this->errors[] = new IXR_Error(NO_CUSTOMFIELDS_DT_LINKED_TO_TESTSUITES, $msg);
         }
     }
     if ($status_ok) {
         $cfSet = $args[self::$customFieldsParamName];
         foreach ($cfSet as $cfName => $cfValue) {
             // $accessKey = "custom_field_" . $item['id'] . <field_type_id>_<cfield_id>
             //  design_values_to_db($hash,$node_id,$cf_map=null,$hash_type=null)
             //
             // Simple check: if name is not present on set => ignore
             if (isset($linkedSet[$cfName])) {
                 $item = $linkedSet[$cfName];
                 $accessKey = "custom_field_" . $item['type'] . '_' . $item['id'];
                 $hash[$accessKey] = $cfValue;
                 $cfieldMgr->design_values_to_db($hash, $itemID);
                 $ret[] = array('status' => 'ok', 'msg' => 'Custom Field:' . $cfName . ' processed ');
             } else {
                 $ret[] = array('status' => 'ko', 'msg' => 'Custom Field:' . $cfName . ' skipped ');
             }
             return $ret;
         }
     } else {
         return $this->errors;
     }
 }
/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * Filename $RCSfile: cfieldsTprojectAssign.php,v $
 *
 * @version $Revision: 1.11 $
 * @modified $Date: 2010/01/21 22:04:18 $ by $Author: franciscom $
 *
**/
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db, false, false, "checkRights");
$templateCfg = templateConfiguration();
$args = init_args();
$cfield_mgr = new cfield_mgr($db);
switch ($args->doAction) {
    case 'doAssign':
        $cfield_ids = array_keys($args->cfield);
        $cfield_mgr->link_to_testproject($args->testproject_id, $cfield_ids);
        break;
    case 'doUnassign':
        $cfield_ids = array_keys($args->cfield);
        $cfield_mgr->unlink_from_testproject($args->testproject_id, $cfield_ids);
        break;
    case 'doReorder':
        $cfield_ids = array_keys($args->display_order);
        $cfield_mgr->set_display_order($args->testproject_id, $args->display_order);
        if (!is_null($args->location)) {
            $cfield_mgr->setDisplayLocation($args->testproject_id, $args->location);
        }
Esempio n. 8
0
 /**
  * returns map with key: verbose location (see custom field class $locations
  *                  value: array with fixed key 'location'
  *                         value: location code
  *
  */
 static function buildCFLocationMap()
 {
     return cfield_mgr::buildLocationMap('testcase');
 }
<?php

/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * @filesource	cfieldsEdit.php
 *
 * @internal revisions
 * @since 1.9.13
 */
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db, false, false, "checkRights");
$cfield_mgr = new cfield_mgr($db);
$templateCfg = templateConfiguration();
$args = init_args();
$gui = new stdClass();
$gui->cfield = null;
$gui->cfield_is_used = 0;
$gui->cfield_is_linked = 0;
$gui->linked_tprojects = null;
$gui->cfield_types = $cfield_mgr->get_available_types();
$result_msg = null;
$do_control_combo_display = 1;
$cfieldCfg = cfieldCfgInit($cfield_mgr);
// Changed default values
$emptyCF = array('id' => $args->cfield_id, 'name' => '', 'label' => '', 'type' => 0, 'possible_values' => '', 'show_on_design' => 1, 'enable_on_design' => 1, 'show_on_execution' => 0, 'enable_on_execution' => 0, 'show_on_testplan_design' => 0, 'enable_on_testplan_design' => 0, 'node_type_id' => $cfieldCfg->allowed_nodes['testcase']);
$gui->cfield = $emptyCF;
switch ($args->do_action) {
    case 'create':
Esempio n. 10
0
/**
 *
 */
function cfForDesign(&$dbHandler, $cfSet)
{
    static $mgr;
    if (!$mgr) {
        $mgr = new cfield_mgr($dbHandler);
    }
    $ret = null;
    foreach ($cfSet as $id => $val) {
        $xx = $mgr->get_by_id($id);
        if ($xx[$id]['enable_on_design']) {
            $ret[$id] = $val;
        }
    }
    return $ret;
}
Esempio n. 11
0
<?php

/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * @filesource	cfieldsView.php
 *
 *
**/
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db);
$templateCfg = templateConfiguration();
$cfield_mgr = new cfield_mgr($db);
$args = init_args($db);
checkRights($db, $_SESSION['currentUser'], $args);
$gui = new stdClass();
$gui->tproject_id = $args->tproject_id;
$gui->tproject_name = $args->tproject_name;
$gui->cf_map = $cfield_mgr->get_all();
$gui->cf_types = $cfield_mgr->get_available_types();
$smarty = new TLSmarty();
$smarty->assign('gui', $gui);
$smarty->display($templateCfg->template_dir . $templateCfg->default_template);
/**
 * create object with all user inputs
 *
 * @internal revisions
 * 20110417 - franciscom - BUGID 4429: Code refactoring to remove global coupling as much as possible
 */
Esempio n. 12
0
 * 20100508 - franciscom - use of $req_cfg->status_labels
 * 20100325 - asimon - added html comments with padded numbers/strings for easier and
 *                     corrent sorting to columns title/version/coverage/relations
 * 20100323 - asimon - show columns for relations and coverage only if these features are enabled.
 *                     added number of requirement relations to table.
 * 20100312 - asimon - replaced "100%"-value (in case where req has no coverage) by N/A-string
 * 20100311 - asimon - fixed a little bug (only notice) when no cfields are defined
 * 20100310 - asimon - refactoring as requested
 * 20100309 - asimon - initial commit
 * 		
 */
require_once "../../config.inc.php";
require_once "common.php";
require_once 'exttable.class.php';
testlinkInitPage($db, false, false, "checkRights");
$cfield_mgr = new cfield_mgr($db);
$templateCfg = templateConfiguration();
$tproject_mgr = new testproject($db);
$req_mgr = new requirement_mgr($db);
$args = init_args($tproject_mgr);
$gui = init_gui($args);
$glue_char = config_get('gui_title_separator_1');
$charset = config_get('charset');
$req_cfg = config_get('req_cfg');
$date_format_cfg = config_get('date_format');
$week_short = lang_get('calendar_week_short');
$time_format_cfg = config_get('timestamp_format');
$coverage_enabled = $req_cfg->expected_coverage_management;
$relations_enabled = $req_cfg->relations->enable;
$gui->reqIDs = $tproject_mgr->get_all_requirement_ids($args->tproject_id);
if (count($gui->reqIDs) > 0) {
Esempio n. 13
0
/**
 * 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);
                    }
                }
            }
        }
    }
}
<?php

/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * @filesource  cfieldsTprojectAssign.php
 *
**/
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db, false, false, "checkRights");
$templateCfg = templateConfiguration();
$args = init_args($db);
$cfield_mgr = new cfield_mgr($db);
switch ($args->doAction) {
    case 'doAssign':
        $cfield_ids = array_keys($args->cfield);
        $cfield_mgr->link_to_testproject($args->tproject_id, $cfield_ids);
        break;
    case 'doUnassign':
        $cfield_ids = array_keys($args->cfield);
        $cfield_mgr->unlink_from_testproject($args->tproject_id, $cfield_ids);
        break;
    case 'doReorder':
        $cfield_ids = array_keys($args->display_order);
        $cfield_mgr->set_display_order($args->tproject_id, $args->display_order);
        if (!is_null($args->location)) {
            $cfield_mgr->setDisplayLocation($args->tproject_id, $args->location);
        }
        break;
Esempio n. 15
0
/**
 * 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);
}
Esempio n. 16
0
 /**
  * Update value of Custom Field with scope='design' for a given Test case
  *
  * @param struct $args
  * @param string $args["devKey"]: used to check if operation can be done.
  *                                if devKey is not valid => abort.
  *
  * @param string $args["testcaseexternalid"]:  
  * @param string $args["version"]: version number  
  * @param string $args["testprojectid"]: 
  * @param string $args["customfields"] - optional
  *               contains an map with key:Custom Field Name, value: value for CF.
  *               VERY IMPORTANT: value must be formatted in the way it's written to db,
  *               this is important for types like:
  *
  *               DATE: strtotime()
  *               DATETIME: mktime()
  *               MULTISELECTION LIST / CHECKBOX / RADIO: se multipli selezione ! come separatore
  *
  *
  *               these custom fields must be configured to be writte during execution.
  *               If custom field do not meet condition value will not be written
  *
  * @return mixed null if everything ok, else array of IXR_Error objects
  *         
  * @access public
  */
 public function updateTestCaseCustomFieldDesignValue($args)
 {
     $msg_prefix = "(" . __FUNCTION__ . ") - ";
     $this->_setArgs($args);
     $checkFunctions = array('authenticate', 'checkTestProjectID', 'checkTestCaseIdentity', 'checkTestCaseVersionNumber');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix);
     if ($status_ok) {
         if (!$this->_isParamPresent(self::$customFieldsParamName)) {
             $status_ok = false;
             $msg = sprintf(MISSING_REQUIRED_PARAMETER_STR, self::$customFieldsParamName);
             $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg);
         }
     }
     if ($status_ok) {
         // now check if custom fields are ok
         // For each custom field need to check if:
         // 1. is linked to test project
         // 2. is available for test case at design time
         $cfieldMgr = new cfield_mgr($this->dbObj);
         // Just ENABLED
         $linkedSet = $cfieldMgr->get_linked_cfields_at_design($this->args[self::$testProjectIDParamName], cfield_mgr::ENABLED, null, 'testcase', null, 'name');
         if (is_null($linkedSet)) {
             $status_ok = false;
             $msg = NO_CUSTOMFIELDS_DT_LINKED_TO_TESTCASES_STR;
             $this->errors[] = new IXR_Error(NO_CUSTOMFIELDS_DT_LINKED_TO_TESTCASES, $msg);
         }
     }
     if ($status_ok) {
         $accessVersionBy['number'] = $this->args[self::$versionNumberParamName];
         $nodeInfo = $this->tcaseMgr->get_basic_info($this->args[self::$testCaseIDParamName], $accessVersionBy);
         $cfSet = $args[self::$customFieldsParamName];
         foreach ($cfSet as $cfName => $cfValue) {
             // $accessKey = "custom_field_" . $item['id'] . <field_type_id>_<cfield_id>
             //  design_values_to_db($hash,$node_id,$cf_map=null,$hash_type=null)
             $item = $linkedSet[$cfName];
             $accessKey = "custom_field_" . $item['type'] . '_' . $item['id'];
             $hash[$accessKey] = $cfValue;
             $cfieldMgr->design_values_to_db($hash, $nodeInfo[0]['tcversion_id']);
         }
     } else {
         return $this->errors;
     }
 }
Esempio n. 17
0
function doUpdate(&$db, &$args, &$tcaseMgr, &$request)
{
    updateExecutionNotes($db, $args->exec_id, $args->notes);
    $cfield_mgr = new cfield_mgr($db);
    $cfield_mgr->execution_values_to_db($request, $args->tcversion_id, $args->exec_id, $args->tplan_id);
}
Esempio n. 18
0
/**
 * 
 * 
 */
function buildResultSet(&$dbHandler, &$guiObj, $tproject_id, $tplan_id)
{
    $cfieldMgr = new cfield_mgr($dbHandler);
    // Get the custom fields linked/enabled on execution to a test project
    // This will be used on report to give name to header of columns that hold custom field value
    $guiObj->cfields = $cfieldMgr->get_linked_cfields_at_execution($tproject_id, 1, 'testcase', null, null, null, 'name');
    // this way on caller can be used on array operations, without warnings
    $guiObj->cfields = (array) $guiObj->cfields;
    if (count($guiObj->cfields) > 0) {
        foreach ($guiObj->cfields as $key => $values) {
            $cf_place_holder['cfields'][$key] = '';
        }
    }
    $cf_map = $cfieldMgr->get_linked_cfields_at_execution($tproject_id, 1, 'testcase', null, null, $tplan_id, 'exec_id');
    // need to transform in structure that allow easy display
    // Every row is an execution with exec data plus a column that contains following map:
    // 'cfields' => CFNAME1 => value
    //              CFNAME2 => value
    $guiObj->resultSet = array();
    if (!is_null($cf_map)) {
        foreach ($cf_map as $exec_id => $exec_info) {
            // Get common exec info and remove useless keys
            $guiObj->resultSet[$exec_id] = $exec_info[0];
            unset($guiObj->resultSet[$exec_id]['name']);
            unset($guiObj->resultSet[$exec_id]['label']);
            unset($guiObj->resultSet[$exec_id]['display_order']);
            unset($guiObj->resultSet[$exec_id]['id']);
            unset($guiObj->resultSet[$exec_id]['value']);
            // Collect custom fields values
            $guiObj->resultSet[$exec_id] += $cf_place_holder;
            foreach ($exec_info as $cfield_data) {
                $guiObj->resultSet[$exec_id]['cfields'][$cfield_data['name']] = $cfield_data['value'];
            }
        }
    }
    if (($guiObj->row_qty = count($cf_map)) == 0) {
        $guiObj->warning_msg = lang_get('no_linked_tc_cf');
    }
}
Esempio n. 19
0
/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * @filesource	testPlanWithCF.php
 * @author 		  Amit Khullar - amkhullar@gmail.com
 *
 * For a test plan, list associated Custom Field Data
 *
 * @internal revisions
 */
require_once "../../config.inc.php";
require_once "common.php";
testlinkInitPage($db);
$cfield_mgr = new cfield_mgr($db);
$templateCfg = templateConfiguration();
$tproject_mgr = new testproject($db);
$tplan_mgr = new testplan($db);
$tcase_mgr = new testcase($db);
$args = init_args($tplan_mgr);
checkRights($db, $_SESSION['currentUser'], $args);
$charset = config_get('charset');
$glue_char = config_get('gui_title_separator_1');
$gui = new stdClass();
$gui->pageTitle = lang_get('caption_testPlanWithCF');
$gui->warning_msg = '';
$gui->path_info = null;
$gui->resultSet = null;
$gui->tproject_id = $args->tproject_id;
$gui->tproject_name = $args->tproject_name;
<?php

/**
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later.
 *
 * @filesource  cfieldsView.php
 *
**/
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db, false, false, "checkRights");
$gui = new stdClass();
$templateCfg = templateConfiguration();
$cfield_mgr = new cfield_mgr($db);
$gui->cf_map = $cfield_mgr->get_all(null, 'transform');
$gui->cf_types = $cfield_mgr->get_available_types();
$smarty = new TLSmarty();
$smarty->assign('gui', $gui);
$smarty->display($templateCfg->template_dir . $templateCfg->default_template);
function checkRights(&$db, &$user)
{
    return $user->hasRight($db, "cfield_view");
}
Esempio n. 21
0
 function exportTestCaseDataToXML($tcase_id, $tcversion_id, $tproject_id = null, $bNoXMLHeader = false, $optExport = array())
 {
     static $reqMgr;
     static $keywordMgr;
     static $cfieldMgr;
     if (is_null($reqMgr)) {
         $reqMgr = new requirement_mgr($this->db);
         $keywordMgr = new tlKeyword();
         $cfieldMgr = new cfield_mgr($this->db);
     }
     // Useful when you need to get info but do not have tcase id
     $tcase_id = intval((int) $tcase_id);
     $tcversion_id = intval((int) $tcversion_id);
     if ($tcase_id <= 0 && $tcversion_id > 0) {
         $info = $this->tree_manager->get_node_hierarchy_info($tcversion_id);
         $tcase_id = $info['parent_id'];
     }
     $tc_data = $this->get_by_id($tcase_id, $tcversion_id);
     $testCaseVersionID = $tc_data[0]['id'];
     if (!$tproject_id) {
         $tproject_id = $this->getTestProjectFromTestCase($tcase_id);
     }
     if (isset($optExport['CFIELDS']) && $optExport['CFIELDS']) {
         $cfMap = $this->get_linked_cfields_at_design($tcase_id, $testCaseVersionID, null, null, $tproject_id);
         // ||yyy||-> tags,  {{xxx}} -> attribute
         // tags and attributes receive different treatment on exportDataToXML()
         //
         // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl
         // value is a key inside $tc_data[0]
         //
         if (!is_null($cfMap) && count($cfMap) > 0) {
             // $cfRootElem = "<custom_fields>{{XMLCODE}}</custom_fields>";
             // $cfElemTemplate = "\t" . "<custom_field>\n" .
             //                   "\t<name><![CDATA[||NAME||]]></name>\n" .
             //                   "\t<value><![CDATA[||VALUE||]]></value>\n</custom_field>\n";
             // $cfDecode = array ("||NAME||" => "name","||VALUE||" => "value");
             // $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportDataToXML($cfMap,$cfRootElem,$cfElemTemplate,$cfDecode,true);
             $tc_data[0]['xmlcustomfields'] = $cfieldMgr->exportValueAsXML($cfMap);
         }
     }
     if (isset($optExport['KEYWORDS']) && $optExport['KEYWORDS']) {
         $keywords = $this->getKeywords($tcase_id);
         if (!is_null($keywords)) {
             $xmlKW = "<keywords>" . $keywordMgr->toXMLString($keywords, true) . "</keywords>";
             $tc_data[0]['xmlkeywords'] = $xmlKW;
         }
     }
     if (isset($optExport['REQS']) && $optExport['REQS']) {
         $requirements = $reqMgr->get_all_for_tcase($tcase_id);
         if (!is_null($requirements) && count($requirements) > 0) {
             $reqRootElem = "\t<requirements>\n{{XMLCODE}}\t</requirements>\n";
             $reqElemTemplate = "\t\t<requirement>\n" . "\t\t\t<req_spec_title><![CDATA[||REQ_SPEC_TITLE||]]></req_spec_title>\n" . "\t\t\t<doc_id><![CDATA[||REQ_DOC_ID||]]></doc_id>\n" . "\t\t\t<title><![CDATA[||REQ_TITLE||]]></title>\n" . "\t\t</requirement>\n";
             $reqDecode = array("||REQ_SPEC_TITLE||" => "req_spec_title", "||REQ_DOC_ID||" => "req_doc_id", "||REQ_TITLE||" => "title");
             $tc_data[0]['xmlrequirements'] = exportDataToXML($requirements, $reqRootElem, $reqElemTemplate, $reqDecode, true);
         }
     }
     // ------------------------------------------------------------------------------------
     $stepRootElem = "<steps>{{XMLCODE}}</steps>";
     $stepTemplate = "\n" . '<step>' . "\n" . "\t<step_number><![CDATA[||STEP_NUMBER||]]></step_number>\n" . "\t<actions><![CDATA[||ACTIONS||]]></actions>\n" . "\t<expectedresults><![CDATA[||EXPECTEDRESULTS||]]></expectedresults>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "</step>\n";
     $stepInfo = array("||STEP_NUMBER||" => "step_number", "||ACTIONS||" => "actions", "||EXPECTEDRESULTS||" => "expected_results", "||EXECUTIONTYPE||" => "execution_type");
     $stepSet = $tc_data[0]['steps'];
     $xmlsteps = exportDataToXML($stepSet, $stepRootElem, $stepTemplate, $stepInfo, true);
     $tc_data[0]['xmlsteps'] = $xmlsteps;
     // ------------------------------------------------------------------------------------
     $rootElem = "{{XMLCODE}}";
     if (isset($optExport['ROOTELEM'])) {
         $rootElem = $optExport['ROOTELEM'];
     }
     $elemTpl = "\n" . '<testcase internalid="{{TESTCASE_ID}}" name="{{NAME}}">' . "\n" . "\t<node_order><![CDATA[||NODE_ORDER||]]></node_order>\n";
     if (!isset($optExport['EXTERNALID']) || $optExport['EXTERNALID']) {
         $elemTpl .= "\t<externalid><![CDATA[||EXTERNALID||]]></externalid>\n";
     }
     $elemTpl .= "\t<version><![CDATA[||VERSION||]]></version>\n" . "\t<summary><![CDATA[||SUMMARY||]]></summary>\n" . "\t<preconditions><![CDATA[||PRECONDITIONS||]]></preconditions>\n" . "\t<execution_type><![CDATA[||EXECUTIONTYPE||]]></execution_type>\n" . "\t<importance><![CDATA[||IMPORTANCE||]]></importance>\n" . "\t<estimated_exec_duration>||ESTIMATED_EXEC_DURATION||</estimated_exec_duration>\n" . "\t<status>||STATUS||</status>\n" . "||STEPS||\n" . "||KEYWORDS||||CUSTOMFIELDS||||REQUIREMENTS||</testcase>\n";
     // ||yyy||-> tags,  {{xxx}} -> attribute
     // tags and attributes receive different treatment on exportDataToXML()
     //
     // each UPPER CASE word in this map KEY, MUST HAVE AN OCCURENCE on $elemTpl
     // value is a key inside $tc_data[0]
     //
     $info = array("{{TESTCASE_ID}}" => "testcase_id", "{{NAME}}" => "name", "||NODE_ORDER||" => "node_order", "||EXTERNALID||" => "tc_external_id", "||VERSION||" => "version", "||SUMMARY||" => "summary", "||PRECONDITIONS||" => "preconditions", "||EXECUTIONTYPE||" => "execution_type", "||IMPORTANCE||" => "importance", "||ESTIMATED_EXEC_DURATION||" => "estimated_exec_duration", "||STATUS||" => "status", "||STEPS||" => "xmlsteps", "||KEYWORDS||" => "xmlkeywords", "||CUSTOMFIELDS||" => "xmlcustomfields", "||REQUIREMENTS||" => "xmlrequirements");
     $xmlTC = exportDataToXML($tc_data, $rootElem, $elemTpl, $info, $bNoXMLHeader);
     return $xmlTC;
 }
function saveImportedResultData(&$db, $resultData, $context, $options)
{
    if (!$resultData) {
        return;
    }
    $debugMsg = ' FUNCTION: ' . __FUNCTION__;
    $tables = tlObjectWithDB::getDBTables(array('executions', 'execution_bugs'));
    $tcaseCfg = config_get('testcase_cfg');
    // ---------------------------------------------------------------------------------------
    $l10n = array('import_results_tc_not_found' => '', 'import_results_invalid_result' => '', 'tproject_id_not_found' => '', 'import_results_ok' => '', 'invalid_cf' => '', 'import_results_skipped' => '');
    foreach ($l10n as $key => $value) {
        $l10n[$key] = lang_get($key);
    }
    $resultsCfg = config_get('results');
    foreach ($resultsCfg['status_label'] as $ks => $lbl) {
        $key = $resultsCfg['status_code'][$ks];
        $l10n[$key] = lang_get($lbl);
    }
    // ---------------------------------------------------------------------------------------
    // Get Column definitions to get size dinamically instead of create constants
    $columnDef = array();
    $adodbObj = $db->get_dbmgr_object();
    $columnDef['execution_bugs'] = $adodbObj->MetaColumns($tables['execution_bugs']);
    $keySet = array_keys($columnDef['execution_bugs']);
    foreach ($keySet as $keyName) {
        if (($keylow = strtolower($keyName)) != $keyName) {
            $columnDef['execution_bugs'][$keylow] = $columnDef['execution_bugs'][$keyName];
            unset($columnDef['execution_bugs'][$keyName]);
        }
    }
    $user = new tlUser($context->userID);
    $user->readFromDB($db);
    $tcase_mgr = new testcase($db);
    $resultMap = array();
    $tplan_mgr = null;
    $tc_qty = sizeof($resultData);
    if ($tc_qty) {
        $tplan_mgr = new testplan($db);
        $tproject_mgr = new testproject($db);
        $build_mgr = new build_mgr($db);
    }
    // Need to do checks on common settings
    //
    // test project exists
    //
    // test plan id:
    //              belongs to target test project
    //              is active
    // build id:
    //          belongs to target test plan
    //          is open
    //
    // platform id:
    //          is linked  to target test plan
    //
    // execution type if not present -> set to MANUAL
    //          if presente is valid i.e. inside the TL domain
    //
    $checks = array();
    $checks['status_ok'] = true;
    $checks['msg'] = null;
    $dummy = null;
    if (!is_null($context->tprojectID) && intval($context->tprojectID) > 0) {
        $dummy = array($tproject_mgr->get_by_id($context->tprojectID, array('output' => 'existsByID')));
    } else {
        if (!is_null($context->tprojectName)) {
            $dummy = $tproject_mgr->get_by_name($context->tprojectName, null, array('output' => 'existsByName'));
        }
    }
    $checks['status_ok'] = !is_null($dummy);
    if (!$checks['status_ok']) {
        $checks['msg'][] = sprintf($l10n['tproject_id_not_found'], $context->tprojectID);
    }
    if (!$checks['status_ok']) {
        foreach ($checks['msg'] as $warning) {
            $resultMap[] = array($warning);
        }
    }
    if ($doIt = $checks['status_ok']) {
        $context->tprojectID = $dummy[0]['id'];
    }
    // --------------------------------------------------------------------
    $dummy = null;
    if (!is_null($context->tplanID) && intval($context->tplanID) > 0) {
        $dummy = $tplan_mgr->get_by_id($context->tplanID, array('output' => 'minimun'));
        if (!is_null($dummy)) {
            $dummy['id'] = $context->tplanID;
        }
    } else {
        if (!is_null($context->tplanName)) {
            $dummy = $tplan_mgr->get_by_name($context->tplanName, $context->tprojectID, array('output' => 'minimun'));
            if (!is_null($dummy)) {
                $dummy = $dummy[0];
            }
        }
    }
    if (!is_null($dummy)) {
        $context->tplanID = $dummy['id'];
    }
    if (intval($context->tprojectID) <= 0 && intval($context->tplanID) > 0) {
        $dummy = $tplan_mgr->tree_manager->get_node_hierarchy_info($context->tplanID);
        $context->tprojectID = $dummy['parent_id'];
    }
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    $dummy = null;
    $tplan_mgr->platform_mgr->setTestProjectID($context->tprojectID);
    if (!is_null($context->platformID) && intval($context->platformID) > 0) {
        $dummy = array($tplan_mgr->platform_mgr->getByID($context->platformID));
    } else {
        if (property_exists($context, 'platformName') && !is_null($context->platformName)) {
            if (!is_null($xx = $tplan_mgr->platform_mgr->getID($context->platformName))) {
                $dummy = array(0 => array('id' => $xx));
            }
        }
    }
    if (!is_null($dummy)) {
        $context->platformID = $dummy[0]['id'];
    }
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    $optGB = array('tplan_id' => $context->tplanID, 'output' => 'minimun');
    $dummy = null;
    if (!is_null($context->buildID) && intval($context->buildID) > 0) {
        $dummy = array($build_mgr->get_by_id($context->buildID, $optGB));
    } else {
        if (!is_null($context->buildName)) {
            $dummy = $build_mgr->get_by_name($context->buildName, $optGB);
        }
    }
    if (!is_null($dummy)) {
        $context->buildID = $dummy[0]['id'];
    }
    // --------------------------------------------------------------------
    // --------------------------------------------------------------------
    for ($idx = 0; $doIt && $idx < $tc_qty; $idx++) {
        $tester_id = 0;
        $tester_name = '';
        $using_external_id = false;
        $message = null;
        $status_ok = true;
        $tcase_exec = $resultData[$idx];
        // New attribute "execution type" makes old XML import files incompatible
        // Important NOTICE:
        // tcase_exec is passed BY REFERENCE to allow check_exec_values()change execution type if needed
        //
        $checks = check_exec_values($db, $tcase_mgr, $user_mgr, $tcaseCfg, $tcase_exec, $columnDef['execution_bugs']);
        $status_ok = $checks['status_ok'];
        if ($status_ok) {
            $tcase_id = $checks['tcase_id'];
            $tcase_external_id = trim($tcase_exec['tcase_external_id']);
            $tester_id = $checks['tester_id'];
            // external_id has precedence over internal id
            $using_external_id = $tcase_external_id != "";
        } else {
            foreach ($checks['msg'] as $warning) {
                $resultMap[] = array($warning);
            }
        }
        if ($status_ok) {
            $tcase_identity = $using_external_id ? $tcase_external_id : $tcase_id;
            $result_code = strtolower($tcase_exec['result']);
            $result_is_acceptable = isset($resultsCfg['code_status'][$result_code]) ? true : false;
            $notes = $tcase_exec['notes'];
            $message = null;
            $info_on_case = $tplan_mgr->getLinkInfo($context->tplanID, $tcase_id, $context->platformID);
            if (is_null($info_on_case)) {
                $message = sprintf($l10n['import_results_tc_not_found'], $tcase_identity);
            } else {
                if (!$result_is_acceptable) {
                    $message = sprintf($l10n['import_results_invalid_result'], $tcase_identity, $tcase_exec['result']);
                } else {
                    $info_on_case = current($info_on_case);
                    $tcversion_id = $info_on_case['tcversion_id'];
                    $version = $info_on_case['version'];
                    $notes = $db->prepare_string(trim($notes));
                    // N.B.: db_now() returns an string ready to be used in an SQL insert
                    //       example '2008-09-04', while $tcase_exec["timestamp"] => 2008-09-04
                    //
                    $execution_ts = $tcase_exec['timestamp'] != '' ? "'" . $tcase_exec["timestamp"] . "'" : $db->db_now();
                    if ($tester_id != 0) {
                        $tester_name = $tcase_exec['tester'];
                    } else {
                        $tester_name = $user->login;
                        $tester_id = $context->userID;
                    }
                    $addExecDuration = strlen($tcase_exec['execution_duration']) > 0 && is_numeric($tcase_exec['execution_duration']);
                    $lexid = 0;
                    if ($options->copyIssues) {
                        $lexid = $tcase_mgr->getSystemWideLastestExecutionID($tcversion_id);
                    }
                    $idCard = array('id' => $tcase_id, 'version_id' => $tcversion_id);
                    $exco = array('tplan_id' => $context->tplanID, 'platform_id' => $context->platformID, 'build_id' => $context->buildID);
                    $lexInfo = $tcase_mgr->getLatestExecSingleContext($idCard, $exco, array('output' => 'timestamp'));
                    $doInsert = true;
                    if (!is_null($lexInfo)) {
                        $tts = $lexInfo[$tcase_id][0]['execution_ts'];
                        $doInsert = $lexInfo[$tcase_id][0]['execution_ts'] != trim($execution_ts, "'");
                        $msgTxt = $l10n['import_results_skipped'];
                    }
                    if ($doInsert) {
                        $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['executions']} (build_id,tester_id,status,testplan_id," . " tcversion_id,execution_ts,notes,tcversion_number,platform_id,execution_type" . ($addExecDuration ? ',execution_duration' : '') . ")" . " VALUES ({$context->buildID}, {$tester_id},'{$result_code}',{$context->tplanID}, " . " {$tcversion_id},{$execution_ts},'{$notes}', {$version}, " . " {$context->platformID}, {$tcase_exec['execution_type']}" . ($addExecDuration ? ",{$tcase_exec['execution_duration']}" : '') . ")";
                        $db->exec_query($sql);
                        $execution_id = $db->insert_id($tables['executions']);
                        // 20150127
                        /*
                        if(isset($tcase_exec['steps']) && !is_null($tcase_exec['steps']))
                        {
                          $stepSet = $tcase_mgr->getStepsSimple($tcversion_id,0,
                                                                array('fields2get' => 'TCSTEPS.step_number,TCSTEPS.id',
                                                                      'accessKey' => 'step_number'));
                          $sc = count($tcase_exec['steps']);
                          for($sx=0; $sx < $sc; $sx++)
                          {
                            $snum = $$tcase_exec['steps'][$sx];
                            // assumption: all data is valid
                            if(isset($stepSet[$snum]))
                            {
                              
                            }  
                          }  
                        }  
                        new dBug($tcase_exec);
                        die();
                        */
                        if ($lexid > 0 && $options->copyIssues) {
                            copyIssues($db, $lexid, $execution_id);
                        }
                        if (isset($tcase_exec['bug_id']) && !is_null($tcase_exec['bug_id']) && is_array($tcase_exec['bug_id'])) {
                            foreach ($tcase_exec['bug_id'] as $bug_id) {
                                $bug_id = trim($bug_id);
                                $sql = " /* {$debugMsg} */ " . " SELECT execution_id AS check_qty FROM  {$tables['execution_bugs']} " . " WHERE bug_id = '{$bug_id}' AND execution_id={$execution_id} ";
                                $rs = $db->get_recordset($sql);
                                if (is_null($rs)) {
                                    $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['execution_bugs']} (bug_id,execution_id)" . " VALUES ('" . $db->prepare_string($bug_id) . "', {$execution_id} )";
                                    $db->exec_query($sql);
                                }
                            }
                        }
                        if (isset($tcase_exec['custom_fields']) && !is_null($tcase_exec['custom_fields']) && is_array($tcase_exec['custom_fields'])) {
                            // Get linked custom fields to this test project, for test case on execution
                            // $context->tprojectID
                            $cfieldMgr = new cfield_mgr($db);
                            $cfSetByName = $cfieldMgr->get_linked_cfields_at_execution($context->tprojectID, 1, 'testcase', null, null, null, 'name');
                            foreach ($tcase_exec['custom_fields'] as $cf) {
                                $ak = null;
                                if (isset($cfSetByName[$cf['name']])) {
                                    // write to db blind
                                    $ak[$cfSetByName[$cf['name']]['id']]['cf_value'] = $cf['value'];
                                } else {
                                    $message = sprintf($l10n['invalid_cf'], $tcase_identity, $cf['name']);
                                }
                                if (!is_null($ak)) {
                                    $cfieldMgr->execution_values_to_db($ak, $tcversion_id, $execution_id, $context->tplanID, null, 'plain');
                                }
                            }
                        }
                        if (!is_null($message)) {
                            $resultMap[] = array($message);
                        }
                        $msgTxt = $l10n['import_results_ok'];
                    }
                    $message = sprintf($msgTxt, $tcase_identity, $version, $tester_name, $l10n[$result_code], $execution_ts);
                }
            }
        }
        if (!is_null($message)) {
            $resultMap[] = array($message);
        }
    }
    return $resultMap;
}