Using Mantis to account for requests from subscribers, often had to face the following difficulties:
1) When adding a new application, you have to enter or copy-paste some of the information from the customer’s card into Mantis, which is, firstly, laziness, and secondly, it can potentially lead to information distortion.
2) It is not always possible to quickly read previous applications for this subscriber, firstly, because it is lazy, secondly, see point one, regarding distorted information.
To solve this problem, we use the API from Mantis - mantisconnect.php.
Start
The mention of this API skipped both on the habre and on the mantisbt forum, but the problem was that all the conversations stopped on the fact that “everything is simple”, but for me as a programmer, it was not very easy to understand with what to start. Looking ahead, I can say that everything is really simple there, I will try to tell about it.
API at Mantis works under the SOAP protocol. To work with it, we need either an external NuSOAP library, or you can use the standard php_soap extension. You can see what is in this API here:
http://www.mantisbt.org/bugs/api/soap/mantisconnect.php
http://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl
')
Now let's figure out what to do with all this wealth.
We need to write a php script in which:
1) Create a SOAP client
$client = new nusoap_client($WSDL_POINT, false);
$WSDL_POINT
is the url of the mantisconnect.php location in your tracker, http: // [website] /api/soap/mantisconnect.php?wsdl
2) Use the created client for our selfish purposes. As an example, use the simplest function - view version (
mc_version
)
$result = $client->call('mc_version', 'http://localhost/mantis/api/soap/mantisconnect.php', 'http://soap.amazon.com');
The result will be a string with a bugtracker version.
If you try to get information about a specific incident, we get the following script:
<?php require_once('nusoap-0.9.5/lib/nusoap.php'); $WSDL_POINT = "http://localhost/mantis/api/soap/mantisconnect.php"; $username = 'administrator'; $password = 'root'; $issue_id = 1; $params = array( 'username' => $username, 'password' => $password, 'issue_id' => $issue_id ); $client = new nusoap_client($WSDL_POINT, false); $result = $client->call('mc_issue_get', $params, 'http://localhost/mantis/api/soap/mantisconnect.php', 'http://soap.amazon.com'); echo "<pre>"; print_r ($result); echo "</pre>"; ?>
$params
- an array of input variables. To receive an incident, as can be seen from the description in api, we need a username, password and the number of the incident.
The result will be an associative array with all the data associated with the incident. You can view it using the
print_r()
function. We can pick up the required fields as elements of an array.
Here we can quite possibly encounter a problem - instead of an array with an incident, an array with an error may arrive:
Array ( [faultcode] => Server [faultactor] => [faultstring] => Error Type: SYSTEM NOTICE, Error Description: Use of undefined constant ERROR_DUPLICATE_FILE - assumed 'ERROR_DUPLICATE_FILE',)
The problem appears if in the settings of the user account whose login / password is used for “communication” with Mantis, any language other than English is indicated in the language settings. This is due to the fact that the code in the mantis changed, and the localization files are not corrected.
To remedy the situation in the following ways:
1) set the English language in the settings;
2) wait for version 1.2.11, where they promise to fix it, or upgrade the nightly assembly;
3) fix the localization file
/lang/strings_russian.txt
yourself - by enclosing
ERROR_DUPLICATE_FILE
in single quotes.
Create application
Having looked at what constitutes an array with an incident, we can create the same in order to create an incident. In addition, those fields that you do not specify in the incoming array will be automatically updated by default.
Suppose to create an application, from the subscriber's card, we need:
1) his full name;
2) login.
Plus the reason for the appeal.
Login we will put in a specially created login field.
We get the following array:
$issue_data = array( 'project' => array ( 'id' => 1 ), 'category' => "general", 'reporter' => array ( 'id' => $reporter_id ), 'summary' => $summary, 'description' => $description, 'custom_fields' => array ($sequence_login_field => array ( 'field' => array ( 'id' => $login_field_id ), 'value' => $login ), ) );
project_id
= 1 - the project id to which we add the incident
$reporter_id
- Yes, we can substitute any user in this place, conveniently, because we will not need to know passwords
all employees
$summary
- consists of the name and maybe even more. information
$description
- reason for contacting
$sequence_login_field, $login_field_id
- taken from Mantis
$login
- subscriber's login from client's card
Next, we put this array in $ params
$params = array( 'username' => $username, 'password' => $password, 'issue' => $issue_data );
and feel free to ship. In response, we will return the number of the incident created.
Information about incidents created
When we have a subscriber's login in all created requests (the login is unique), when opening a client card we can perform another soap request to Mantis, namely, a search query in order to show us all the incidents related to this subscriber.
Unfortunately, there is no such request so that you can search in the Mantis base, but you can use a pre-created pre-made filter. In my case, I created a filter for 1000 incidents with all statuses except “closed” and sorted in ascending order of the time of the last instance change.
$params = array( 'username' => $username, 'password' => $password, 'project_id' => 1, 'filter_id' => $filter_id, 'page_number' => 1, 'per_page' => 100 );
As a result, I accept an array of 100 incidents, and it remains for me to only display those whose login matches the one specified in this client card.