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);
        }
    }
}
/**
 * Migrate the existing user assignments for all test plans and test projects.
 * All test case execution assignments will be stored per build in TL 1.9.
 * So all tester assignments for the test cases in each test plan will be updated 
 * with the ID of the newest available build for that test plan.
 * 
 * @author Andreas Simon
 * @param database $dbHandler
 * @param array $tableSet
 */
function migrate_user_assignments(&$dbHandler, $tableSet)
{
    //$starttime = microtime(true);
    echo 'Step - User Execution Assignment Migration - STARTED <br> ';
    echo 'Working - User Execution Assignment Migration <br> ';
    $testplan_mgr = new testplan($dbHandler);
    // get assignment type for execution
    $assignment_mgr = new assignment_mgr($dbHandler);
    $assignment_types = $assignment_mgr->get_available_types();
    $execution = $assignment_types['testcase_execution']['id'];
    // get table names
    $ua = $tableSet['user_assignments'];
    $tp_tcv = $tableSet['testplan_tcversions'];
    // get list of test plan IDs from the assigned test cases
    $sql = " SELECT distinct T.testplan_id " . " FROM {$ua} UA, {$tp_tcv} T " . " WHERE UA.feature_id = T.id " . " AND (UA.type={$execution} OR UA.type IS NULL) ";
    $testplans = $dbHandler->fetchColumnsIntoArray($sql, 'testplan_id');
    // Get the newest (max) build ID for each of these test plan IDs and store them.
    // In $testplan_builds, we then have an array consisting of testplan_id => max_build_id
    // If no build for a test plan is found, its assignments will not be changed (build_id=0).
    $testplan_builds = array();
    if (!is_null($testplans)) {
        foreach ($testplans as $key => $tp_id) {
            // first we try to get an active build
            $max_build_id = $testplan_mgr->get_max_build_id($tp_id, testplan::GET_ACTIVE_BUILD);
            // if there is no active build, we get the max id no matter if it is active or not
            if ($max_build_id == 0) {
                $max_build_id = $testplan_mgr->get_max_build_id($tp_id);
            }
            if ($max_build_id > 0) {
                $testplan_builds[$tp_id] = $max_build_id;
            }
        }
        // now update all assignments for these test plans
        foreach ($testplan_builds as $testplan_id => $build_id) {
            $subquery = " SELECT id as feature_id FROM {$tp_tcv} " . " WHERE testplan_id = {$testplan_id} ";
            // This update with ALIAS is not LIKED by Postgres
            //
            // OK
            // UPDATE user_assignments UA
            // SET build_id = 2  WHERE UA.feature_id IN
            // ( SELECT id AS feature_id FROM testplan_tcversions  WHERE testplan_id = 70)
            //
            // if used UA.build_id -> problems on Postgre 8.4
            // Message:
            // ERROR:  column "ua" of relation "user_assignments" does not exist
            // LINE 2: SET UA.build_id = 2  WHERE UA.feature_id IN
            // $sql = " UPDATE {$ua} UA " .
            //        " SET UA.build_id = {$build_id} " .
            //        " WHERE UA.feature_id IN($subquery) " .
            //        " AND (UA.type={$execution} OR UA.type IS NULL) ";
            //
            // 20101212 - franciscom
            $sql = " UPDATE {$ua} " . " SET build_id = {$build_id} " . " WHERE feature_id IN({$subquery}) " . " AND (type={$execution} OR type IS NULL) ";
            $dbHandler->exec_query($sql);
        }
    }
    // delete objects
    unset($testplan_mgr);
    // check how long the function is running on huge databases...
    //$endtime = microtime(true) - $starttime;
    //echo "<br/>migrate_user_assignments() needed $endtime seconds to finish<br/>";
    echo 'Step - User Execution Assignment Migration - Finished <br><br> ';
}
 * @link        http://www.testlink.org
 *
 * @internal revisions
 * @since 1.9.14
 */
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
require_once "treeMenu.inc.php";
require_once 'email_api.php';
require_once "specview.php";
// Time tracking - $chronos[] = microtime(true);$tnow = end($chronos);
testlinkInitPage($db, false, false, "checkRights");
$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) {
Example #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;
 }
 * @author 		  Francisco Mancardi (francisco.mancardi@gmail.com)
 * @copyright 	2005-2012, TestLink community 
 * @link 		    http://www.teamst.org/index.php
 *
 * @internal revisions
 */
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
require_once "treeMenu.inc.php";
require_once 'email_api.php';
require_once "specview.php";
testlinkInitPage($db);
$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($db);
checkRights($db, $_SESSION['currentUser'], $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;
}
if (!is_null($args->doAction)) {
    if (!is_null($args->achecked_tc)) {
        $types_map = $assignment_mgr->get_available_types();
        $status_map = $assignment_mgr->get_available_status();
Example #6
0
echo '<span>Connecting to Testlink 1.6 (source) database. - ' . $db_cfg['source']['db_name'] . ' - </span>';
$source_db = connect_2_db($db_cfg['source']);
// 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";
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 * This script is distributed under the GNU General Public License 2 or later. 
 *
 * @filesource	tc_exec_unassign_all.php
 * @package		TestLink
 * @author		Andreas Simon
 * @copyright	2005-2010, TestLink community 
 * @link		http://www.teamst.org/index.php
 *
 * @internal revisions:
 * 
 */
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
testlinkInitPage($db);
$assignment_mgr = new assignment_mgr($db);
$testplan_mgr = new testplan($db);
$build_mgr = new build_mgr($db);
$templateCfg = templateConfiguration();
$args = init_args($testplan_mgr->tree_manager);
checkRights($db, $_SESSION['currentUser'], $args);
$gui = init_gui($db, $args);
$assignment_count = 0;
$build_name = "";
if ($args->build_id) {
    $assignment_count = $assignment_mgr->get_count_of_assignments_for_build_id($args->build_id);
    $build_info = $build_mgr->get_by_id($args->build_id);
    $build_name = $build_info['name'];
}
if ($assignment_count > 0) {
    if ($args->confirmed) {
Example #8
0
/**
 * Migrate the existing user assignments for all test plans and test projects.
 * All test case execution assignments will be stored per build in TL 1.9.
 * So all tester assignments for the test cases in each test plan will be updated 
 * with the ID of the newest available build for that test plan.
 * 
 * @author Andreas Simon
 * @param database $dbHandler
 * @param array $tableSet
 */
function migrate_user_assignments(&$dbHandler, $tableSet)
{
    //$starttime = microtime(true);
    $testplan_mgr = new testplan($dbHandler);
    // get assignment type for execution
    $assignment_mgr = new assignment_mgr($dbHandler);
    $assignment_types = $assignment_mgr->get_available_types();
    $execution = $assignment_types['testcase_execution']['id'];
    // get table names
    $ua = $tableSet['user_assignments'];
    $tp_tcv = $tableSet['testplan_tcversions'];
    // get list of test plan IDs from the assigned test cases
    $sql = " SELECT distinct T.testplan_id " . " FROM {$ua} UA, {$tp_tcv} T " . " WHERE UA.feature_id = T.id " . " AND (UA.type={$execution} OR UA.type IS NULL) ";
    $testplans = $dbHandler->fetchColumnsIntoArray($sql, 'testplan_id');
    // Get the newest (max) build ID for each of these test plan IDs and store them.
    // In $testplan_builds, we then have an array consisting of testplan_id => max_build_id
    // If no build for a test plan is found, its assignments will not be changed (build_id=0).
    $testplan_builds = array();
    foreach ($testplans as $key => $tp_id) {
        // first we try to get an active build
        $max_build_id = $testplan_mgr->get_max_build_id($tp_id, testplan::GET_ACTIVE_BUILD);
        // if there is no active build, we get the max id no matter if it is active or not
        if ($max_build_id == 0) {
            $max_build_id = $testplan_mgr->get_max_build_id($tp_id);
        }
        if ($max_build_id > 0) {
            $testplan_builds[$tp_id] = $max_build_id;
        }
    }
    // now update all assignments for these test plans
    foreach ($testplan_builds as $testplan_id => $build_id) {
        $subquery = " SELECT id as feature_id FROM {$tp_tcv} " . " WHERE testplan_id = {$testplan_id} ";
        $sql = " UPDATE {$ua} UA " . " SET UA.build_id = {$build_id} " . " WHERE UA.feature_id IN({$subquery}) " . " AND (UA.type={$execution} OR UA.type IS NULL) ";
        $dbHandler->exec_query($sql);
    }
    // delete objects
    unset($testplan_mgr);
    // check how long the function is running on huge databases...
    //$endtime = microtime(true) - $starttime;
    //echo "<br/>migrate_user_assignments() needed $endtime seconds to finish<br/>";
}
 * @filesource  tc_exec_assignment.php
 * @link        http://www.testlink.org
 *
 * @internal revisions
 * @since 1.9.15
 */
require_once dirname(__FILE__) . "/../../config.inc.php";
require_once "common.php";
require_once "treeMenu.inc.php";
require_once 'email_api.php';
require_once "specview.php";
testlinkInitPage($db, false, false, "checkRights");
$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) {
Example #10
0
 // with just one element with key => test case version ID executed.
 //
 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;