Exemple #1
0
/**
 * Copy a bug from one project to another. Also make copies of issue notes, attachments, history,
 * email notifications etc.
 * @todo Not managed FTP file upload
 * @param array p_bug_id integer representing bug id
 * @param int p_target_project_id
 * @param bool p_copy_custom_fields
 * @param bool p_copy_relationships
 * @return int representing the new bugid
 * @access public
 */
function bug_copy($p_bug_id, $p_target_project_id = null, $p_copy_custom_fields = false, $p_copy_relationships = false, $p_copy_history = false, $p_copy_attachments = false, $p_copy_bugnotes = false, $p_copy_monitoring_users = false)
{
    global $g_db;
    $t_mantis_custom_field_string_table = db_get_table('custom_field_string');
    $t_mantis_bug_file_table = db_get_table('bug_file');
    $t_mantis_bugnote_table = db_get_table('bugnote');
    $t_mantis_bugnote_text_table = db_get_table('bugnote_text');
    $t_mantis_bug_history_table = db_get_table('bug_history');
    $t_mantis_db = $g_db;
    $t_bug_id = db_prepare_int($p_bug_id);
    $t_target_project_id = db_prepare_int($p_target_project_id);
    $t_bug_data = bug_get($t_bug_id, true);
    # retrieve the project id associated with the bug
    if ($p_target_project_id == null || is_blank($p_target_project_id)) {
        $t_target_project_id = $t_bug_data->project_id;
    }
    $t_bug_data->project_id = $t_target_project_id;
    $t_new_bug_id = $t_bug_data->create();
    # MASC ATTENTION: IF THE SOURCE BUG HAS TO HANDLER THE bug_create FUNCTION CAN TRY TO AUTO-ASSIGN THE BUG
    # WE FORCE HERE TO DUPLICATE THE SAME HANDLER OF THE SOURCE BUG
    # @todo VB: Shouldn't we check if the handler in the source project is also a handler in the destination project?
    bug_set_field($t_new_bug_id, 'handler_id', $t_bug_data->handler_id);
    bug_set_field($t_new_bug_id, 'duplicate_id', $t_bug_data->duplicate_id);
    bug_set_field($t_new_bug_id, 'status', $t_bug_data->status);
    bug_set_field($t_new_bug_id, 'resolution', $t_bug_data->resolution);
    bug_set_field($t_new_bug_id, 'projection', $t_bug_data->projection);
    bug_set_field($t_new_bug_id, 'date_submitted', $t_bug_data->date_submitted);
    bug_set_field($t_new_bug_id, 'last_updated', $t_bug_data->last_updated);
    bug_set_field($t_new_bug_id, 'eta', $t_bug_data->eta);
    bug_set_field($t_new_bug_id, 'fixed_in_version', $t_bug_data->fixed_in_version);
    bug_set_field($t_new_bug_id, 'target_version', $t_bug_data->target_version);
    bug_set_field($t_new_bug_id, 'sponsorship_total', 0);
    bug_set_field($t_new_bug_id, 'sticky', 0);
    bug_set_field($t_new_bug_id, 'due_date', $t_bug_data->due_date);
    # COPY CUSTOM FIELDS
    if ($p_copy_custom_fields) {
        $query = "SELECT field_id, bug_id, value\n\t\t\t\t\t   FROM {$t_mantis_custom_field_string_table}\n\t\t\t\t\t   WHERE bug_id=" . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_custom = db_fetch_array($result);
            $c_field_id = db_prepare_int($t_bug_custom['field_id']);
            $c_new_bug_id = db_prepare_int($t_new_bug_id);
            $c_value = $t_bug_custom['value'];
            $query = "INSERT INTO {$t_mantis_custom_field_string_table}\n\t\t\t\t\t\t   ( field_id, bug_id, value )\n\t\t\t\t\t\t   VALUES (" . db_param() . ', ' . db_param() . ', ' . db_param() . ')';
            db_query_bound($query, array($c_field_id, $c_new_bug_id, $c_value));
        }
    }
    # Copy Relationships
    if ($p_copy_relationships) {
        relationship_copy_all($t_bug_id, $t_new_bug_id);
    }
    # Copy bugnotes
    if ($p_copy_bugnotes) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bugnote_table}\n\t\t\t\t\t  WHERE bug_id=" . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_note = db_fetch_array($result);
            $t_bugnote_text_id = $t_bug_note['bugnote_text_id'];
            $query2 = "SELECT *\n\t\t\t\t\t\t   FROM {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t   WHERE id=" . db_param();
            $result2 = db_query_bound($query2, array($t_bugnote_text_id));
            $t_count2 = db_num_rows($result2);
            $t_bugnote_text_insert_id = -1;
            if ($t_count2 > 0) {
                $t_bugnote_text = db_fetch_array($result2);
                $query2 = "INSERT INTO {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t\t   ( note )\n\t\t\t\t\t\t\t   VALUES ( " . db_param() . ' )';
                db_query_bound($query2, array($t_bugnote_text['note']));
                $t_bugnote_text_insert_id = db_insert_id($t_mantis_bugnote_text_table);
            }
            $query2 = "INSERT INTO {$t_mantis_bugnote_table}\n\t\t\t\t\t\t   ( bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified )\n\t\t\t\t\t\t   VALUES ( " . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ')';
            db_query_bound($query2, array($t_new_bug_id, $t_bug_note['reporter_id'], $t_bugnote_text_insert_id, $t_bug_note['view_state'], $t_bug_note['date_submitted'], $t_bug_note['last_modified']));
        }
    }
    # Copy attachments
    if ($p_copy_attachments) {
        $query = 'SELECT * FROM ' . $t_mantis_bug_file_table . ' WHERE bug_id = ' . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        $t_bug_file = array();
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_file = db_fetch_array($result);
            # prepare the new diskfile name and then copy the file
            $t_file_path = dirname($t_bug_file['folder']);
            $t_new_diskfile_name = $t_file_path . file_generate_unique_name('bug-' . $t_bug_file['filename'], $t_file_path);
            $t_new_file_name = file_get_display_name($t_bug_file['filename']);
            if (config_get('file_upload_method') == DISK) {
                copy($t_bug_file['diskfile'], $t_new_diskfile_name);
                chmod($t_new_diskfile_name, config_get('attachments_file_permissions'));
            }
            $query = "INSERT INTO {$t_mantis_bug_file_table}\n\t\t\t\t\t\t( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content )\n\t\t\t\t\t\tVALUES ( " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ",\n\t\t\t\t\t\t\t\t " . db_param() . ");";
            db_query_bound($query, array($t_new_bug_id, $t_bug_file['title'], $t_bug_file['description'], $t_new_diskfile_name, $t_new_file_name, $t_bug_file['folder'], $t_bug_file['filesize'], $t_bug_file['file_type'], $t_bug_file['date_added'], $t_bug_file['content']));
        }
    }
    # Copy users monitoring bug
    if ($p_copy_monitoring_users) {
        bug_monitor_copy($t_bug_id, $t_new_bug_id);
    }
    # COPY HISTORY
    history_delete($t_new_bug_id);
    # should history only be deleted inside the if statement below?
    if ($p_copy_history) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bug_history_table}\n\t\t\t\t\t  WHERE bug_id = " . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_history = db_fetch_array($result);
            $query = "INSERT INTO {$t_mantis_bug_history_table}\n\t\t\t\t\t\t  ( user_id, bug_id, date_modified, field_name, old_value, new_value, type )\n\t\t\t\t\t\t  VALUES ( " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . " );";
            db_query_bound($query, array($t_bug_history['user_id'], $t_new_bug_id, $t_bug_history['date_modified'], $t_bug_history['field_name'], $t_bug_history['old_value'], $t_bug_history['new_value'], $t_bug_history['type']));
        }
    }
    return $t_new_bug_id;
}
/**
 * Copy a bug from one project to another. Also make copies of issue notes, attachments, history,
 * email notifications etc.
 * @todo Not managed FTP file upload
 * @param array p_bug_id integer representing bug id
 * @param int p_target_project_id
 * @param bool p_copy_custom_fields
 * @param bool p_copy_relationships
 * @param bool p_copy_history
 * @param bool p_copy_attachments
 * @param bool p_copy_bugnotes
 * @param bool p_copy_monitoring_users
 * @return int representing the new bugid
 * @access public
 */
