Menu

#2 Searching issue Id from description

open
nobody
None
5
2011-04-04
2011-04-04
No

Add the abilitty to search an issue from its description.

---> Request.cs

/// <summary>
/// Search for an issue with the specified description and return its issue id.
/// </summary>
/// <remarks>
/// This is useful to allow a software which is automatically reporting issues due
/// to exceptions or whatever reason to check first that the issue was not reported
/// before. And if it was, then it knows the issue id and hence is able to add
/// a note or do whatever with this id. Other applications may decide to delete
/// the issue and create a new one, basically it is up to the client application
/// to decide how to use the returned issue id.
/// </remarks>
/// <param name="summary">The description to search for.</param>
/// <returns>0: not found, otherwise issue id</returns>
/// <exception cref="ArgumentNullException">Description field is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">Description field is empty.</exception>
public int IssueGetIdFromDescription(string description)
{
if (description == null)
throw new ArgumentNullException("description");

if (description.Trim().Length == 0)
throw new ArgumentOutOfRangeException("description");

return Convert.ToInt32(mc.mc_issue_get_id_from_summary(session.Username, session.Password, description));
}

In the Mantis API :

--> mantisconnect.php

### mc_issue_get_id_from_description (should be replaced with a more general search that returns matching issues directly)
$l_oServer->register( 'mc_issue_get_id_from_description',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'description' => 'xsd:string'
),
array(
'return' => 'xsd:integer'
),
$t_namespace,
false, false, false,
'Get the id of the issue with the specified summary.'
);

--> mc_issue_api.php

/**
* Get the id of an issue via the issue's description.
*
* @param string $p_username The name of the user trying to delete the issue.
* @param string $p_password The password of the user.
* @param string $p_description The description of the issue to retrieve.
* @return integer The id of the issue with the given description, 0 if there is no such issue.
*/
function mc_issue_get_id_from_description( $p_username, $p_password, $p_description ) {
$t_user_id = mci_check_login( $p_username, $p_password );
if( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

$t_bug_table = db_get_table( 'mantis_bug_table' );

$query = "SELECT id
FROM $t_bug_text_table
WHERE description = " . db_param();

$result = db_query_bound( $query, Array( $p_description ), 1 );

if( db_num_rows( $result ) == 0 ) {
return 0;
} else {
while(( $row = db_fetch_array( $result ) ) !== false ) {
$t_issue_id = (int) $row['id'];
//$t_project_id = bug_get_field( $t_issue_id, 'project_id' );

//if( mci_has_readonly_access( $t_user_id, $t_project_id ) ) {
return $t_issue_id;
//}
}

// no issue found that belongs to a project that the user has read access to.
return 0;
}
}

Jeff

Discussion


Log in to post a comment.