From: <jfi...@us...> - 2002-12-30 10:46:28
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1:/tmp/cvs-serv30797/core Modified Files: bug_api.php bugnote_api.php Log Message: cleanup all the bugnote pages (except bugnote_inc.php) and the bugnote_api Index: bug_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/bug_api.php,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- bug_api.php 23 Dec 2002 02:12:39 -0000 1.26 +++ bug_api.php 30 Dec 2002 10:46:25 -0000 1.27 @@ -1,7 +1,7 @@ <?php # Mantis - a php based bugtracking system # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... - # Copyright (C) 2002 Mantis Team - man...@li... + # Copyright (C) 2002 - 2003 Mantis Team - man...@li... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details Index: bugnote_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/bugnote_api.php,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- bugnote_api.php 30 Dec 2002 08:09:24 -0000 1.10 +++ bugnote_api.php 30 Dec 2002 10:46:25 -0000 1.11 @@ -1,7 +1,7 @@ <?php # Mantis - a php based bugtracking system # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... - # Copyright (C) 2002 Mantis Team - man...@li... + # Copyright (C) 2002 - 2003 Mantis Team - man...@li... # This program is distributed under the terms and conditions of the GPL # See the files README and LICENSE for details @@ -13,35 +13,21 @@ # Bugnote API ########################################################################### - # -------------------- - # updates the last_modified field - function bugnote_date_update( $p_bugnote_id ) { - global $g_mantis_bugnote_table; - - $c_bugnote_id = db_prepare_int( $p_bugnote_id ); - - $query = "UPDATE $g_mantis_bugnote_table - SET last_modified=NOW() - WHERE id='$c_bugnote_id'"; - db_query( $query ); + #=================================== + # Boolean queries and ensures + #=================================== - # db_query() errors if there was a problem so: - return true; - } - # -------------------- - # Pads the bugnote id with the appropriate number of zeros. - function bugnote_format_id( $p_bug_id ) { - return( str_pad( $p_bug_id, 7, '0', STR_PAD_LEFT ) ); - } # -------------------- - # returns true if the bugnote exists, false otherwise + # Check if a bugnote with the given ID exists + # + # return true if the bugnote exists, false otherwise function bugnote_exists( $p_bugnote_id ) { - global $g_mantis_bugnote_table; - $c_bugnote_id = db_prepare_int( $p_bugnote_id ); + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + $query ="SELECT COUNT(*) ". - "FROM $g_mantis_bugnote_table ". + "FROM $t_bugnote_table ". "WHERE id='$c_bugnote_id'"; $result = db_query( $query ); @@ -51,228 +37,260 @@ return true; } } + # -------------------- - # check to see if bugnote exists - # if it doesn't exist then redirect to the main page - # otherwise let execution continue undisturbed + # Check if a bugnote with the given ID exists + # + # return true if the bugnote exists, raise an error if not function bugnote_ensure_exists( $p_bugnote_id ) { if ( ! bugnote_exists( $p_bugnote_id ) ) { trigger_error( ERROR_BUGNOTE_NOT_FOUND, ERROR ); } } + + #=================================== + # Creation / Deletion / Updating + #=================================== + # -------------------- - # add a bugnote to a bug + # Add a bugnote to a bug + # + # return the ID of the new bugnote function bugnote_add ( $p_bug_id, $p_bugnote_text, $p_private=false ) { - global $g_mantis_bugnote_text_table, $g_mantis_bugnote_table; + $c_bug_id = db_prepare_int( $p_bug_id ); + $c_bugnote_text = db_prepare_string( $p_bugnote_text ); + $c_private = db_prepare_bool( $p_private ); - $c_bug_id = db_prepare_int( $p_bug_id ); - $c_bugnote_text = db_prepare_string( $p_bugnote_text ); - $c_private = db_prepare_bool( $p_private ); + $t_bugnote_text_table = config_get( 'mantis_bugnote_text_table' ); + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); # insert bugnote text $query = "INSERT - INTO $g_mantis_bugnote_text_table + INTO $t_bugnote_text_table ( id, note ) VALUES ( null, '$c_bugnote_text' )"; - $result = db_query( $query ); + db_query( $query ); - if ( $result ) { - # retrieve bugnote text id number - $t_bugnote_text_id = db_insert_id(); + # retrieve bugnote text id number + $t_bugnote_text_id = db_insert_id(); - # Check for private bugnotes. - if ( $c_private && access_level_check_greater_or_equal( config_get( 'private_bugnote_threshold' ) ) ) { - $t_view_state = PRIVATE; - } else { - $t_view_state = PUBLIC; - } + # Check for private bugnotes. + if ( $p_private && access_level_check_greater_or_equal( config_get( 'private_bugnote_threshold' ) ) ) { + $t_view_state = PRIVATE; + } else { + $t_view_state = PUBLIC; + } - # get user information - $u_id = current_user_get_field( 'id' ); + # get user information + $t_user_id = current_user_get_field( 'id' ); - # insert bugnote info - $query = "INSERT - INTO $g_mantis_bugnote_table - ( id, bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified ) - VALUES - ( null, '$c_bug_id', '$u_id','$t_bugnote_text_id', '$t_view_state', NOW(), NOW() )"; - $result = db_query( $query ); + # insert bugnote info + $query = "INSERT + INTO $t_bugnote_table + ( id, bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified ) + VALUES + ( null, '$c_bug_id', '$t_user_id','$t_bugnote_text_id', '$t_view_state', NOW(), NOW() )"; + db_query( $query ); - if ( $result ) { - # update bug last updated - $result = bug_update_date( $p_bug_id ); + # get bugnote id + $t_bugnote_id = db_insert_id(); - if ( $result ) { - # get bugnote id - $t_bugnote_id = bugnote_format_id( db_insert_id() ); + # update bug last updated + bug_update_date( $p_bug_id ); - # log new bug - history_log_event_special( $p_bug_id, BUGNOTE_ADDED , $t_bugnote_id ); + # log new bug + history_log_event_special( $p_bug_id, BUGNOTE_ADDED, bugnote_format_id( $t_bugnote_id ) ); - return true; - } - } - } + email_bugnote_add( $p_bug_id ); - return false; + return $t_bugnote_id; } + # -------------------- # Delete a bugnote function bugnote_delete( $p_bugnote_id ) { - global $g_mantis_bugnote_table, $g_mantis_bugnote_text_table; - - $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); - $c_bugnote_id = db_prepare_int( $p_bugnote_id ); + $c_bugnote_id = db_prepare_int( $p_bugnote_id ); - # grab the bugnote text id + $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); $t_bugnote_text_id = bugnote_get_field( $p_bugnote_id, 'bugnote_text_id' ); + $t_bugnote_text_table = config_get( 'mantis_bugnote_text_table' ); + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + # Remove the bugnote $query = "DELETE - FROM $g_mantis_bugnote_table + FROM $t_bugnote_table WHERE id='$c_bugnote_id'"; - $result = db_query( $query ); + db_query( $query ); - if ( $result ) { - # Remove the bugnote text - $query = "DELETE - FROM $g_mantis_bugnote_text_table - WHERE id='$t_bugnote_text_id'"; - $result = db_query( $query ); + # Remove the bugnote text + $query = "DELETE + FROM $t_bugnote_text_table + WHERE id='$t_bugnote_text_id'"; + db_query( $query ); - if ( $result ) { - # log deletion of bug - $t_bugnote_id = bugnote_format_id( $c_bugnote_id ); - history_log_event_special( $t_bug_id, BUGNOTE_DELETED, $t_bugnote_id ); - return true; - } - } + # log deletion of bug + history_log_event_special( $t_bug_id, BUGNOTE_DELETED, bugnote_format_id( $p_bugnote_id ) ); - return false; + return true; } - # -------------------- - # Update a bugnote text - function bugnote_update_text( $p_bugnote_id, $p_bugnote_text ) { - global $g_mantis_bugnote_text_table; - $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); - $t_bugnote_text_id = bugnote_get_field( $p_bugnote_id, 'bugnote_text_id' ); + # -------------------- + # delete all bugnotes associated with the given bug + function bugnote_delete_all( $p_bug_id ) { + $c_bug_id = db_prepare_int( $p_bug_id ); - $c_bugnote_text = db_prepare_string( $p_bugnote_text ); + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + $t_bugnote_text_table = config_get( 'mantis_bugnote_text_table' ); - $query = "UPDATE $g_mantis_bugnote_text_table - SET note='$c_bugnote_text' - WHERE id='$t_bugnote_text_id'"; - $result = db_query( $query ); + # Delete the bugnote text items + $query = "SELECT bugnote_text_id + FROM $t_bugnote_table + WHERE bug_id='$c_bug_id'"; + $result = db_query($query); - if ( $result ) { - # updated the last_updated date - $result = bugnote_date_update( $p_bugnote_id ); + $bugnote_count = db_num_rows( $result ); - if ( $result ) { - # log new bugnote - history_log_event_special( $t_bug_id, BUGNOTE_UPDATED, $p_bugnote_id ); + for ( $i = 0 ; $i < $bugnote_count ; $i++ ) { + $row = db_fetch_array( $result ); + $t_bugnote_text_id = $row['bugnote_text_id']; - return true; - } + # Delete the corresponding bugnote texts + $query = "DELETE + FROM $t_bugnote_text_table + WHERE id='$t_bugnote_text_id'"; + $result = db_query( $query ); } - return false; - } - # -------------------- - # Updated the view state of a bugnote - function bugnote_update_view_state( $p_bugnote_id, $p_private ) { - global $g_mantis_bugnote_table; - - $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); + # Delete the corresponding bugnotes + $query = "DELETE + FROM $t_bugnote_table + WHERE bug_id='$c_bug_id'"; + $result = db_query($query); - $c_bugnote_id = db_prepare_int( $p_bugnote_id ); + # db_query() errors on failure so: + return true; + } - if ( $p_private ) { - $t_view_state = PRIVATE; - } else { - $t_view_state = PUBLIC; - } - # update view_state - $query = "UPDATE $g_mantis_bugnote_table - SET view_state='$t_view_state' - WHERE id='$c_bugnote_id'"; - $result = db_query( $query ); + #=================================== + # Data Access + #=================================== - if ( $result ) { - history_log_event_special( $t_bug_id, BUGNOTE_STATE_CHANGED, $t_view_state, $c_bugnote_id ); - return true; - } else { - return false; - } - } # -------------------- - # Returns the text associated with the bugnote + # Get the text associated with the bugnote function bugnote_get_text( $p_bugnote_id ) { - global $g_mantis_bugnote_text_table; + $t_bugnote_text_id = bugnote_get_field( $p_bugnote_id, 'bugnote_text_id' ); - $c_bugnote_text_id = bugnote_get_field( $p_bugnote_id, 'bugnote_text_id' ); + $t_bugnote_text_table = config_get( 'mantis_bugnote_text_table' ); # grab the bugnote text $query = "SELECT note - FROM $g_mantis_bugnote_text_table - WHERE id='$c_bugnote_text_id'"; + FROM $t_bugnote_text_table + WHERE id='$t_bugnote_text_id'"; $result = db_query( $query ); return db_result( $result ); } + # -------------------- - # Returns a field for the given bugnote + # Get a field for the given bugnote function bugnote_get_field( $p_bugnote_id, $p_field_name ) { - global $g_mantis_bugnote_table; - $c_bugnote_id = db_prepare_int( $p_bugnote_id ); + $c_field_name = db_prepare_string( $p_field_name ); - $query ="SELECT $p_field_name ". - "FROM $g_mantis_bugnote_table ". - "WHERE id ='$c_bugnote_id' ". + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + + $query ="SELECT $c_field_name ". + "FROM $t_bugnote_table ". + "WHERE id='$c_bugnote_id' ". "LIMIT 1"; $result = db_query( $query ); return db_result( $result ); } + + + #=================================== + # Data Modification + #=================================== + # -------------------- - # delete all bugnotes associated with the given bug - function bugnote_delete_all( $p_bug_id ) { - $c_bug_id = db_prepare_int( $p_bug_id ); + # Update the last_modified field of the bugnote + function bugnote_date_update( $p_bugnote_id ) { + $c_bugnote_id = db_prepare_int( $p_bugnote_id ); $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + + $query = "UPDATE $t_bugnote_table + SET last_modified=NOW() + WHERE id='$c_bugnote_id'"; + db_query( $query ); + + # db_query() errors if there was a problem so: + return true; + } + + # -------------------- + # Set the bugnote text + function bugnote_set_text( $p_bugnote_id, $p_bugnote_text ) { + $c_bugnote_text = db_prepare_string( $p_bugnote_text ); + + $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); + $t_bugnote_text_id = bugnote_get_field( $p_bugnote_id, 'bugnote_text_id' ); + $t_bugnote_text_table = config_get( 'mantis_bugnote_text_table' ); - # Delete the bugnote text items - $query = "SELECT bugnote_text_id - FROM $t_bugnote_table - WHERE bug_id='$c_bug_id'"; - $result = db_query($query); + $query = "UPDATE $t_bugnote_text_table + SET note='$c_bugnote_text' + WHERE id='$t_bugnote_text_id'"; + db_query( $query ); - $bugnote_count = db_num_rows( $result ); + # updated the last_updated date + bugnote_date_update( $p_bugnote_id ); - for ( $i = 0 ; $i < $bugnote_count ; $i++ ) { - $row = db_fetch_array( $result ); - $t_bugnote_text_id = $row['bugnote_text_id']; + # log new bugnote + history_log_event_special( $t_bug_id, BUGNOTE_UPDATED, bugnote_format_id( $p_bugnote_id ) ); - # Delete the corresponding bugnote texts - $query = "DELETE - FROM $t_bugnote_text_table - WHERE id='$t_bugnote_text_id'"; - $result = db_query( $query ); + return true; + } + + # -------------------- + # Set the view state of the bugnote + function bugnote_set_view_state( $p_bugnote_id, $p_private ) { + $c_bugnote_id = db_prepare_int( $p_bugnote_id ); + + $t_bug_id = bugnote_get_field( $p_bugnote_id, 'bug_id' ); + + if ( $p_private ) { + $t_view_state = PRIVATE; + } else { + $t_view_state = PUBLIC; } - # Delete the corresponding bugnotes - $query = "DELETE - FROM $t_bugnote_table - WHERE bug_id='$c_bug_id'"; - $result = db_query($query); + $t_bugnote_table = config_get( 'mantis_bugnote_table' ); + + # update view_state + $query = "UPDATE $t_bugnote_table + SET view_state='$t_view_state' + WHERE id='$c_bugnote_id'"; + db_query( $query ); + + history_log_event_special( $t_bug_id, BUGNOTE_STATE_CHANGED, bugnote_format_id( $t_view_state ), $p_bugnote_id ); - # db_query() errors on failure so: return true; } -?> + + + #=================================== + # Other + #=================================== + + # -------------------- + # Pad the bugnote id with the appropriate number of zeros for printing + function bugnote_format_id( $p_bug_id ) { + return( str_pad( $p_bug_id, 7, '0', STR_PAD_LEFT ) ); + } +?> \ No newline at end of file |