function bug_copy($p_bug_id, $p_target_project_id = null, $p_copy_custom_fields = false, $p_copy_relationships = false, $p_copy_history = false, $p_copy_attachments = false, $p_copy_bugnotes = false, $p_copy_monitoring_users = false)
{
    global $g_db;
    $t_mantis_custom_field_string_table = db_get_table('mantis_custom_field_string_table');
    $t_mantis_bug_file_table = db_get_table('mantis_bug_file_table');
    $t_mantis_bugnote_table = db_get_table('mantis_bugnote_table');
    $t_mantis_bugnote_text_table = db_get_table('mantis_bugnote_text_table');
    $t_mantis_bug_history_table = db_get_table('mantis_bug_history_table');
    $t_mantis_db = $g_db;
    $t_bug_id = db_prepare_int($p_bug_id);
    $t_target_project_id = db_prepare_int($p_target_project_id);
    $t_bug_data = bug_get($t_bug_id, true);
    # retrieve the project id associated with the bug
    if ($p_target_project_id == null || is_blank($p_target_project_id)) {
        $t_target_project_id = $t_bug_data->project_id;
    }
    $t_bug_data->project_id = $t_target_project_id;
    $t_bug_data->reporter_id = auth_get_current_user_id();
    $t_new_bug_id = $t_bug_data->create();
    # MASC ATTENTION: IF THE SOURCE BUG HAS TO HANDLER THE bug_create FUNCTION CAN TRY TO AUTO-ASSIGN THE BUG
    # WE FORCE HERE TO DUPLICATE THE SAME HANDLER OF THE SOURCE BUG
    # @todo VB: Shouldn't we check if the handler in the source project is also a handler in the destination project?
    bug_set_field($t_new_bug_id, 'handler_id', $t_bug_data->handler_id);
    bug_set_field($t_new_bug_id, 'duplicate_id', $t_bug_data->duplicate_id);
    bug_set_field($t_new_bug_id, 'status', $t_bug_data->status);
    bug_set_field($t_new_bug_id, 'resolution', $t_bug_data->resolution);
    bug_set_field($t_new_bug_id, 'projection', $t_bug_data->projection);
    bug_set_field($t_new_bug_id, 'eta', $t_bug_data->eta);
    bug_set_field($t_new_bug_id, 'fixed_in_version', $t_bug_data->fixed_in_version);
    bug_set_field($t_new_bug_id, 'target_version', $t_bug_data->target_version);
    bug_set_field($t_new_bug_id, 'sponsorship_total', 0);
    bug_set_field($t_new_bug_id, 'sticky', 0);
    bug_set_field($t_new_bug_id, 'due_date', $t_bug_data->due_date);
    # COPY CUSTOM FIELDS
    if ($p_copy_custom_fields) {
        $query = "SELECT field_id, bug_id, value\n\t\t\t\t\t   FROM {$t_mantis_custom_field_string_table}\n\t\t\t\t\t   WHERE bug_id=" . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_custom = db_fetch_array($result);
            $c_field_id = db_prepare_int($t_bug_custom['field_id']);
            $c_new_bug_id = db_prepare_int($t_new_bug_id);
            $c_value = $t_bug_custom['value'];
            $query = "INSERT INTO {$t_mantis_custom_field_string_table}\n\t\t\t\t\t\t   ( field_id, bug_id, value )\n\t\t\t\t\t\t   VALUES (" . db_param() . ', ' . db_param() . ', ' . db_param() . ')';
            db_query_bound($query, array($c_field_id, $c_new_bug_id, $c_value));
        }
    }
    # Copy Relationships
    if ($p_copy_relationships) {
        relationship_copy_all($t_bug_id, $t_new_bug_id);
    }
    # Copy bugnotes
    if ($p_copy_bugnotes) {
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bugnote_table}\n\t\t\t\t\t  WHERE bug_id=" . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_note = db_fetch_array($result);
            $t_bugnote_text_id = $t_bug_note['bugnote_text_id'];
            $query2 = "SELECT *\n\t\t\t\t\t\t   FROM {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t   WHERE id=" . db_param();
            $result2 = db_query_bound($query2, array($t_bugnote_text_id));
            $t_count2 = db_num_rows($result2);
            $t_bugnote_text_insert_id = -1;
            if ($t_count2 > 0) {
                $t_bugnote_text = db_fetch_array($result2);
                $query2 = "INSERT INTO {$t_mantis_bugnote_text_table}\n\t\t\t\t\t\t\t   ( note )\n\t\t\t\t\t\t\t   VALUES ( " . db_param() . ' )';
                db_query_bound($query2, array($t_bugnote_text['note']));
                $t_bugnote_text_insert_id = db_insert_id($t_mantis_bugnote_text_table);
            }
            $query2 = "INSERT INTO {$t_mantis_bugnote_table}\n\t\t\t\t\t\t   ( bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified )\n\t\t\t\t\t\t   VALUES ( " . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ",\n\t\t\t\t\t\t   \t\t\t" . db_param() . ')';
            db_query_bound($query2, array($t_new_bug_id, $t_bug_note['reporter_id'], $t_bugnote_text_insert_id, $t_bug_note['view_state'], $t_bug_note['date_submitted'], $t_bug_note['last_modified']));
        }
    }
    # Copy attachments
    if ($p_copy_attachments) {
        file_copy_attachments($t_bug_id, $t_new_bug_id);
    }
    # Copy users monitoring bug
    if ($p_copy_monitoring_users) {
        bug_monitor_copy($t_bug_id, $t_new_bug_id);
    }
    # COPY HISTORY
    history_delete($t_new_bug_id);
    # should history only be deleted inside the if statement below?
    if ($p_copy_history) {
        # @todo problem with this code: the generated history trail is incorrect because the note IDs are those of the original bug, not the copied ones
        # @todo actually, does it even make sense to copy the history ?
        $query = "SELECT *\n\t\t\t\t\t  FROM {$t_mantis_bug_history_table}\n\t\t\t\t\t  WHERE bug_id = " . db_param();
        $result = db_query_bound($query, array($t_bug_id));
        $t_count = db_num_rows($result);
        for ($i = 0; $i < $t_count; $i++) {
            $t_bug_history = db_fetch_array($result);
            $query = "INSERT INTO {$t_mantis_bug_history_table}\n\t\t\t\t\t\t  ( user_id, bug_id, date_modified, field_name, old_value, new_value, type )\n\t\t\t\t\t\t  VALUES ( " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . ",\n\t\t\t\t\t\t  \t\t   " . db_param() . " );";
            db_query_bound($query, array($t_bug_history['user_id'], $t_new_bug_id, $t_bug_history['date_modified'], $t_bug_history['field_name'], $t_bug_history['old_value'], $t_bug_history['new_value'], $t_bug_history['type']));
        }
    } else {
        # Create a "New Issue" history entry
        history_log_event_special($t_new_bug_id, NEW_BUG);
    }
    # Create history entries to reflect the copy operation
    history_log_event_special($t_new_bug_id, BUG_CREATED_FROM, '', $t_bug_id);
    history_log_event_special($t_bug_id, BUG_CLONED_TO, '', $t_new_bug_id);
    return $t_new_bug_id;
}
Exemple #3
0
/**
 * Copy a bug from one project to another. Also make copies of issue notes, attachments, history,
 * email notifications etc.
 * @todo Not managed FTP file upload
 * @param array p_bug_id integer representing bug id
 * @param int p_target_project_id
 * @param bool p_copy_custom_fields
 * @param bool p_copy_relationships
 * @return int representing the new bugid
 * @access public
 */
