/** * Move a bug from one project to another. Also move attachments * @param array p_bug_id integer representing bug id * @param int p_target_project_id */ function bug_move( $p_bug_id, $p_target_project_id ) { global $g_db; $t_mantis_bug_file_table = db_get_table( 'mantis_bug_file_table' ); $t_mantis_db = $g_db; $t_bug_id = db_prepare_int( $p_bug_id ); # retrieve the project id associated with the bug, if not found return if(( $p_target_project_id == null ) || is_blank( $p_target_project_id ) ) { return; } $t_target_project_id = db_prepare_int( $p_target_project_id ); # update project_id in the existing bug bug_set_field( $t_bug_id, 'project_id', $t_target_project_id ); helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) ); # Move 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 ( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content ) VALUES ( " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ", " . db_param() . ");"; db_query_bound( $query, Array( $t_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'] ) ); # delete existing file & reference $old_file = $t_bug_file['diskfile']; // delete reference $query = "DELETE FROM $t_mantis_bug_file_table where diskfile='$old_file' "; db_query_bound($query); // delete physical file $t_method = config_get( 'file_upload_method' ); if(( DISK == $t_method ) || ( FTP == $t_method ) ) { if( FTP == $t_method ) { $ftp = file_ftp_connect(); } $t_local_diskfile = file_normalize_attachment_path( $t_bug_file['diskfile'] ); file_delete_local( $t_local_diskfile ); if( FTP == $t_method ) { file_ftp_delete( $ftp, $t_bug_file['diskfile'] ); } if( FTP == $t_method ) { file_ftp_disconnect( $ftp ); } } } return; }