From: <vb...@us...> - 2002-08-29 14:26:48
|
Update of /cvsroot/mantisbt/mantisbt/core In directory usw-pr-cvs1:/tmp/cvs-serv28212/core Modified Files: email_api.php history_api.php Log Message: - Implemented 0002419: Include Bug History in emails - Moved the bug history retrieval code to history_api.php - Re-used the new api from history_api.php to implement bug history viewing and e-mailing. Index: email_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/email_api.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- email_api.php 29 Aug 2002 02:56:23 -0000 1.7 +++ email_api.php 29 Aug 2002 14:26:45 -0000 1.8 @@ -351,7 +351,6 @@ email_bug_info( $p_bug_id, $s_email_bug_deleted_msg, $t_bcc ); } # -------------------- - # messages are in two parts, the bug info and the bugnotes # Build the bug info part of the message function email_build_bug_message( $p_bug_id, $p_message ) { global $g_mantis_bug_table, $g_mantis_bug_text_table, @@ -444,7 +443,6 @@ return $t_message; } # -------------------- - # messages are in two parts, the bug info and the bugnotes # Build the bugnotes part of the message function email_build_bugnote_message( $p_bug_id ) { global $g_mantis_bugnote_table, $g_mantis_bugnote_text_table, @@ -488,6 +486,26 @@ return $t_message; } # -------------------- + # Builds the bug history portion of the bug e-mail + function email_build_history_message( $p_bug_id ) { + $history = history_get_events_array( $p_bug_id ); + $t_message = lang_get( 'bug_history' ) . "\n"; + $t_message .= str_pad( lang_get( 'date_modified' ), 20 ) . + str_pad( lang_get( 'username' ), 20 ) . + str_pad( lang_get( 'field' ), 20 ) . + str_pad( lang_get( 'change' ), 20 ). "\n"; + $t_message .= config_get( 'email_separator1' ) . "\n"; + for ( $i = 0; $i < count($history); $i++ ) { + $t_message .= str_pad( $history[$i]['date'], 20 ) . + str_pad( $history[$i]['username'], 20 ) . + str_pad( $history[$i]['note'], 20 ) . + str_pad( $history[$i]['change'], 20 ). "\n"; + } + + $t_message .= config_get( 'email_separator1' ) . "\n\n"; + return ( $t_message ); + } + # -------------------- # Send bug info to reporter and handler function email_bug_info( $p_bug_id, $p_message, $p_headers='' ) { global $g_to_email, $g_use_bcc; @@ -499,6 +517,7 @@ $t_message = $p_message."\n"; $t_message .= email_build_bug_message( $p_bug_id, $p_message ); $t_message .= email_build_bugnote_message( $p_bug_id ); + $t_message .= email_build_history_message( $p_bug_id ); # send mail Index: history_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/history_api.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- history_api.php 29 Aug 2002 13:00:50 -0000 1.4 +++ history_api.php 29 Aug 2002 14:26:45 -0000 1.5 @@ -75,4 +75,116 @@ $result = db_query( $query ); } # -------------------- + # Retrieves the history events for the specified bug id and returns it in an array + # The array is indexed from 0 to N-1. The second dimension is: 'date', 'username', + # 'note', 'change'. + function history_get_events_array( $p_bug_id ) { + $t_mantis_bug_history_table = config_get( 'mantis_bug_history_table' ); + $t_mantis_user_table = config_get( 'mantis_user_table' ); + $t_history_order = config_get( 'history_order' ); + $c_bug_id = db_prepare_int( $p_bug_id ); + + # grab history and display by date_modified then field_name + $query = "SELECT b.*, UNIX_TIMESTAMP(b.date_modified) as date_modified, u.username + FROM $t_mantis_bug_history_table b + LEFT JOIN $t_mantis_user_table u + ON b.user_id=u.id + WHERE bug_id='$c_bug_id' + ORDER BY date_modified $t_history_order, field_name ASC"; + $result = db_query( $query ); + $history_count = db_num_rows( $result ); + $history = array(); + + for ( $i=0; $i < $history_count; $i++ ) { + $row = db_fetch_array( $result ); + extract( $row, EXTR_PREFIX_ALL, 'v' ); + + $status_color = alternate_colors( $i+1, config_get( 'background_color' ) ); + + $v_date_modified = date( config_get( 'complete_date_format' ), $v_date_modified ); + + switch ( $v_field_name ) { + case 'status': $v_old_value = get_enum_element( 'status', $v_old_value ); + $v_new_value = get_enum_element( 'status', $v_new_value ); + break; + case 'severity': $v_old_value = get_enum_element( 'severity', $v_old_value ); + $v_new_value = get_enum_element( 'severity', $v_new_value ); + break; + case 'reproducibility': $v_old_value = get_enum_element( 'reproducibility', $v_old_value ); + $v_new_value = get_enum_element( 'reproducibility', $v_new_value ); + break; + case 'resolution': $v_old_value = get_enum_element( 'resolution', $v_old_value ); + $v_new_value = get_enum_element( 'resolution', $v_new_value ); + break; + case 'priority': $v_old_value = get_enum_element( 'priority', $v_old_value ); + $v_new_value = get_enum_element( 'priority', $v_new_value ); + break; + case 'eta': $v_old_value = get_enum_element( 'eta', $v_old_value ); + $v_new_value = get_enum_element( 'eta', $v_new_value ); + break; + case 'view_state': $v_old_value = get_enum_element( 'view_state', $v_old_value ); + $v_new_value = get_enum_element( 'view_state', $v_new_value ); + break; + case 'projection': $v_old_value = get_enum_element( 'projection', $v_old_value ); + $v_new_value = get_enum_element( 'projection', $v_new_value ); + break; + case 'project_id': $v_old_value = project_get_field( $v_old_value, 'name' ); + $v_new_value = project_get_field( $v_new_value, 'name' ); + break; + case 'handler_id': + case 'reporter_id': $v_old_value = user_get_field( $v_old_value, 'username' ); + $v_new_value = user_get_field( $v_new_value, 'username' ); + break; + } + + if ( NORMAL_TYPE != $v_type ) { + switch ( $v_type ) { + case NEW_BUG: $t_note = lang_get( 'new_bug' ); + break; + case BUGNOTE_ADDED: $t_note = lang_get( 'bugnote_added' ) . ": " . $v_old_value; + break; + case BUGNOTE_UPDATED: $t_note = lang_get( 'bugnote_edited' ) . ": " . $v_old_value; + break; + case BUGNOTE_DELETED: $t_note = lang_get( 'bugnote_deleted' ) . ": " . $v_old_value; + break; + case SUMMARY_UPDATED: $t_note = lang_get( 'summary_updated' ); + break; + case DESCRIPTION_UPDATED: $t_note = lang_get( 'description_updated' ); + break; + case ADDITIONAL_INFO_UPDATED: $t_note = lang_get( 'additional_information_updated' ); + break; + case STEP_TO_REPRODUCE_UPDATED: $t_note = lang_get( 'steps_to_reproduce_updated' ); + break; + case FILE_ADDED: $t_note = lang_get( 'file_added' ) . ": " . $v_old_value; + break; + case FILE_DELETED: $t_note = lang_get( 'file_deleted' ) . ": " . $v_old_value; + break; + case BUGNOTE_STATE_CHANGED: $v_old_value = get_enum_element( 'view_state', $v_old_value ); + $t_note = lang_get( 'bugnote_view_state' ) . ": " . $v_old_value . ": " . $v_new_value; + break; + case BUG_MONITOR: $v_old_value = user_get_field( $v_old_value, 'username' ); + $t_note = lang_get( 'bug_monitor' ) . ": " . $v_old_value; + break; + case BUG_UNMONITOR: $v_old_value = user_get_field( $v_old_value, 'username' ); + $t_note = lang_get( 'bug_end_monitor' ) . ": " . $v_old_value; + break; + } + } + + # output special cases + if ( NORMAL_TYPE != $v_type ) { + $history[$i]['date'] = $v_date_modified; + $history[$i]['username'] = $v_username; + $history[$i]['note'] = $t_note; + $history[$i]['change'] = ''; + } else { # output normal changes + $history[$i]['date'] = $v_date_modified; + $history[$i]['username'] = $v_username; + $history[$i]['note'] = $v_field_name; + $history[$i]['change'] = $v_old_value . ' => ' . $v_new_value; + } # end if DEFAULT + } # end for loop + + return ( $history ); + } ?> |