Navigation Menu

Skip to content

Commit

Permalink
Fixed #9102: webservice api call causes SYSTEM NOTICEs \nAdded unit t…
Browse files Browse the repository at this point in the history
…ests for SOAP API.
  • Loading branch information
vboctor committed Apr 13, 2009
1 parent fb158f7 commit a6773fc
Show file tree
Hide file tree
Showing 7 changed files with 573 additions and 79 deletions.
81 changes: 58 additions & 23 deletions api/soap/mc_api.php
Expand Up @@ -124,35 +124,67 @@ function mci_get_user_lang( $p_user_id ) {
return $t_lang;
}

function mci_get_status_id( $p_status ) {
function mci_get_status_id( &$p_status ) {
if ( !isset( $p_status ) ) {
return (int)config_get( 'bug_submit_status' );
}

return mci_get_enum_id_from_objectref( 'status', $p_status );
}

function mci_get_severity_id( $p_severity ) {
function mci_get_severity_id( &$p_severity ) {
if ( !isset( $p_severity ) ) {
return (int)config_get( 'default_bug_severity' );
}

return mci_get_enum_id_from_objectref( 'severity', $p_severity );
}

function mci_get_priority_id( $p_priority ) {
function mci_get_priority_id( &$p_priority ) {
if ( !isset( $p_priority ) ) {
return (int)config_get( 'default_bug_priority' );
}

return mci_get_enum_id_from_objectref( 'priority', $p_priority );
}

function mci_get_reproducibility_id( $p_reproducibility ) {
function mci_get_reproducibility_id( &$p_reproducibility ) {
if ( !isset( $p_reproducibility ) ) {
return (int)config_get( 'default_bug_reproducibility' );
}

return mci_get_enum_id_from_objectref( 'reproducibility', $p_reproducibility );
}

function mci_get_resolution_id( $p_resolution ) {
function mci_get_resolution_id( &$p_resolution ) {
if ( !isset( $p_resolution ) ) {
return (int)OPEN;
}

return mci_get_enum_id_from_objectref( 'resolution', $p_resolution );
}

function mci_get_projection_id( $p_projection ) {
function mci_get_projection_id( &$p_projection ) {
if ( !isset( $p_projection ) ) {
return (int)10;
}

return mci_get_enum_id_from_objectref( 'projection', $p_projection );
}

function mci_get_eta_id( $p_eta ) {
function mci_get_eta_id( &$p_eta ) {
if ( !isset( $p_eta ) ) {
return (int)10;
}

return mci_get_enum_id_from_objectref( 'eta', $p_eta );
}

function mci_get_view_state_id( $p_view_state ) {
function mci_get_view_state_id( &$p_view_state ) {
if ( !isset( $p_view_state ) ) {
return (int)config_get( 'default_bug_view_status' );
}

return mci_get_enum_id_from_objectref( 'view_state', $p_view_state );
}

Expand Down Expand Up @@ -222,7 +254,11 @@ function mci_user_get_accessible_subprojects( $p_user_id, $p_parent_project_id,
return $t_result;
}

function translate_category_name_to_id( $p_category_name, $p_project_id ) {
function translate_category_name_to_id( &$p_category_name, $p_project_id ) {
if ( !isset( $p_category_name ) ) {
return 0;
}

$t_cat_array = category_get_all_rows( $p_project_id );
foreach( $t_cat_array as $t_category_row ) {
if( $t_category_row['name'] == $p_category_name ) {
Expand Down Expand Up @@ -379,9 +415,9 @@ function mc_error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {

# Get a stack trace if PHP provides the facility or xdebug is present
function error_get_stack_trace() {
$t_stack = '';
$t_trace = '';

if( extension_loaded( 'xdebug' ) ) {
if ( extension_loaded( 'xdebug' ) ) {

#check for xdebug presence
$t_stack = xdebug_get_function_stack();
Expand All @@ -392,23 +428,22 @@ function error_get_stack_trace() {
array_shift( $t_stack );

#remove the call to this function from the stack trace

foreach( $t_stack as $t_frame ) {
$t_stack .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
$t_trace .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );

$t_args = array();
if( isset( $t_frame['params'] ) ) {
$t_stack .= ' Params: ';
if ( isset( $t_frame['params'] ) && ( count( $t_frame['params'] ) > 0 ) ) {
$t_trace .= ' Params: ';
foreach( $t_frame['params'] as $t_value ) {
$t_args[] = error_build_parameter_string( $t_value );
}

$t_stack .= '(' . implode( $t_args, ', ' ) . ')';
$t_trace .= '(' . implode( $t_args, ', ' ) . ')';
} else {
$t_stack .= '()';
$t_trace .= '()';
}

$t_stack .= "\n";
$t_trace .= "\n";
}
} else {
$t_stack = debug_backtrace();
Expand All @@ -417,22 +452,22 @@ function error_get_stack_trace() {
array_shift( $t_stack ); #remove the call to the error handler from the stack trace

foreach( $t_stack as $t_frame ) {
$t_stack .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
$t_trace .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );

$t_args = array();
if( isset( $t_frame['args'] ) ) {
foreach( $t_frame['args'] as $t_value ) {
$t_args[] = error_build_parameter_string( $t_value );
}

$t_stack .= '(' . implode( $t_args, ', ' ) . ')';
$t_trace .= '(' . implode( $t_args, ', ' ) . ')';
} else {
$t_stack .= '()';
$t_trace .= '()';
}

$t_stack .= "\n";
$t_trace .= "\n";
}
}

return $t_stack;
return $t_trace;
}
76 changes: 29 additions & 47 deletions api/soap/mc_issue_api.php
Expand Up @@ -429,11 +429,8 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
$t_eta_id = mci_get_eta_id( $p_issue['eta'] );
$t_view_state_id = mci_get_view_state_id( $p_issue['view_state'] );
$t_reporter_id = mci_get_user_id( $p_issue['reporter'] );
$t_category = $p_issue['category'];
$t_version = $p_issue['version'];
$t_summary = $p_issue['summary'];
$t_description = $p_issue['description'];
$t_custom_fields = $p_issue['custom_fields'];

if( $t_reporter_id == 0 ) {
$t_reporter_id = $t_user_id;
Expand Down Expand Up @@ -469,23 +466,25 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
return new soap_fault( 'Client', '', "User '$t_handler_id' does not exist." );
}

$t_category_id = translate_category_name_to_id( $t_category, $t_project_id );
if( $t_category_id == 0 ) {
if ( is_blank( $t_category ) ) {
return new soap_fault( 'Client', '', "Category cannot be empty." );
$t_category_id = translate_category_name_to_id( $p_issue['category'], $t_project_id );
if ( $t_category_id == 0 && !config_get( 'allow_no_category' ) ) {
if ( !isset( $p_issue['category'] ) || is_blank( $p_issue['category'] ) ) {
return new soap_fault( 'Client', '', "Category field must be supplied." );
} else {
return new soap_fault( 'Client', '', "Category '$t_category' does not exist in project '$t_project_id'." );
return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_id'." );
}
}

if ( isset( $t_version ) && !is_blank( $t_version ) && !version_get_id( $t_version, $t_project_id ) ) {
if ( isset( $p_issue['version'] ) && !is_blank( $p_issue['version'] ) && !version_get_id( $p_issue['version'], $t_project_id ) ) {
$t_version = $p_issue['version'];

$t_error_when_version_not_found = config_get( 'mc_error_when_version_not_found' );
if( $t_error_when_version_not_found == ON ) {
$t_project_name = project_get_name( $t_project_id );
return new soap_fault( 'Client', '', "Version '$v_version' does not exist in project '$t_project_name'." );
return new soap_fault( 'Client', '', "Version '$t_version' does not exist in project '$t_project_name'." );
} else {
$t_version_when_not_found = config_get( 'mc_version_when_not_found' );
$v_version = $t_version_when_not_found;
$t_version = $t_version_when_not_found;
}
}

Expand All @@ -497,22 +496,6 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
return new soap_fault( 'Client', '', "Mandatory field 'description' is missing." );
}

if ( $t_priority_id == 0 ) {
$t_priority_id = config_get( 'default_bug_priority' );
}

if ( $t_severity_id == 0 ) {
$t_severity_id = config_get( 'default_bug_severity' );
}

if ( $t_view_state_id == 0 ) {
$t_view_state_id = config_get( 'default_bug_view_status' );
}

if ( $t_reproducibility_id == 0 ) {
$t_reproducibility_id = 10;
}

$t_bug_data = new BugData;
$t_bug_data->project_id = $t_project_id;
$t_bug_data->reporter_id = $t_reporter_id;
Expand All @@ -524,33 +507,33 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
$t_bug_data->resolution = $t_resolution_id;
$t_bug_data->projection = $t_projection_id;
$t_bug_data->category_id = $t_category_id;
$t_bug_data->date_submitted = isset( $v_date_submitted ) ? $v_date_submitted : '';
$t_bug_data->last_updated = isset( $v_last_updated ) ? $v_last_updated : '';
$t_bug_data->date_submitted = isset( $p_issue['date_submitted'] ) ? $p_issue['date_submitted'] : '';
$t_bug_data->last_updated = isset( $p_issue['last_updated'] ) ? $p_issue['last_updated'] : '';
$t_bug_data->eta = $t_eta_id;
$t_bug_data->os = isset( $v_os ) ? $v_os : '';
$t_bug_data->os_build = isset( $v_os_build ) ? $v_os_build : '';
$t_bug_data->platform = isset( $v_platform ) ? $v_platform : '';
$t_bug_data->version = isset( $v_version ) ? $v_version : '';
$t_bug_data->fixed_in_version = isset( $v_fixed_in_version ) ? $v_fixed_in_version : '';
$t_bug_data->target_version = isset( $v_target_version ) ? $v_target_version : '';
$t_bug_data->build = isset( $v_build ) ? $v_build : '';
$t_bug_data->os = isset( $p_issue['os'] ) ? $p_issue['os'] : '';
$t_bug_data->os_build = isset( $p_issue['os_build'] ) ? $p_issue['os_build'] : '';
$t_bug_data->platform = isset( $p_issue['platform'] ) ? $p_issue['platform'] : '';
$t_bug_data->version = isset( $p_issue['version'] ) ? $p_issue['version'] : '';
$t_bug_data->fixed_in_version = isset( $p_issue['fixed_in_version'] ) ? $p_issue['fixed_in_version'] : '';
$t_bug_data->target_version = isset( $p_issue['target_version'] ) ? $p_issue['target_version'] : '';
$t_bug_data->build = isset( $p_issue['build'] ) ? $p_issue['build'] : '';
$t_bug_data->view_state = $t_view_state_id;
$t_bug_data->summary = $t_summary;
$t_bug_data->sponsorship_total = isset( $v_sponsorship_total ) ? $v_sponsorship_total : 0;
$t_bug_data->sponsorship_total = isset( $p_issue['sponsorship_total'] ) ? $p_issue['sponsorship_total'] : 0;
$t_bug_data->due_date = date_get_null();

# omitted:
# var $bug_text_id
# $t_bug_data->profile_id;
# extended info
$t_bug_data->description = $t_description;
$t_bug_data->steps_to_reproduce = isset( $v_steps_to_reproduce ) ? $v_steps_to_reproduce : '';
$t_bug_data->additional_information = isset( $v_additional_information ) ? $v_additional_information : '';
$t_bug_data->steps_to_reproduce = isset( $p_issue['steps_to_reproduce'] ) ? $p_issue['steps_to_reproduce'] : '';
$t_bug_data->additional_information = isset( $p_issue['additional_information'] ) ? $p_issue['additional_information'] : '';

# submit the issue
$t_issue_id = bug_create( $t_bug_data );

mci_issue_set_custom_fields( $t_issue_id, $t_custom_fields );
mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'] );

if( isset( $v_notes ) && is_array( $v_notes ) ) {
foreach( $v_notes as $t_note ) {
Expand Down Expand Up @@ -607,7 +590,6 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
$t_view_state_id = mci_get_view_state_id( $p_issue['view_state'] );
$t_reporter_id = mci_get_user_id( $p_issue['reporter'] );
$t_project = $p_issue['project'];
$t_category = $p_issue['category'];
$t_summary = $p_issue['summary'];
$t_description = $p_issue['description'];
$t_custom_fields = $p_issue['custom_fields'];
Expand Down Expand Up @@ -636,13 +618,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
return new soap_fault( 'Client', '', "User '$t_handler_id' does not exist." );
}

$t_category_id = translate_category_name_to_id( $t_category, $t_project_id );
if( $t_category_id == 0 ) {
if ( is_blank( $t_category ) ) {
return new soap_fault( 'Client', '', "Category cannot be empty." );
$t_category_id = translate_category_name_to_id( $p_issue['category'], $t_project_id );
if ( $t_category_id == 0 && !config_get( 'allow_no_category' ) ) {
if ( isset( $p_issue['category'] ) && !is_blank( $p_issue['category'] ) ) {
return new soap_fault( 'Client', '', "Category field must be supplied." );
} else {
return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_name'." );
}

return new soap_fault( 'Client', '', "Category '$v_category' does not exist in project '$t_project_id'." );
}

if( isset( $v_version ) && !is_blank( $v_version ) && !version_get_id( $v_version, $t_project_id ) ) {
Expand Down
6 changes: 4 additions & 2 deletions core/bug_api.php
Expand Up @@ -569,7 +569,9 @@ function bug_create( $p_bug_data ) {
}

# Insert the rest of the data
$t_resolution = OPEN;
$c_resolution = OPEN;
$c_projection = 10;
$c_eta = 10;

$query = "INSERT INTO $t_bug_table
( project_id,
Expand Down Expand Up @@ -615,7 +617,7 @@ function bug_create( $p_bug_data ) {
" . db_param() . ",
" . db_param() . ",
" . db_param() . ")";
db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status, $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version, $c_build, $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date ) );
db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status, $c_resolution, $c_projection, $c_category_id, db_now(), db_now(), $c_eta, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version, $c_build, $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date ) );

$t_bug_id = db_insert_id( $t_bug_table );

Expand Down
21 changes: 14 additions & 7 deletions core/email_api.php
Expand Up @@ -850,15 +850,22 @@ function email_send( $p_email_data ) {
}
}

if( !$mail->Send() ) {
$t_success = false;
} else {
$t_success = true;

if( $t_email_data->email_id > 0 ) {
email_queue_delete( $t_email_data->email_id );
try
{
if ( !$mail->Send() ) {
$t_success = false;
} else {
$t_success = true;

if ( $t_email_data->email_id > 0 ) {
email_queue_delete( $t_email_data->email_id );
}
}
}
catch ( phpmailerException $e )
{
$t_success = false;
}

$mail->ClearAllRecipients();
$mail->ClearAttachments();
Expand Down

0 comments on commit a6773fc

Please sign in to comment.