Skip to content
Browse files

Mantis integration contributed by Simone Tellini

  • Loading branch information...
1 parent 6d2e3f0 commit c6cd50bf8a24259aa787701ef0d9f04c1642d05f @tcurdt tcurdt committed
Showing with 261 additions and 0 deletions.
  1. +23 −0 Server/Mantis/README.txt
  2. +19 −0 Server/Mantis/config.php
  3. +155 −0 Server/Mantis/mantis.php
  4. +64 −0 Server/Mantis/submit.php
View
23 Server/Mantis/README.txt
@@ -0,0 +1,23 @@
+Hi,
+
+this is a simple script that enable you to integrate FeedbackReporter and
+Mantis.
+
+You'll need to change a couple of values in config.php
+
+If you need to contact me, you can do it via my website:
+
+ http://tellini.info/
+
+
+Other useful links... FeedbackReporter Framework:
+
+ http://vafer.org/projects/feedbackreporter/
+
+Mantis:
+
+ http://www.mantisbt.org/
+
+
+Have fun,
+ Simone
View
19 Server/Mantis/config.php
@@ -0,0 +1,19 @@
+<?php
+ // the reporter of the issues
+ define( 'MANTIS_USER', 'user' );
+ define( 'MANTIS_PWD', 'password' );
+
+ // if true, this script is running on the same machine hosting mantis,
+ // so we can use its API directly
+ define( 'MANTIS_LOCAL', true );
+ // path to your mantis installation, only needed if MANTIS_LOCAL is true
+ define( 'MANTIS_PATH', dirname( __FILE__ ) . '/../mantis/' );
+
+ // used only when MANTIS_LOCAL is false. The SOAP extension is required.
+ define( 'MANTIS_URL', 'http://www.yoursite.com/mantis/' );
+ define( 'MANTIS_WSDL', MANTIS_URL . 'api/soap/mantisconnect.php?wsdl' );
+
+ // constants for the reports
+ define( 'BUG_SUMMARY', 'Crash report' );
+ define( 'BUG_CATEGORY', 'Feedback' );
+?>
View
155 Server/Mantis/mantis.php
@@ -0,0 +1,155 @@
+<?php
+/*
+ * Copyright 2009, Simone Tellini, http://tellini.info
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+$g_bypass_headers = true;
+require_once( MANTIS_PATH . 'core.php' );
+
+class Mantis
+{
+ private $userID;
+ private $client;
+
+ public function __construct()
+ {
+ if( MANTIS_LOCAL ) {
+
+ if( auth_attempt_script_login( MANTIS_USER, MANTIS_PWD ))
+ $this->userID = auth_get_current_user_id();
+
+ } else
+ $this->client = new SoapClient( MANTIS_WSDL );
+ }
+
+ public function getProject( $proj )
+ {
+ if( MANTIS_LOCAL ) {
+
+ $ret = new StdClass;
+ $ret->id = project_get_id_by_name( $proj );
+
+ } else {
+
+ $projects = $this->client->mc_projects_get_user_accessible( MANTIS_USER, MANTIS_PWD );
+
+ foreach( $projects as $p )
+ if( $p->name == $proj )
+ $ret = $p;
+ }
+
+ return( $ret );
+ }
+
+ public function hasVersion( $projID, $version )
+ {
+ if( MANTIS_LOCAL )
+ $ret = version_get_id( $version, $projID ) !== false;
+ else {
+
+ $vers = $this->client->mc_project_get_versions( MANTIS_USER, MANTIS_PWD, $projID );
+ $ret = false;
+
+ foreach( $vers as $v )
+ if( $v->name == $version ) {
+ $ret = true;
+ break;
+ }
+ }
+
+ return( $ret );
+ }
+
+ public function addVersion( $projID, $version )
+ {
+ if( MANTIS_LOCAL ) {
+
+ if( version_add( $projID, $version, true, $version )) {
+
+ $t_version_id = version_get_id( $version, $projID );
+
+ if ( !is_blank( $v_date_order )) {
+
+ $t_version = version_get( $t_version_id );
+ $t_version->date_order = date( "Y-m-d H:i:s", strtotime( $v_date_order ));
+
+ version_update( $t_version );
+ }
+ }
+
+ } else {
+
+ $this->client->mc_project_version_add( MANTIS_USER, MANTIS_PWD,
+ array(
+ 'name' => $version,
+ 'project_id' => $projID,
+ 'description' => $version,
+ 'released' => true
+ ));
+ }
+ }
+
+ public function addIssue( $issue )
+ {
+ if( MANTIS_LOCAL ) {
+
+ $t_bug_data = new BugData;
+ $t_bug_data->project_id = $issue->project->id;
+ $t_bug_data->reporter_id = $this->userID;
+ $t_bug_data->priority = $issue->priority[ 'id' ];
+ $t_bug_data->severity = $issue->severity[ 'id' ];
+ $t_bug_data->reproducibility = $issue->reproducibility[ 'id' ];
+ $t_bug_data->status = $issue->status[ 'id' ];
+ $t_bug_data->resolution = $issue->resolution[ 'id' ];
+ $t_bug_data->projection = $issue->projection[ 'id' ];
+ $t_bug_data->category = $issue->category;
+ $t_bug_data->eta = $issue->eta[ 'id' ];
+ $t_bug_data->version = $issue->version;
+ $t_bug_data->view_state = $issue->view_state[ 'id' ];
+ $t_bug_data->summary = $issue->summary;
+
+ # extended info
+ $t_bug_data->description = $issue->description;
+ $t_bug_data->additional_information = $issue->additional_information;
+
+ # submit the issue
+ $ret = bug_create( $t_bug_data );
+
+ email_new_bug( $ret );
+
+ } else
+ $ret = $this->client->mc_issue_add( MANTIS_USER, MANTIS_PWD, $issue );
+
+ return( $ret );
+ }
+
+ public function addAttachment( $bugID, $name, $str )
+ {
+ if( MANTIS_LOCAL ) {
+
+ $tmpFile = tempnam( sys_get_temp_dir(), 'feedback' );
+
+ file_put_contents( $tmpFile, $str );
+
+ file_add( $bugID, $tmpFile, $name, 'text/plain' );
+
+ unlink( $tmpFile );
+
+ } else
+ $this->client->mc_issue_attachment_add( MANTIS_USER, MANTIS_PWD, $bugID,
+ $name, 'text/plain', $str );
+ }
+}
+?>
View
64 Server/Mantis/submit.php
@@ -0,0 +1,64 @@
+<?php
+ /*
+ * Copyright 2009, Simone Tellini, http://tellini.info
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ require_once( 'config.php' );
+ require_once( 'mantis.php' );
+
+ $issue = new StdClass;
+ $crashlog = explode( 'Binary Images:', $_POST[ 'crashes' ] );
+
+ $issue->summary = BUG_SUMMARY;
+ $issue->severity = array( 'id' => 70 );
+ $issue->category = BUG_CATEGORY;
+ $issue->description = 'From: ' . $_POST[ 'email' ] . "\n\n" . $_POST[ 'comment' ];
+ $issue->additional_information = $crashlog[ 0 ];
+ $issue->priority = array( 'id' => 10 );
+ $issue->status = array( 'id' => 10 );
+ $issue->reproducibility = array( 'id' => 70 );
+ $issue->resolution = array( 'id' => 10 );
+ $issue->projection = array( 'id' => 10 );
+ $issue->eta = array( 'id' => 10 );
+ $issue->view_state = array( 'id' => 50 );
+ $issue->version = $_POST[ 'version' ];
+
+ if( empty( $issue->description ))
+ $issue->description = 'Crashed.';
+
+ $attachments = array( 'crashes', 'console', 'preferences', 'exception', 'shell', 'system' );
+
+ try {
+ $mantis = new Mantis();
+
+ $issue->project = $mantis->getProject( $_REQUEST[ 'project' ] );
+
+ if( !$mantis->hasVersion( $issue->project->id, $issue->version ))
+ $mantis->addVersion( $issue->project->id, $issue->version );
+
+ $id = $mantis->addIssue( $issue );
+
+ foreach( $attachments as $f ) {
+
+ $str = $_POST[ $f ];
+
+ if( !empty( $str ))
+ $mantis->addAttachment( $id, $f . '.txt', $str );
+ }
+ }
+ catch( SoapFault $e ) {
+ print( 'ERR An error occurred while storing the report' );
+ }
+?>

0 comments on commit c6cd50b

Please sign in to comment.
Something went wrong with that request. Please try again.