Skip to content

Commit

Permalink
* core/bug_api.php
Browse files Browse the repository at this point in the history
  (bug_set_field): new function
  (bug_assign): take a bugnote string as parameter and fix incorrect
   variable name ($t_handler_id)
  (bug_close): use bug_set_field()
  (bug_resolve): new function
* bug_actiongroup.php: cleanup to use new api functions


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1489 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Sep 16, 2002
1 parent 760c849 commit 75a5e0c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 149 deletions.
136 changes: 20 additions & 116 deletions bug_actiongroup.php
Expand Up @@ -11,152 +11,56 @@
<?php require_once( 'core.php' ) ?>
<?php login_cookie_check() ?>
<?php

$f_action = gpc_get_string( 'f_action' );
$f_bug_arr = gpc_get_string_array( 'f_bug_arr', array() );
$f_action = gpc_get_string( 'f_action' );
$f_bug_arr = gpc_get_int_array( 'f_bug_arr', array() );

# the queries
function updateBugLite($p_id, $p_status, $p_request) {
$t_handler_id = auth_get_current_user_id();
$t_query='';
$result = 1;

bug_ensure_exists( $p_id );

# history treatment
# extract current extended information into history variables
$row = bug_get_extended_row( $p_id );
extract( $row, EXTR_PREFIX_ALL, 'h' );

switch ($p_status) {

case 'MOVED' :
check_access( config_get( 'bug_move_access_level' ) );
$t_query = "project_id='$p_request'";
break;

case CLOSED :
check_access( config_get( 'close_bug_threshold' ) );
$t_query="status='$p_status'";
break ;

case ASSIGNED :
check_access( config_get( 'update_bug_threshold' ) );
// @@@ Check that $p_request has access to handle a bug.
$t_handler_id = $p_request ;
$t_query="handler_id='$t_handler_id', status='$p_status'";
break ;

case RESOLVED :
check_access( config_get( 'handle_bug_threshold' ) );
$t_query=" status='$p_status', resolution='$p_request'";
break ;

case 'UP_PRIOR' :
check_access( config_get( 'update_bug_threshold' ) );
$t_query="priority='$p_request'";
break ;

case 'UP_STATUS' :
check_access( config_get( 'update_bug_threshold' ) );
$t_query="handler_id='$t_handler_id', status='$p_request'";
break ;
}
# Update fields
$query = "UPDATE ".config_get( 'mantis_bug_table' )."
SET $t_query
WHERE id='$p_id'";

$result = db_query($query);

if ( !$result ) {
print_mantis_error( ERROR_GENERIC );
}

# history logging should be done after the field updates
switch ($p_status) {

case 'MOVED' :
history_log_event_direct( $p_id, 'project_id', $h_project_id, $p_request, $t_handler_id );
break;

case CLOSED :
history_log_event_direct( $p_id, 'status', $h_status, $p_status, $t_handler_id );
break ;

case ASSIGNED :
history_log_event_direct( $p_id, 'handler_id', $h_handler_id, $p_request, $t_handler_id );
history_log_event_direct( $p_id, 'status', $h_status, $p_status, $t_handler_id );
break ;

case RESOLVED :
history_log_event_direct( $p_id, 'resolution', $h_resolution, $p_request, $t_handler_id );
history_log_event_direct( $p_id, 'status', $h_status, $p_status, $t_handler_id );
break ;

case 'UP_PRIOR' :
history_log_event_direct( $p_id, 'priority', $h_priority, $p_request, $t_handler_id );
break ;

case 'UP_STATUS' :
history_log_event_direct( $p_id, 'status', $h_status, $p_request, $t_handler_id );
break ;
}

# update bug last updated
bug_update_date($p_id);

# notify reporter and handler
switch ( $p_status ) {

case ASSIGNED: email_assign( $p_id );
break;
case RESOLVED: email_resolved( $p_id );
break;
case CLOSED: email_close( $p_id );
break;
}

}//updateBug

