function migrate_ownership(&$source_db, &$target_db, &$rs, &$map_tc_tcversion, &$old_new)
{
    $db_now = $target_db->db_now();
    $assignment_mgr = new assignment_mgr($target_db);
    $assignment_types = $assignment_mgr->get_available_types();
    $assignment_status = $assignment_mgr->get_available_status();
    $sql = "SELECT * FROM user";
    $users = $source_db->fetchRowsIntoMap($sql, 'login');
    $qty_item = count($rs);
    echo "<pre>   Number of ownership assignments to update: " . $qty_item;
    echo "</pre>";
    foreach ($rs as $rid => $rdata) {
        $tcversion_id = $map_tc_tcversion[$rdata['mgttcid']];
        $tplan_id = intval($rdata['projid']);
        $sql = " SELECT id FROM testplan_tcversions " . " WHERE testplan_id=" . $old_new['tplan'][$tplan_id] . " AND tcversion_id=" . $tcversion_id;
        $feature_row = $target_db->get_recordset($sql);
        $feature_id = $feature_row[0]['id'];
        $owner_login = $rdata['owner'];
        $user_id = isset($users[$owner_login]) ? $users[$owner_login]['id'] : 0;
        if ($user_id > 0 && $feature_id) {
            $sql = "INSERT INTO user_assignments " . "(feature_id,user_id,creation_ts,type,status) " . " VALUES({$feature_id},{$user_id},{$db_now}," . $assignment_types['testcase_execution']['id'] . "," . $assignment_status['open']['id'] . ")";
            $exec_id = $target_db->exec_query($sql);
        }
    }
}
$tree_mgr = new tree($db);
$tplan_mgr = new testplan($db);
$tcase_mgr = new testcase($db);
$assignment_mgr = new assignment_mgr($db);
$templateCfg = templateConfiguration();
$args = init_args();
$gui = initializeGui($db, $args, $tplan_mgr, $tcase_mgr);
$keywordsFilter = new stdClass();
$keywordsFilter->items = null;
$keywordsFilter->type = null;
if (is_array($args->keyword_id)) {
    $keywordsFilter->items = $args->keyword_id;
    $keywordsFilter->type = $gui->keywordsFilterType;
}
$arrData = array();
$status_map = $assignment_mgr->get_available_status();
$types_map = $assignment_mgr->get_available_types();
$task_test_execution = $types_map['testcase_execution']['id'];
switch ($args->doAction) {
    case 'std':
        if (!is_null($args->achecked_tc)) {
            $open = $status_map['open']['id'];
            $db_now = $db->db_now();
            $features2 = array('upd' => array(), 'ins' => array(), 'del' => array());
            $method2call = array('upd' => 'update', 'ins' => 'assign', 'del' => 'delete_by_feature_id_and_build_id');
            $called = array('upd' => false, 'ins' => false, 'del' => false);
            foreach ($args->achecked_tc as $key_tc => $platform_tcversion) {
                foreach ($platform_tcversion as $platform_id => $tcversion_id) {
                    $feature_id = $args->feature_id[$key_tc][$platform_id];
                    $op = 'ins';
                    $features2[$op][$feature_id]['user_id'] = $args->tester_for_tcid[$key_tc][$platform_id];
Exemplo n.º 3
0
// TARGET DB
echo '<span>Connecting to Testlink 1.7 (target) database. - ' . $db_cfg['target']['db_name'] . ' - </span>';
$target_db = connect_2_db($db_cfg['target']);
// make sure we have a connection to both dbs
if (is_null($source_db) || is_null($target_db)) {
    echo "<p>FATAL ERROR: Could not connect to either source or target db!</p>";
    exit;
}
// -----------------------------------------------------------------------------------
$tproject_mgr = new testproject($target_db);
$ts_mgr = new testsuite($target_db);
$tc_mgr = new testcase($target_db);
$tree_mgr = new tree($target_db);
$assignment_mgr = new assignment_mgr($target_db);
$assignment_types = $assignment_mgr->get_available_types();
$assignment_status = $assignment_mgr->get_available_status();
define('EMPTY_NOTES', '');
// all the tables that will be truncated in the 1.7 db
$a_sql = array();
$a_sql[] = "TRUNCATE TABLE attachments";
$a_sql[] = "TRUNCATE TABLE builds";
$a_sql[] = "TRUNCATE TABLE cfield_node_types";
$a_sql[] = "TRUNCATE TABLE cfield_testprojects";
$a_sql[] = "TRUNCATE TABLE cfield_design_values";
$a_sql[] = "TRUNCATE TABLE cfield_execution_values";
$a_sql[] = "TRUNCATE TABLE custom_fields";
$a_sql[] = "TRUNCATE TABLE executions";
$a_sql[] = "TRUNCATE TABLE execution_bugs";
$a_sql[] = "TRUNCATE TABLE keywords";
$a_sql[] = "TRUNCATE TABLE milestones";
$a_sql[] = "TRUNCATE TABLE nodes_hierarchy";
Exemplo n.º 4
0
 /**
  * @param struct $args
  * @param string $args["devKey"]
  * @param string $args["action"]: assignOne, unassignOne, unassignAll
  * 
  * @param int $args["testplanid"]
  * @param string $args["testcaseexternalid"] format PREFIX-NUMBER
  * @param int $args["buildid"] Mandatory => you can provide buildname as alternative
  * @param int $args["buildname"] Mandatory => you can provide buildid (DB ID) as alternative
  * @param int $args["platformid"] optional - BECOMES MANDATORY if Test plan has platforms
  *                                           you can provide platformname as alternative  
  *  
  * @param int $args["platformname"] optional - BECOMES MANDATORY if Test plan has platforms
  *                                           you can provide platformid as alternative  
  * @param string $args["user'] - login name => tester
  *
  */
 private function manageTestCaseExecutionTask($args, $msg_prefix)
 {
     $status_ok = true;
     $this->_setArgs($args);
     $resultInfo = array();
     // Checks are done in order
     $checkFunctions = array('authenticate', 'checkTestPlanID', 'checkTestCaseIdentity', 'checkBuildID');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix);
     if ($status_ok) {
         switch ($args['action']) {
             case 'assignOne':
             case 'unassignOne':
                 if ($status_ok = $this->_isParamPresent(self::$userParamName, $msg_prefix, self::SET_ERROR)) {
                     $tester_id = tlUser::doesUserExist($this->dbObj, $this->args[self::$userParamName]);
                     if (!($status_ok = !is_null($tester_id))) {
                         $msg = $msg_prefix . sprintf(NO_USER_BY_THIS_LOGIN_STR, $this->args[self::$userParamName]);
                         $this->errors[] = new IXR_Error(NO_USER_BY_THIS_LOGIN, $msg);
                     }
                 }
                 break;
             case 'unassignAll':
                 break;
         }
     }
     // Check if requested test case is linked to test plan
     // if answer is yes, get link info, in order to be able to check if
     // we need also platform info
     if ($status_ok) {
         $execContext = array('tplan_id' => $this->args[self::$testPlanIDParamName], 'platform_id' => null, 'build_id' => $this->args[self::$buildIDParamName]);
         $tplan_id = $this->args[self::$testPlanIDParamName];
         $tcase_id = $this->args[self::$testCaseIDParamName];
         $filters = array('exec_status' => "ALL", 'active_status' => "ALL", 'tplan_id' => $tplan_id, 'platform_id' => null);
         $info = $this->tcaseMgr->get_linked_versions($tcase_id, $filters, array('output' => "feature_id"));
         // more than 1 item => we have platforms
         // access key => tcversion_id, tplan_id, platform_id
         $link = current($info);
         $link = $link[$tplan_id];
         // Inside test plan, is indexed by platform
         $hits = count($link);
         $platform_id = 0;
         $check_platform = count($hits) > 1 || !isset($link[0]);
     }
     if ($status_ok && $check_platform) {
         // this means that platform is MANDATORY
         if (!$this->_isParamPresent(self::$platformIDParamName, $msg_prefix) && !$this->_isParamPresent(self::$platformNameParamName, $msg_prefix)) {
             $status_ok = false;
             $pname = self::$platformNameParamName . ' OR ' . self::$platformIDParamName;
             $msg = $messagePrefix . sprintf(MISSING_REQUIRED_PARAMETER_STR, $pname);
             $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg);
         } else {
             // get platform_id and check it
             if ($status_ok = $this->checkPlatformIdentity($tplan_id)) {
                 $platform_set = $this->tplanMgr->getPlatforms($tplan_id, array('outputFormat' => 'mapAccessByID', 'outputDetails' => 'name'));
                 // Now check if link has all 3 components
                 // test plan, test case, platform
                 $platform_id = $this->args[self::$platformIDParamName];
                 $platform_info = array($platform_id => $platform_set[$platform_id]);
                 if ($status_ok = $this->_checkTCIDAndTPIDValid($platform_info, $msg_prefix)) {
                     $execContext['platform_id'] = $platform_id;
                 }
             }
         }
     }
     if ($status_ok) {
         $assignment_mgr = new assignment_mgr($this->dbObj);
         $types = $assignment_mgr->get_available_types();
         // Remove old execution task assignment
         // `id` int(10) unsigned NOT NULL auto_increment,
         // `type` int(10) unsigned NOT NULL default '1',
         // `feature_id` int(10) unsigned NOT NULL default '0',
         // `user_id` int(10) unsigned default '0',
         // `build_id` int(10) unsigned default '0',
         // `deadline_ts` datetime NULL,
         // `assigner_id`  int(10) unsigned default '0',
         // `creation_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
         // `status` int(10) unsigned default '1',
         // ATTENTION WITH PLATFORMS
         $link = is_null($execContext['platform_id']) ? $link[0] : $link[$execContext['platform_id']];
         $feature = array($link['feature_id'] => array('build_id' => $execContext['build_id']));
         switch ($args['action']) {
             case 'unassignOne':
                 $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']);
                 $assignment_mgr->deleteBySignature($signature);
                 break;
             case 'assignOne':
                 // Step 1 - remove if exists
                 $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']);
                 $assignment_mgr->deleteBySignature($signature);
                 // Step 2 - Now assign
                 $assign_status = $assignment_mgr->get_available_status();
                 $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id'];
                 $oo[$link['feature_id']]['status'] = $assign_status['open']['id'];
                 $oo[$link['feature_id']]['user_id'] = $tester_id;
                 $oo[$link['feature_id']]['assigner_id'] = $this->userID;
                 $oo[$link['feature_id']]['build_id'] = $execContext['build_id'];
                 $assignment_mgr->assign($oo);
                 break;
             case 'unassignAll':
                 $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id'];
                 $oo[$link['feature_id']]['build_id'] = $execContext['build_id'];
                 $assignment_mgr->delete_by_feature_id_and_build_id($oo);
                 break;
         }
         $resultInfo = array("status" => true, "args" => $this->args);
         unset($resultInfo['args']['devKey']);
     }
     return $status_ok ? $resultInfo : $this->errors;
 }
Exemplo n.º 5
0
 if ($args->save_results || $args->do_bulk_save || $args->save_and_next || $args->save_and_exit || $args->doMoveNext || $args->doMovePrevious) {
     // this has to be done to do not break logic present on write_execution()
     $args->save_results = $args->save_and_next ? $args->save_and_next : ($args->save_results ? $args->save_results : $args->save_and_exit);
     if ($args->save_results || $args->do_bulk_save) {
         // Need to get Latest execution ID before writing
         $lexid = 0;
         if ($args->copyIssues && $args->level == 'testcase') {
             $lexid = $tcase_mgr->getSystemWideLastestExecutionID($args->version_id);
         }
         $_REQUEST['save_results'] = $args->save_results;
         list($execSet, $gui->addIssueOp) = write_execution($db, $args, $_REQUEST, $its);
         if ($args->assignTask) {
             $fid = $tplan_mgr->getFeatureID($args->tplan_id, $args->platform_id, $args->version_id);
             $taskMgr = new assignment_mgr($db);
             $taskDomain = $taskMgr->get_available_types();
             $taskStatusDomain = $taskMgr->get_available_status();
             $fmap[$fid]['user_id'] = $fmap[$fid]['assigner_id'] = $args->user_id;
             $fmap[$fid]['build_id'] = $args->build_id;
             $fmap[$fid]['type'] = $taskDomain['testcase_execution']['id'];
             $fmap[$fid]['status'] = $taskStatusDomain['open']['id'];
             $taskMgr->assign($fmap);
         }
         if ($lexid > 0 && $args->copyIssues && $args->level == 'testcase') {
             copyIssues($db, $lexid, $execSet[$args->version_id]);
         }
     }
     // Need to re-read to update test case status
     if ($args->save_and_next || $args->doMoveNext || $args->doMovePrevious) {
         $nextInChain = -1;
         if ($cfg->exec_cfg->exec_mode->save_and_move == 'unlimited') {
             if ($args->caller == 'tcAssignedToMe') {