' . lang_get( 'importing_from' ) . $f_import_file['name'] . '
'; $f_fieldlim = gpc_get_string( 'fieldlim' ); $f_linelim = gpc_get_string( 'linelim' ); $f_client = gpc_get_bool( 'client' ); # get submitted data - target project id. # go no further if current project is "All Projects". $t_project_id = helper_get_current_project(); if ( $t_project_id == ALL_PROJECTS ) { echo '' . lang_get( 'import_reject_all_projects' ) . project_get_name( $t_project_id ) . '.
'; html_page_bottom1( __FILE__ ); return; } echo '' . lang_get( 'importing_into_project' ) . project_get_name( $t_project_id ) . '
'; # get submitted data - column data sources. $f_reporterx = gpc_get_int( 'reporter' ); $f_const_reporter = gpc_get_int( 'const_reporter', auth_get_current_user_id() ); $f_handlerx = gpc_get_int( 'handler' ); $f_const_handler = gpc_get_int( 'const_handler', 0 ); $f_priorityx = gpc_get_int( 'priority' ); $f_const_priority = gpc_get_int( 'const_priority', config_get( 'default_bug_priority' ) ); $f_severityx = gpc_get_int( 'severity' ); $f_const_severity = gpc_get_int( 'const_severity', config_get( 'default_bug_severity' ) ); $f_reproducibilityx = gpc_get_int( 'reproducibility' ); $f_const_reproducibility = gpc_get_int( 'const_reproducibility', 0 ); $f_statusx = gpc_get_int( 'status' ); $f_const_status = gpc_get_int( 'const_status', config_get( 'bug_submit_status' ) ); $f_resolutionx = gpc_get_int( 'resolution' ); $f_const_resolution = gpc_get_int( 'const_resolution', OPEN ); $f_categoryx = gpc_get_int( 'category' ); $f_const_category = gpc_get_string( 'const_category', '' ); $f_date_submittedx = gpc_get_int( 'date_submitted' ); $f_const_date_submitted = gpc_get_string( 'const_date_submitted', '' ); $f_osx = gpc_get_int( 'os' ); $f_const_os = gpc_get_string( 'const_os' ); $f_os_buildx = gpc_get_int( 'os_build' ); $f_const_os_build = gpc_get_string( 'const_os_build' ); $f_platformx = gpc_get_int( 'platform' ); $f_const_platform = gpc_get_string( 'const_platform' ); $f_versionx = gpc_get_int( 'version' ); $f_const_version = gpc_get_string( 'const_version' ); $f_fixed_in_versionx = gpc_get_int( 'fixed_in_version' ); $f_const_fixed_in_version = gpc_get_string( 'const_fixed_in_version' ); $f_buildx = gpc_get_int( 'build' ); $f_const_build = gpc_get_string( 'const_build' ); $f_view_statex = gpc_get_int( 'view_state' ); $f_const_view_state = gpc_get_int( 'const_view_state', config_get( 'default_bug_view_status' ) ); $f_summaryx = gpc_get_int( 'summary' ); $f_descriptionx = gpc_get_int( 'description' ); $f_const_description = gpc_get_string( 'const_description' ); $f_steps_to_reproducex = gpc_get_int( 'steps_to_reproduce' ); $f_const_steps_to_reproduce = gpc_get_string( 'const_steps_to_reproduce' ); $f_additional_informationx = gpc_get_int( 'additional_information' ); $f_const_additional_information = gpc_get_string( 'const_additional_information' ); # check completeness if ( is_blank( $f_import_file['tmp_name'] ) || ( $f_import_file['size'] == 0 ) || is_blank( $f_fieldlim ) || is_blank( $f_linelim ) ) { trigger_error( ERROR_EMPTY_FIELD, ERROR ); } $t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id ); foreach( $t_related_custom_field_ids as $t_id ) { $t_def = custom_field_get_definition( $t_id ); if ( ( gpc_get_int( "choice_custom_field_$t_id" ) == IMPORT_USE_CONST_VALUE ) && ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], $t_def['default_value'] ) ) ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } } # build column list for import $t_column_array = array(); $t_column_count = 0; if ( $f_reporterx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'reporter'; } if ( $f_handlerx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'handler'; } if ( $f_priorityx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'priority'; } if ( $f_severityx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'severity'; } if ( $f_reproducibilityx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'reproducibility'; } if ( $f_statusx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'status'; } if ( $f_resolutionx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'resolution'; } if ( $f_categoryx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'category'; } if ( $f_date_submittedx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'date_submitted'; } if ( $f_osx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'os'; } if ( $f_os_buildx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'os_build'; } if ( $f_platformx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'platform'; } if ( $f_versionx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'version'; } if ( $f_fixed_in_versionx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'fixed_in_version'; } if ( $f_buildx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'build'; } if ( $f_view_statex == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'view_state'; } if ( $f_summaryx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'summary'; } if ( $f_descriptionx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'description'; } if ( $f_steps_to_reproducex == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'reproduce'; } if ( $f_additional_informationx == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = 'info'; } foreach( $t_related_custom_field_ids as $t_id ) { if ( gpc_get_int( "choice_custom_field_$t_id" ) == IMPORT_FROM_FILE ) { $t_column_array[$t_column_count++] = "custom_field_$t_id"; } } $t_column_list = "(" . implode ( "," , $t_column_array ) . ")"; echo '' . lang_get( 'importing_columns' ) . $t_column_list . '
'; # drop import table if it remains from a previous import attempt # (may wind up with duplicate records otherwise). $t_mantis_import_issues_table = config_get( 'db_table_prefix' ) . '_import_issues' . config_get( 'db_table_suffix' ); $query = 'DROP TABLE IF EXISTS ' . $t_mantis_import_issues_table; db_query( $query ); # create temporary table for uploading data. $query = 'CREATE TABLE ' . $t_mantis_import_issues_table . '(' . 'reporter VARCHAR(32)' . ', handler VARCHAR(32)' . ', priority VARCHAR(32)' . ', severity VARCHAR(32)' . ', reproducibility VARCHAR(32)' . ', status VARCHAR(32)' . ', resolution VARCHAR(32)' . ', category VARCHAR(64)' . ', date_submitted DATETIME' . ', os VARCHAR(32)' . ', os_build VARCHAR(32)' . ', platform VARCHAR(32)' . ', version VARCHAR(64)' . ', fixed_in_version VARCHAR(64)' . ', build VARCHAR(32)' . ', view_state VARCHAR(64)' . ', summary VARCHAR(128)' . ', description TEXT' . ', reproduce TEXT' . ', info TEXT' ; foreach( $t_related_custom_field_ids as $t_id ) { $query .= ", custom_field_$t_id VARCHAR(255)" ; } $query .= ' ) '; db_query( $query ); $c_import_file = db_prepare_string( $f_import_file['tmp_name'] ); $c_fieldlim = db_prepare_string( $f_fieldlim ); if ( $f_linelim == '\r' ) $c_linelim = '\r'; else if ( $f_linelim == '\n' ) $c_linelim = '\n'; else $c_linelim = '\r\n'; # upload data into temporary table. if ( $f_client ) { $query = 'LOAD DATA INFILE '; } else { $query = 'LOAD DATA LOCAL INFILE '; } $query .= '"'; $query .= $c_import_file ; $query .= '"'; $query .= ' REPLACE INTO TABLE ' . $t_mantis_import_issues_table . ' FIELDS TERMINATED BY ' ; $query .= '"'; $query .= $c_fieldlim ; $query .= '"'; $query .= ' LINES TERMINATED BY '; $query .= '"'; $query .= $c_linelim ; $query .= '" '; $query .= $t_column_list ; $query .= ";"; db_query( $query ); # do actual importing here: # for each row in temporary table, # - construct a BugData object # - use bug_create to create a new issue. $t_bug_count = 0; $t_success_count = 0; $t_error_count = 0; $query = 'SELECT * FROM ' . $t_mantis_import_issues_table; $result = db_query( $query ); $num_rows = db_num_rows($result); # @@@ mgf: inserted # print_r($num_rows); # @@@ mgf: inserted to test for ($i=0;$i<$num_rows;$i++) { # @@@ mgf: inserted # while ( $t_row = db_fetch_array( $result ) ) { # @@@ mgf: use $num_files instead of this line and fudge below # @@@ note: the following ugly fudge is present to catch the end of file - gtomlin # if ( in_array( chr( 26 ), $t_row ) ) # @@@ mgf: commented out # break; # @@@ mgf: commented out # echo($i); # @@@ mgf: inserted to test $t_row = db_fetch_array( $result ); # @@@ mgf: inserted # print_r($t_row); # @@@ mgf: inserted to test $t_bug_count++; /* # @@@ mgf: replaced all numerical indices into $t_row by actual keys # @@@ mgf: custom fields must then be treated differently also, see below $t_col = 0; $t_reporter = $t_row[$t_col++]; $t_handler = $t_row[$t_col++]; $t_priority = $t_row[$t_col++]; $t_severity = $t_row[$t_col++]; $t_reproducibility = $t_row[$t_col++]; $t_status = $t_row[$t_col++]; $t_resolution = $t_row[$t_col++]; $t_category = $t_row[$t_col++]; $t_date_submitted = $t_row[$t_col++]; $t_os = $t_row[$t_col++]; $t_os_build = $t_row[$t_col++]; $t_platform = $t_row[$t_col++]; $t_version = $t_row[$t_col++]; $t_fixed_in_version = $t_row[$t_col++]; $t_build = $t_row[$t_col++]; $t_view_state = $t_row[$t_col++]; $t_summary = $t_row[$t_col++]; $t_description = $t_row[$t_col++]; $t_steps_to_reproduce = $t_row[$t_col++]; $t_additional_information = $t_row[$t_col++]; */ $t_reporter = $t_row['reporter']; $t_handler = $t_row['handler']; $t_priority = $t_row['priority']; $t_severity = $t_row['severity']; $t_reproducibility = $t_row['reproducibility']; $t_status = $t_row['status']; $t_resolution = $t_row['resolution']; $t_category = $t_row['category']; $t_date_submitted = $t_row['date_submitted']; $t_os = $t_row['os']; $t_os_build = $t_row['os_build']; $t_platform = $t_row['platform']; $t_version = $t_row['version']; $t_fixed_in_version = $t_row['fixed_in_version']; $t_build = $t_row['build']; $t_view_state = $t_row['view_state']; $t_summary = $t_row['summary']; $t_description = $t_row['description']; $t_steps_to_reproduce = $t_row['reproduce']; $t_additional_information = $t_row['info']; # this number should reflect the number of standard columns, this is used later to calculate # @@@ mgf: no, key is now used # the index of the first custom field. # @@@ mgf: no, key is now used # $t_num_of_columns = $t_col; # @@@ mgf: no, this is not used anymore, see below if ( is_blank( $t_description ) ) { $t_description = $t_summary; } # Fill the fields for uploading # Set up reporter_id (if value is from file must translate from string to id) if ( $f_reporterx == IMPORT_FROM_FILE ) { $t_reporter_id = user_get_id_by_name( $t_reporter ); } else if ( $f_reporterx == IMPORT_USE_CONST_VALUE ) { $t_reporter_id = $f_const_reporter; } else { $t_reporter_id = 1 ; } # Set up handler_id (if value is from file must translate from string to id) if ( $f_handlerx == IMPORT_FROM_FILE ) { $t_handler_id = user_get_id_by_name( $t_handler ); } else if ( $f_handlerx == IMPORT_USE_CONST_VALUE ) { $t_handler_id = $f_const_handler; } else { $t_handler_id = 0 ; } # Set up duplicate_id (hard coded since it's the # ID of another bug, which could be in import stream so we will not know its ID). $t_duplicate_id = 0; # Set up priority (if value is from file must translate from string to id) if ( $f_priorityx == IMPORT_FROM_FILE ) { $t_priority = get_string_to_enum( 'priority', $t_priority ); } else if ( $f_priorityx == IMPORT_USE_CONST_VALUE ) { $t_priority = $f_const_priority; } else { $t_priority = config_get( 'default_bug_priority' ) ; } # Set up severity (if value is from file must translate from string to id) if ( $f_severityx == IMPORT_FROM_FILE ) { $t_severity = get_string_to_enum( 'severity', $t_severity ); } else if ( $f_severityx == IMPORT_USE_CONST_VALUE ) { $t_severity = $f_const_severity; } else { $t_severity = config_get( 'default_bug_severity' ) ; } # Set up reproducibility (if value is from file must translate from string to id) if ( $f_reproducibilityx == IMPORT_FROM_FILE ) { $t_reproducibility = get_string_to_enum( 'reproducibility', $t_reproducibility ); } else if ( $f_reproducibilityx == IMPORT_USE_CONST_VALUE ) { $t_reproducibility = $f_const_reproducibility; } else { $t_reproducibility = 10 ; } # Set up status (if value is from file must translate from string to id) if ( $f_statusx == IMPORT_FROM_FILE ) { $t_status = get_string_to_enum( 'status', $t_status ); } else if ( $f_statusx == IMPORT_USE_CONST_VALUE ) { $t_status = $f_const_status; } else { $t_status = config_get( 'bug_submit_status' ) ; } # Default resolution - bug_create will set value if ( $f_resolutionx == IMPORT_FROM_FILE ) { $t_resolution = get_string_to_enum( 'resolution', $t_resolution ); } else if ( $f_resolutionx == IMPORT_USE_CONST_VALUE ) { $t_resolution = $f_const_resolution; } else { $t_resolution = OPEN ; } # Default projection - bug_create will set value $t_projection = 10 ; # Set up category # @@@ should not really trust value from file here! (gtomlin) if ( $f_categoryx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_categoryx == IMPORT_USE_CONST_VALUE ) { $t_category = $f_const_category; } else { $t_category = '' ; } # Date fields. Last updated is set to now by bug_create if ( $f_date_submittedx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_date_submittedx == IMPORT_USE_CONST_VALUE ) { $t_date_submitted = $f_const_date_submitted; } else { $t_date_submitted = '' ; } $t_last_updated = ''; # Default eta - bug_create will set value $t_eta = 10 ; # Set up os if ( $f_osx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_osx == IMPORT_USE_CONST_VALUE ) { $t_os = $f_const_os; } else { $t_os = '' ; } # Set up os_build if ( $f_os_buildx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_os_buildx == IMPORT_USE_CONST_VALUE ) { $t_os_build = $f_const_os_build; } else { $t_os_build = ''; } # Set up platform if( $f_platformx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_platformx == IMPORT_USE_CONST_VALUE ) { $t_platform = $f_const_platform; } else { $t_platform = '' ; } # Set up version (should not really trust value from file here) if ( $f_versionx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_versionx == IMPORT_USE_CONST_VALUE ) { $t_version = $f_const_version; } else { $t_version = '' ; } # Set up fixed_in_version (should not really trust value from file here) if ( $f_fixed_in_versionx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_fixed_in_versionx == IMPORT_USE_CONST_VALUE ) { $t_fixed_in_version = $f_const_fixed_in_version; } else { $t_fixed_in_version = '' ; } # Set up build if( $f_buildx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_buildx == IMPORT_USE_CONST_VALUE ) { $t_build = $f_const_build; } else { $t_build = '' ; } # Set up view state if( $f_view_statex == IMPORT_FROM_FILE ) { $t_view_state = get_string_to_enum( 'view_state', $t_view_state ); } else if ( $f_buildx == IMPORT_USE_CONST_VALUE ) { $t_view_state = $f_const_view_state; } else { $t_view_state = config_get( 'default_bug_view_status' ) ; } # Defaulting sponsorship for now. $t_sponsorship_total = 0; # Set up description if( $f_descriptionx == IMPORT_FROM_FILE ) { # do nothing } else { $t_description = $f_const_description; } # Set up steps to reproduce if( $f_steps_to_reproducex == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_steps_to_reproducex == IMPORT_USE_CONST_VALUE ) { $t_steps_to_reproduce = $f_const_steps_to_reproduce; } else { $t_steps_to_reproduce = ''; } # Set up additional information if( $f_additional_informationx == IMPORT_FROM_FILE ) { # do nothing } else if ( $f_additional_informationx == IMPORT_USE_CONST_VALUE ) { $t_additional_information = $f_const_additional_information; } else { $t_additional_information = '' ; } # Defaulting profile_id for now. $t_profile_id = 0; # Create the bug $t_bug_data = new BugData; $t_bug_data->project_id = $t_project_id; $t_bug_data->reporter_id = $t_reporter_id; $t_bug_data->handler_id = $t_handler_id; $t_bug_data->duplicate_id = $t_duplicate_id; $t_bug_data->priority = $t_priority; $t_bug_data->severity = $t_severity; $t_bug_data->reproducibility = $t_reproducibility; $t_bug_data->status = $t_status; $t_bug_data->resolution = $t_resolution; $t_bug_data->projection = $t_projection; $t_bug_data->category = $t_category; $t_bug_data->date_submitted = $t_date_submitted; $t_bug_data->last_updated = $t_last_updated; $t_bug_data->eta = $t_eta; $t_bug_data->os = $t_os; $t_bug_data->os_build = $t_os_build; $t_bug_data->platform = $t_platform; $t_bug_data->version = $t_version; $t_bug_data->fixed_in_version = $t_fixed_in_version; $t_bug_data->build = $t_build; $t_bug_data->view_state = $t_view_state; $t_bug_data->summary = $t_summary; $t_bug_data->description = $t_description; $t_bug_data->steps_to_reproduce = $t_steps_to_reproduce; $t_bug_data->additional_information = $t_additional_information; $t_bug_data->profile_id = $t_profile_id; $t_bug_data->sponsorship_total = $t_sponsorship_total; $t_bug_id = bug_create($t_bug_data); if ( $t_bug_id ) { $t_error = false; # Setting status if ( $t_bug_data->status != config_get( 'bug_submit_status' ) ) { bug_set_field( $t_bug_id, 'status', $t_bug_data->status ); } # Setting resolution if ( $t_bug_data->resolution != OPEN ) { bug_set_field( $t_bug_id, 'resolution', $t_bug_data->resolution ); } # Setting fixed_in_version if ( $t_bug_data->fixed_in_version != '' ) { bug_set_field( $t_bug_id, 'fixed_in_version', $t_bug_data->fixed_in_version ); } # Setting date fields if ( $t_bug_data->date_submitted != '' ) { bug_set_field( $t_bug_id, 'date_submitted', $t_bug_data->date_submitted ); } # Adding custom fields $t_custom_field_count = 0; foreach( $t_related_custom_field_ids as $t_id ) { $t_custom_field_count++; $t_def = custom_field_get_definition( $t_id ); if ( gpc_get_int( "choice_custom_field_$t_id" ) == IMPORT_FROM_FILE ) { # $t_custom_field_value = $t_row[ $t_num_of_columns - 1 + $t_custom_field_count ]; # @@@ mgf: commented out $t_custom_field_value = $t_row[ "custom_field_$t_id" ]; # @@@ mgf: inserted } else if ( gpc_get_int( "choice_custom_field_$t_id" ) == IMPORT_USE_CONST_VALUE ) { $t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], $t_def['default_value'] ); } else { continue; } # August 2006 - mBernigaud : don't set empty date --> if ( $t_custom_field_value != '') { # August 2006 - mBernigaud : Convert string date to its internal value if ( $t_def['type'] == CUSTOM_FIELD_TYPE_DATE ) { $t_custom_field_value = strtotime( $t_custom_field_value ) ; } if( !custom_field_set_value( $t_id, $t_bug_id, $t_custom_field_value ) ) { echo '' . lang_get( 'import_custom_field_failure' ) . $t_def['name'] . ' : ' . $t_summary . '
'; $t_error_count++; $t_error = true; } } } if ( !$t_error ) { echo '' . lang_get( 'import_success' ) . $t_bug_id . ": " . $t_summary . '
'; $t_success_count++; } } else { echo '' . lang_get( 'import_failure' ) . $t_summary . '
'; $t_error_count++; } } #echo '' . lang_get( 'import_completed' ) . $t_error_count . '
'; echo '' . lang_get( 'import_completed_1' ) . $t_success_count . lang_get( 'import_completed_2' ) . $t_error_count . '
'; # remove temporary import table $query = 'DROP TABLE IF EXISTS ' . $t_mantis_import_issues_table; db_query( $query ); html_page_bottom1( __FILE__ ); #----------------------- # get_string_to_enum: # arg: enum name, string value # return: enum value #----------------------- function get_string_to_enum( $p_enum_name, $p_value ) { $t_config_var_name = $p_enum_name.'_enum_string'; #$t_config_var_value = config_get( $t_config_var_name ); $t_config_var_value = lang_get( $t_config_var_name ); $t_arr = explode_enum_string( $t_config_var_value ); $t_enum_count = count( $t_arr ); for ( $i = 0; $i < $t_enum_count; $i++ ) { $t_elem = explode_enum_arr( $t_arr[$i] ); if ( $t_elem[1] == $p_value ) { return $t_elem[0]; } } # end for return 0; } ?>