foreach($f_bug_arr as $value) {
foreach( $f_bug_arr as $t_bug_id ) {
bug_ensure_exists( $t_bug_id );

switch ( $f_action ) {

case 'CLOSE':
updateBugLite( $value, CLOSED, '' );
check_access( config_get( 'close_bug_threshold' ) );
bug_close( $t_bug_id );
break;

case 'DELETE':
bug_delete( $value );
check_access( config_get( 'allow_bug_delete_access_level' ) );
bug_delete( $t_bug_id );
break;

case 'MOVE':
check_access( config_get( 'bug_move_access_level' ) );
$f_project_id = gpc_get_int( 'f_project_id' );
updateBugLite( $value, 'MOVED', $f_project_id );
bug_set_field( $t_bug_id, 'project_id', $f_project_id );
break;

case 'ASSIGN':
check_access( config_get( 'update_bug_threshold' ) );
// @@@ Check that $f_assign has access to handle a bug.
$f_assign = gpc_get_int( 'f_assign' );
updateBugLite( $value, ASSIGNED, $f_assign );
bug_assign( $t_bug_id, $f_assign );
break;

case 'RESOLVE':
check_access( config_get( 'handle_bug_threshold' ) );
$f_resolution = gpc_get_int( 'f_resolution' );
updateBugLite( $value, RESOLVED, $f_resolution );
bug_resolve( $t_bug_id, $f_resolution );
break;

case 'UP_PRIOR':
check_access( config_get( 'update_bug_threshold' ) );
$f_priority = gpc_get_int( 'f_priority' );
updateBugLite( $value, 'UP_PRIOR', $f_priority );
bug_set_field( $t_bug_id, 'priority', $f_priority );
break;

case 'UP_STATUS':
check_access( config_get( 'update_bug_threshold' ) );
$f_status = gpc_get_int( 'f_status' );
updateBugLite( $value, 'UP_STATUS', $f_status );
bug_set_field( $t_bug_id, 'status', $f_status );
break;
}
}

print_meta_redirect( 'view_all_bug_page.php',0);
print_meta_redirect( 'view_all_bug_page.php',0 );
?>
96 changes: 63 additions & 33 deletions core/bug_api.php
Expand Up @@ -6,7 +6,7 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Id: bug_api.php,v 1.10 2002-09-16 04:16:59 jfitzell Exp $
# $Id: bug_api.php,v 1.11 2002-09-16 06:10:25 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -325,9 +325,41 @@ function bug_get_newest_bugnote_timestamp( $p_bug_id ) {
# Data Modification
#===================================

# --------------------
# set the value of a bug field
function bug_set_field( $p_bug_id, $p_field_name, $p_status ) {
$c_bug_id = db_prepare_int( $p_bug_id );
$c_field_name = db_prepare_string( $p_field_name );
$c_status = db_prepare_string( $p_status ); #generic, unknown type

$h_status = bug_get_field( $p_bug_id, $p_field_name );

# return if status is already set
if ( $c_status == $h_status ) {
return true;
}

$t_bug_table = config_get ( 'mantis_bug_table' );

# Update fields
$query = "UPDATE $t_bug_table
SET $c_field_name='$c_status'
WHERE id='$c_bug_id'";
db_query( $query );

# updated the last_updated date
bug_update_date( $p_bug_id );

# log changes
history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );

bug_clear_cache( $p_bug_id );

return true;
}
# --------------------
# assign the bug to the given user
function bug_assign( $p_bug_id, $p_user_id ) {
function bug_assign( $p_bug_id, $p_user_id, $p_bugnote_text='' ) {
$c_bug_id = db_prepare_int( $p_bug_id );
$c_user_id = db_prepare_int( $p_user_id );

Expand All @@ -343,68 +375,67 @@ function bug_assign( $p_bug_id, $p_user_id ) {

$t_bug_table = config_get( 'mantis_bug_table' );

if ( ( $t_ass_val != $h_status ) || ( $t_handler_id != $h_handler_id ) ) {
if ( ( $t_ass_val != $h_status ) || ( $p_user_id != $h_handler_id ) ) {

# get user id
$query = "UPDATE $t_bug_table
SET handler_id='$c_user_id', status='$t_ass_val'
WHERE id='$c_bug_id'";
db_query( $query );

# updated the last_updated date
bug_update_date( $p_bug_id );

# log changes
history_log_event_direct( $c_bug_id, 'status', $h_status, $t_ass_val );
history_log_event_direct( $c_bug_id, 'handler_id', $h_handler_id, $t_handler_id );
history_log_event_direct( $c_bug_id, 'handler_id', $h_handler_id, $p_user_id );

# Add bugnote if supplied
if ( $p_bugnote_text != '' ) {
bugnote_add( $p_bug_id, $p_bugnote_text );
}

# updated the last_updated date
bug_update_date( $p_bug_id );

# send assigned to email
email_assign( $p_bug_id );

bug_clear_cache( $p_bug_id );
}

return true;
}
# --------------------
# close the given bug
function bug_close( $p_bug_id, $p_bugnote_text ) {
function bug_close( $p_bug_id, $p_bugnote_text='' ) {
$p_bugnote_text = trim( $p_bugnote_text );

$c_bug_id = db_prepare_int( $p_bug_id );
$c_bugnote_text = db_prepare_string( $p_bugnote_text );

$h_status = bug_get_field( $p_bug_id, 'status' );

# bug is already closed, return error
if ( CLOSED == $h_status ) {
return false;
}
bug_set_field( $p_bug_id, 'status', CLOSED );

# Add bugnote if supplied
if ( $p_bugnote_text != '' ) {
bugnote_add( $p_bug_id, $p_bugnote_text );
}

# Clean variables
$t_bug_table = config_get ( 'mantis_bug_table' );

$t_status_val = CLOSED;
email_close( $p_bug_id );

# Update fields
$query = "UPDATE $t_bug_table
SET status='$t_status_val'
WHERE id='$c_bug_id'";
db_query( $query );
return true;
}
# --------------------
# resolve the given bug
function bug_resolve( $p_bug_id, $p_resolution, $p_bugnote_text='' ) {
$p_bugnote_text = trim( $p_bugnote_text );

# updated the last_updated date
bug_update_date( $p_bug_id );
bug_set_field( $p_bug_id, 'status', RESOLVED );
bug_set_field( $p_bug_id, 'resolution', (int)$p_resolution );

# log changes
history_log_event_direct( $p_bug_id, 'status', $h_status, CLOSED );
# Add bugnote if supplied
if ( $p_bugnote_text != '' ) {
bugnote_add( $p_bug_id, $p_bugnote_text );
}

email_close( $p_bug_id );
email_resolved( $p_bug_id );

return true;
}

# --------------------
# updates the last_updated field
function bug_update_date( $p_bug_id ) {
Expand All @@ -419,5 +450,4 @@ function bug_update_date( $p_bug_id ) {

return true;
}

?>

0 comments on commit 75a5e0c

Please sign in to comment.