Esempio n. 1
0
/**
 * Moves an issue from a project to another.
 *
 * @todo Validate with sub-project / category inheritance scenarios.
 * @param int p_bug_id The bug to be moved.
 * @param int p_target_project_id The target project to move the bug to.
 * @access public
 */
function bug_move($p_bug_id, $p_target_project_id)
{
    // Attempt to move disk based attachments to new project file directory.
    file_move_bug_attachments($p_bug_id, $p_target_project_id);
    // Move the issue to the new project.
    bug_set_field($p_bug_id, 'project_id', $p_target_project_id);
    // Update the category if needed
    $t_category_id = bug_get_field($p_bug_id, 'category_id');
    // Bug has no category
    if ($t_category_id == 0) {
        // Category is required in target project, set it to default
        if (ON != config_get('allow_no_category', null, null, $p_target_project_id)) {
            bug_set_field($p_bug_id, 'category_id', config_get('default_category_for_moves'));
        }
    } else {
        $t_category_project_id = category_get_field($t_category_id, 'project_id');
        if ($t_category_project_id != ALL_PROJECTS && !in_array($t_category_project_id, project_hierarchy_inheritance($p_target_project_id))) {
            // Map by name
            $t_category_name = category_get_field($t_category_id, 'name');
            $t_target_project_category_id = category_get_id_by_name($t_category_name, $p_target_project_id, false);
            if ($t_target_project_category_id === false) {
                // Use default category after moves, since there is no match by name.
                $t_target_project_category_id = config_get('default_category_for_moves');
            }
            bug_set_field($p_bug_id, 'category_id', $t_target_project_category_id);
        }
    }
}
Esempio n. 2
0
/**
 * Moves an issue from a project to another.
 *
 * @todo Validate with sub-project / category inheritance scenarios.
 * @param int p_bug_id The bug to be moved.
 * @param int p_target_project_id The target project to move the bug to.
 * @access public
 */
function bug_move( $p_bug_id, $p_target_project_id ) {
	// Attempt to move disk based attachments to new project file directory.
	file_move_bug_attachments( $p_bug_id, $p_target_project_id );

	// Move the issue to the new project.
	bug_set_field( $p_bug_id, 'project_id', $p_target_project_id );

	// Check if the category for the issue is global or not.
	$t_category_id = bug_get_field( $p_bug_id, 'category_id' );
	$t_category_project_id = category_get_field( $t_category_id, 'project_id' );

	// If not global, then attempt mapping it to the new project.
	if ( $t_category_project_id != ALL_PROJECTS && !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_project_id ) ) {
		// Map by name
		$t_category_name = category_get_field( $t_category_id, 'name' );
		$t_target_project_category_id = category_get_id_by_name( $t_category_name, $p_target_project_id, /* triggerErrors */ false );
		if ( $t_target_project_category_id === false ) {
			// Use default category after moves, since there is no match by name.
			$t_target_project_category_id = config_get( 'default_category_for_moves' );
		}

		bug_set_field( $p_bug_id, 'category_id', $t_target_project_category_id );
	}
}