function bug_copy( $p_bug_id, $p_target_project_id = null, $p_copy_custom_fields = false, $p_copy_relationships = false, $p_copy_history = false, $p_copy_attachments = false, $p_copy_bugnotes = false, $p_copy_monitoring_users = false ) {
	global $g_db;

	$t_mantis_custom_field_string_table = db_get_table( 'custom_field_string' );
	$t_mantis_bug_file_table = db_get_table( 'bug_file' );
	$t_mantis_bugnote_table = db_get_table( 'bugnote' );
	$t_mantis_bugnote_text_table = db_get_table( 'bugnote_text' );
	$t_mantis_bug_history_table = db_get_table( 'bug_history' );
	$t_mantis_db = $g_db;

	$t_bug_id = db_prepare_int( $p_bug_id );
	$t_target_project_id = db_prepare_int( $p_target_project_id );

	$t_bug_data = bug_get( $t_bug_id, true );

	# retrieve the project id associated with the bug
	if(( $p_target_project_id == null ) || is_blank( $p_target_project_id ) ) {
		$t_target_project_id = $t_bug_data->project_id;
	}

	$t_bug_data->project_id = $t_target_project_id;

	$t_new_bug_id = $t_bug_data->create();

	# MASC ATTENTION: IF THE SOURCE BUG HAS TO HANDLER THE bug_create FUNCTION CAN TRY TO AUTO-ASSIGN THE BUG
	# WE FORCE HERE TO DUPLICATE THE SAME HANDLER OF THE SOURCE BUG
	# @todo VB: Shouldn't we check if the handler in the source project is also a handler in the destination project?
	bug_set_field( $t_new_bug_id, 'handler_id', $t_bug_data->handler_id );

	bug_set_field( $t_new_bug_id, 'duplicate_id', $t_bug_data->duplicate_id );
	bug_set_field( $t_new_bug_id, 'status', $t_bug_data->status );
	bug_set_field( $t_new_bug_id, 'resolution', $t_bug_data->resolution );
	bug_set_field( $t_new_bug_id, 'projection', $t_bug_data->projection );
	bug_set_field( $t_new_bug_id, 'date_submitted', $t_bug_data->date_submitted );
	bug_set_field( $t_new_bug_id, 'last_updated', $t_bug_data->last_updated );
	bug_set_field( $t_new_bug_id, 'eta', $t_bug_data->eta );
	bug_set_field( $t_new_bug_id, 'fixed_in_version', $t_bug_data->fixed_in_version );
	bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
	bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
	bug_set_field( $t_new_bug_id, 'sticky', 0 );
	bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );

	# COPY CUSTOM FIELDS
	if( $p_copy_custom_fields ) {
		$query = "SELECT field_id, bug_id, value
					   FROM $t_mantis_custom_field_string_table
					   WHERE bug_id=" . db_param();
		$result = db_query_bound( $query, Array( $t_bug_id ) );
		$t_count = db_num_rows( $result );

		for( $i = 0;$i < $t_count;$i++ ) {
			$t_bug_custom = db_fetch_array( $result );

			$c_field_id = db_prepare_int( $t_bug_custom['field_id'] );
			$c_new_bug_id = db_prepare_int( $t_new_bug_id );
			$c_value = $t_bug_custom['value'];

			$query = "INSERT INTO $t_mantis_custom_field_string_table
						   ( field_id, bug_id, value )
						   VALUES (" . db_param() . ', ' . db_param() . ', ' . db_param() . ')';
			db_query_bound( $query, Array( $c_field_id, $c_new_bug_id, $c_value ) );
		}
	}

	# Copy Relationships
	if( $p_copy_relationships ) {
		relationship_copy_all( $t_bug_id, $t_new_bug_id );
	}

	# Copy bugnotes
	if( $p_copy_bugnotes ) {
		$query = "SELECT *
					  FROM $t_mantis_bugnote_table
					  WHERE bug_id=" . db_param();
		$result = db_query_bound( $query, Array( $t_bug_id ) );
		$t_count = db_num_rows( $result );

		for( $i = 0;$i < $t_count;$i++ ) {
			$t_bug_note = db_fetch_array( $result );
			$t_bugnote_text_id = $t_bug_note['bugnote_text_id'];

			$query2 = "SELECT *
						   FROM $t_mantis_bugnote_text_table
						   WHERE id=" . db_param();
			$result2 = db_query_bound( $query2, Array( $t_bugnote_text_id ) );
			$t_count2 = db_num_rows( $result2 );

			$t_bugnote_text_insert_id = -1;
			if( $t_count2 > 0 ) {
				$t_bugnote_text = db_fetch_array( $result2 );

				$query2 = "INSERT INTO $t_mantis_bugnote_text_table
							   ( note )
							   VALUES ( " . db_param() . ' )';
				db_query_bound( $query2, Array( $t_bugnote_text['note'] ) );
				$t_bugnote_text_insert_id = db_insert_id( $t_mantis_bugnote_text_table );
			}

			$query2 = "INSERT INTO $t_mantis_bugnote_table
						   ( bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified )
						   VALUES ( " . db_param() . ",
						   			" . db_param() . ",
						   			" . db_param() . ",
						   			" . db_param() . ",
						   			" . db_param() . ",
						   			" . db_param() . ')';
			db_query_bound( $query2, Array( $t_new_bug_id, $t_bug_note['reporter_id'], $t_bugnote_text_insert_id, $t_bug_note['view_state'], $t_bug_note['date_submitted'], $t_bug_note['last_modified'] ) );
		}
	}

	# Copy attachments
	if( $p_copy_attachments ) {
	    file_copy_attachments( $t_bug_id , $t_new_bug_id );
	}

	# Copy users monitoring bug
	if( $p_copy_monitoring_users ) {
		bug_monitor_copy( $t_bug_id, $t_new_bug_id );
	}

	# COPY HISTORY
	history_delete( $t_new_bug_id );	# should history only be deleted inside the if statement below?
	if( $p_copy_history ) {
		$query = "SELECT *
					  FROM $t_mantis_bug_history_table
					  WHERE bug_id = " . db_param();
		$result = db_query_bound( $query, Array( $t_bug_id ) );
		$t_count = db_num_rows( $result );

		for( $i = 0;$i < $t_count;$i++ ) {
			$t_bug_history = db_fetch_array( $result );
			$query = "INSERT INTO $t_mantis_bug_history_table
						  ( user_id, bug_id, date_modified, field_name, old_value, new_value, type )
						  VALUES ( " . db_param() . ",
						  		   " . db_param() . ",
						  		   " . db_param() . ",
						  		   " . db_param() . ",
						  		   " . db_param() . ",
						  		   " . db_param() . ",
						  		   " . db_param() . " );";
			db_query_bound( $query, Array( $t_bug_history['user_id'], $t_new_bug_id, $t_bug_history['date_modified'], $t_bug_history['field_name'], $t_bug_history['old_value'], $t_bug_history['new_value'], $t_bug_history['type'] ) );
		}
	}

	return $t_new_bug_id;
}