Wednesday, December 5, 2012

bugzilla to gforge conversion of the database

Script for converting bugzilla to gforge database.

I found that gforge bug reporting tool did not have very good documentation on the process of conversion and my old company wanted a quick method for getting all old bug reporting stuff in bugzilla into gforge including attachments.

This is by no means complete but it will give you an easy way to get an idea of the gforge database structure.





$bugzilla = new bugzillatransfer();
$bugzilla->startprogram();

class bugzillatransfer{

function __construct(){
// batch process here
$this->mysql = new mysqlclass();

}


public function startprogram(){


//CHANGES TO BUGS example added email person or removed them etc..
$res = $this->mysql->mysqlquery("SELECT * FROM bugs_activity where bug_id=41 order by bug_when");
while($row = mysql_fetch_array($res)){

$added = $row['added'];
$removed = $row['removed'];
$date_of_change = $row['bug_when'];
$who_tmp = $row['who'];
$who_email = $userlist_array[$who_tmp];


}

//GET THE BUG DETAILS
$res = $this->mysql->mysqlquery("SELECT * FROM bugs where bug_id='41'");
$row = mysql_fetch_array($res);
$bug_id = $row['bug_id'];
//$bug_when = $row['bug_when'];
//$email = $this->getallusers($row['who']);
//$thetext = $row['thetext'];
$assigned_to = $this->getallusers($row['assigned_to']);
$bug_status = $row['bug_status'];
$creation_ts = $row['creation_ts'];
$bug_severity = $row['bug_severity'];
$last_updated = $row['delta_ts'];
$shortdesc = $row['short_desc'];
$priority = $row['priority'];
$product_id = $row['product_id'];
$reporter = $this->getallusers($row['reporter']);
$version = $row['version'];
$component_id = $row['component_id'];
$product_component_array = $this->getcomponentinfo($component_id);

$resolution = $row['resolution'];
$everconfirmed = $row['everconfirmed']; // 1 or 0

//GET THE PEOPLE WHO ARE CC'd on the bug
$res = $this->mysql->mysqlquery("SELECT * FROM cc where bug_id='41'");
while($row = mysql_fetch_array($res)){
  $who_tmp = $row['who'];
$who_ccd_array[] = $userlist_array[$who_tmp];
 }


 //GET ALL COMMENTS ON THE BUG
 $res = $this->mysql->mysqlquery("SELECT * FROM longdescs where bug_id='41' order by bug_when");
 while($row = mysql_fetch_array($res)){
  $added = $row['thetext'];
  $who_tmp = $row['who'];
$who_email = $this->getallusers($who_tmp);

echo "COMMENTS:\n";
echo "Added: ".$added."\n"."Email: ".$who_email."\n\n";
 }



//GET ATTACHMENT and WRITE TO DIRECTORY FILES/
$query = "SELECT * FROM attach_data as d, attachments as a where a.attach_id=d.id and a.bug_id='$bug_id' ";
$res = $this->mysql->mysqlquery($query);


//LOOP WITH While STATEMENT
$row = mysql_fetch_array($res);
//print_r($row);

$myFile = "files/".$row['filename'];
$fh = fopen($myFile, 'w') or die("can't open file");
//print_r($row['thedata']);
fwrite($fh, $row['thedata']);
fclose($fh);


//SPIT OUT THE DATA
echo "Bug ID# ".$bug_id."\n".
"date of when: ".$bug_when."\n".
"email: ".$email."\n".
"Text Details: ".$thetext."\n".
"Who assigned to: ".$assigned_to."\n".
"Bug Status: ".$bug_status."\n".
"Creation timestamp: ".$creation_ts."\n".
"Bug Severity: ".$bug_severity."\n".
"Last Updated: ".$last_updated."\n".
"Short Desc: ".$shortdesc."\n".
"Priority: ".$priority."\n".
"Product id: ".$product_id."\n".
"Reporter: ".$reporter."\n".
"version: ".$version."\n".
"component id: ".$component_id."\n".
"Resolution: ".$resolution."\n".
"Everconfirmed: ".$everconfirmed."\n";

$product_component_array = $this->getcomponentinfo($component_id);
print_r($product_component_array);


}


private function getallusers($user_id){

//GET ALL THE USERS FOR LATER MAPPING THEM
if($user_id != "")
$sql = " where userid='$user_id'";

$res = $this->mysql->mysqlquery("SELECT * FROM profiles $sql");
if(mysql_num_rows($res) == 1){
$row = mysql_fetch_array($res);
$email = $row['login_name'];
$userid = $row['userid'];
//$userlist_array[$userid] = $email;
return $email;
}else{
 while($row = mysql_fetch_array($res)){
$email = $row['login_name'];
$userid = $row['userid'];
$userlist_array[$userid] = $email;
 }
  return $userlist_array;
}
}

private function getcomponentinfo($component_id){
 //GET THE components/product mapping
$res = $this->mysql->mysqlquery("select c.product_id, c.initialowner, c.name, c.description, p.name as prod_name,
p.description as prod_descrip,  from components as c, products as p
where p.id=c.product_id and c.id='$component_id'");
$row = mysql_fetch_array($res);
  //component details
  $data['initialowner'] = $row['initialowner'];
  $data['shortdesc'] = $row['name'];
  $data['longdesc'] = $row['description'];
  //product details
  $data['product_id'] = $row['product_id'];
  $data['prodname'] = $row['prod_name'];
  $data['proddesc'] = $row['prod_descrip'];
 
 return $data;
}


}


No comments:

Post a Comment

Got a Suggestion please let us know