bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_profiles2mantis_user_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_products2mantis_project_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value ); bz2m_migration_bugs2mantis_bug_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_bugs2mantis_bug_table_callback( $row_count, $flag_first, $key, $value ); bz2m_migration_bugs2mantis_bug_text_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_bugs_activity2mantis_bug_history_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_bugs_activity2mantis_bug_history_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_longdescs2mantis_bugnote_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_longdescs2mantis_bugnote_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_longdescs2mantis_bugnote_text_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_longdescs2mantis_bugnote_text_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_mantis_category_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_mantis_category_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_mantis_customclient_table(); //CUSTOM \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_mantis_customclient_table_callback( $row_count, $flag_first, $key, $value ); //CUSTOM bz2m_migration_mantis_bug_file_table(); //CUSTOM - TO USE THIS, YOU NEED TO COPY EMPTY mantis_bug_file_table TO YOUR BUGZILLA DATABASE (YOU HAVE TO DUMP AND MOVE THIS TABLE LATER BACK TO MANTIS DB) \-> bz2m_select( $sql_fields_source, $sql_table_source, $data, $total, $joins ); //COMMON \-> bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); //COMMON \-> bz2m_migration_mantis_bug_file_table_callback( $row_count, $flag_first, $key, $value ); //COMMON mysql_close( $link); */ // ------------------------------------------------------------------------------------------ // PHP CODE // ------------------------------------------------------------------------------------------ function bz2m_connect( &$mysqli ) { // BUGZILLA - connect to database /********* // PHP version before 5.6.16 $link = mysql_connect('localhost', 'myuser', 'mypassword'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bugs", $link); *********/ $myport = 3306; $mysqli = new mysqli('localhost', 'webuser', 'password', 'bugzilla', $myport); if ($mysqli->connect_error) { die('Erreur de connexion (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); } echo 'Success... ' . $mysqli->host_info . "\n"; } // ------------------------------------------------------------------------------------------ function bz2m_select($con, $sql_fields, $sql_table, &$data, &$total, $joins = "", $limit = "") { // BUGZILLA - read bugs $sql="SELECT "; $flag_first = true; foreach ($sql_fields as $key1=> $value1 ) { if($flag_first ) { $flag_first = false; $sql = $sql."`".$value1."`"; } else { $sql = $sql.","."`".$value1."`"; } } $sql = $sql." FROM "."`".$sql_table."` " . $joins . " " . $limit; // $sql = $sql." FROM "."`".$sql_table."` WHERE `bug_id`<3"; // $sql = $sql." FROM "."`".$sql_table."` limit 0 ,3;"; echo ""; echo $sql; echo ""; $result = mysqli_query($con, $sql ); $columns = array(); $data = array(); // Table(Rows) while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { foreach ($sql_fields as $key1=> $value1 ) { $columns[]= $row[$value1]; //echo "$value1 $row[$value1] "; } $data[]= $columns; unset($columns); } $total = mysqli_num_rows($result); mysqli_free_result($result); } // ------------------------------------------------------------------------------------------ function bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, &$data, $callback_function ) { // MANTIS - write bugs global $mysqli; $sql="INSERT INTO `$sql_table` ("; $flag_first = true; foreach ($sql_fields as $key1=> $value1 ) { if($flag_first ) { $flag_first = false; $sql = $sql."`".$value1."`"; } else { $sql = $sql.","."`".$value1."`"; } } $sql = $sql.") VALUES( "; $sql_header = $sql; foreach ($data as $key0 => $value0 ) { unset($sql); $sql = $sql_header; $row_count = $key0 + 1; $flag_first = true; foreach ($value0 as $key1 => $value1 ) { $sql.= call_user_func( $callback_function, $row_count, $flag_first, $sql_fields_source[$key1], $value1); if($flag_first ) $flag_first = false; //echo ""; echo "$key1 $value1"; echo ""; } $sql.= " );"; if($sql_table === 'mantis_bug_file_table') { $mysqli->query($sql); //echo $sql; echo ""; echo "#"; } else { echo $sql; echo ""; } } } // ------------------------------------------------------------------------------------------ function bz2m_migration_profiles2mantis_user_table($mysqli) //USERS { /* USERS ##### mysql> describe profiles; +----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+----------------+ | userid | mediumint(9) | NO | PRI | NULL | auto_increment | | login_name | varchar(255) | NO | UNI | NULL | | | cryptpassword | varchar(128) | YES | | NULL | | | realname | varchar(255) | YES | | NULL | | | disabledtext | mediumtext | NO | | NULL | | | disable_mail | tinyint(4) | NO | | 0 | | | mybugslink | tinyint(4) | NO | | 1 | | | extern_id | varchar(64) | YES | | NULL | | | is_enabled | tinyint(4) | NO | | 1 | | | last_seen_date | datetime | NO | | NULL | | | email | varchar(255) | NO | | NULL | | +----------------+--------------+------+-----+---------+----------------+ 11 rows in set (0.00 sec) ##### mysql> describe mantis_user_table; +-----------------------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------------+------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | varchar(32) | NO | UNI | NULL | | | realname | varchar(64) | NO | | NULL | | | email | varchar(64) | NO | | NULL | | | password | varchar(32) | NO | | NULL | | | enabled | tinyint(4) | NO | MUL | 1 | | | protected | tinyint(4) | NO | | 0 | | | access_level | smallint(6) | NO | MUL | 10 | | | login_count | int(11) | NO | | 0 | | | lost_password_request_count | smallint(6) | NO | | 0 | | | failed_login_count | smallint(6) | NO | | 0 | | | cookie_string | varchar(64) | NO | UNI | NULL | | | last_visit | datetime | NO | | 1970-01-01 00:00:01 | | | date_created | datetime | NO | | 1970-01-01 00:00:01 | | +-----------------------------+------------------+------+-----+---------------------+----------------+ 14 rows in set (0.00 sec) */ $sql_table_source= "profiles"; $sql_fields_source=array( "userid","login_name","cryptpassword","realname","login_name", "last_seen_date", "cryptpassword" ); $sql_table= "mantis_user_table"; $sql_fields = array("id","username","password","realname","email","date_created", "cookie_string"); $callback_function = "bz2m_migration_profiles2mantis_user_table_callback"; // ------ $data = array(); $total = 0; bz2m_select($mysqli, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_profiles2mantis_user_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "userid": $value1 = $value; break; case "login_name": case "cryptpassword": case "realname": case "refreshed_when": $value1 = "'".str_replace("'", "''", $value)."'"; break; case "last_seen_date": $value1 = time(value); break; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_products2mantis_project_table($mysqli) //PROJECTS { /* PROJECTS ##### mysql> describe products; +-------------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+-------------+------+-----+---------+----------------+ | id | smallint(6) | NO | PRI | NULL | auto_increment | | name | varchar(64) | NO | UNI | NULL | | | classification_id | smallint(6) | NO | | 1 | | | description | mediumtext | YES | | NULL | | | isactive | tinyint(4) | NO | | 1 | | | votesperuser | smallint(6) | NO | | NULL | | | maxvotesperbug | smallint(6) | NO | | 10000 | | | votestoconfirm | smallint(6) | NO | | NULL | | | defaultmilestone | varchar(20) | NO | | --- | | | allows_unconfirmed| tinyint(4) | NO | | 1 | | +-------------------+-------------+------+-----+---------+----------------+ 10 rows in set (0.00 sec) mysql> ##### mysql> describe mantis_project_table; +----------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(128) | NO | UNI | NULL | | | status | smallint(6) | NO | | 10 | | | enabled | tinyint(4) | NO | | 1 | | | view_state | smallint(6) | NO | MUL | 10 | | | access_min | smallint(6) | NO | | 10 | | | file_path | varchar(250) | NO | | NULL | | | description | text | NO | | NULL | | | category_id | int(10) unsigned | NO | | 1 | | | inherit_global | tinyint(4) | NO | | 0 | | +----------------+------------------+------+-----+---------+----------------+ 10 rows in set (0.01 sec) */ $sql_table_source= "products"; $sql_fields_source= array( "id","name","description","votesperuser","votestoconfirm" ); $sql_table= "mantis_project_table"; $callback_function = "bz2m_migration_products2mantis_project_table_callback"; $sql_fields = array("id","name","description", "status", "enabled"); // ---- $data = array(); $total = 0; bz2m_select($mysqli, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_products2mantis_project_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "id": $value1 = $value; break; case "name": case "description": $value1 = "'".str_replace("'", "''", htmlentities($value, ENT_HTML5, 'utf-8'))."'"; break; case "votesperuser": $value1 = 10; break; case "votestoconfirm": $value1 = 1; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs2mantis_bug_table($con) //BUGS { /* BUGS ##### mysql> describe bugs; +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | bug_id | mediumint(9) | NO | PRI | NULL | auto_increment | | assigned_to | mediumint(9) | NO | MUL | NULL | | | bug_file_loc | text | YES | | NULL | | | bug_severity | varchar(64) | NO | MUL | NULL | | | bug_status | varchar(64) | NO | MUL | NULL | | | creation_ts | datetime | YES | MUL | NULL | | | delta_ts | datetime | NO | MUL | NULL | | | short_desc | mediumtext | NO | MUL | NULL | | | op_sys | varchar(64) | NO | MUL | NULL | | | priority | varchar(64) | NO | MUL | NULL | | | product_id | smallint(6) | NO | MUL | NULL | | | rep_platform | varchar(64) | NO | | NULL | | | reporter | mediumint(9) | NO | MUL | NULL | | | version | varchar(64) | NO | MUL | NULL | | | component_id | smallint(6) | NO | MUL | NULL | | | resolution | varchar(64) | NO | MUL | NULL | | | target_milestone | varchar(20) | NO | MUL | --- | | | qa_contact | mediumint(9) | YES | MUL | NULL | | | status_whiteboard | mediumtext | NO | | NULL | | | votes | mediumint(9) | NO | MUL | 0 | | | lastdiffed | datetime | YES | | NULL | | | everconfirmed | tinyint(4) | NO | | NULL | | | reporter_accessible | tinyint(4) | NO | | 1 | | | cclist_accessible | tinyint(4) | NO | | 1 | | | estimated_time | decimal(5,2) | NO | | 0.00 | | | remaining_time | decimal(5,2) | NO | | 0.00 | | | deadline | datetime | YES | | NULL | | | cf_client | varchar(255) | NO | | | | | cf_customer | varchar(64) | NO | | | | +---------------------+--------------+------+-----+---------+----------------+ 29 rows in set (0.00 sec) ##### mysql> describe mantis_bug_table; +-------------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | project_id | int(10) unsigned | NO | MUL | 0 | | | reporter_id | int(10) unsigned | NO | | 0 | | | handler_id | int(10) unsigned | NO | | 0 | | | duplicate_id | int(10) unsigned | NO | | 0 | | | priority | smallint(6) | NO | | 30 | | | severity | smallint(6) | NO | | 50 | | | reproducibility | smallint(6) | NO | | 10 | | | status | smallint(6) | NO | MUL | 10 | | | resolution | smallint(6) | NO | | 10 | | | projection | smallint(6) | NO | | 10 | | | eta | smallint(6) | NO | | 10 | | | bug_text_id | int(10) unsigned | NO | | 0 | | | os | varchar(32) | NO | | NULL | | | os_build | varchar(32) | NO | | NULL | | | platform | varchar(32) | NO | | NULL | | | version | varchar(64) | NO | | NULL | | | fixed_in_version | varchar(64) | NO | MUL | NULL | | | build | varchar(32) | NO | | NULL | | | profile_id | int(10) unsigned | NO | | 0 | | | view_state | smallint(6) | NO | | 10 | | | summary | varchar(128) | NO | | NULL | | | sponsorship_total | int(11) | NO | MUL | 0 | | | sticky | tinyint(4) | NO | | 0 | | | category_id | int(10) unsigned | NO | | 1 | | | date_submitted | int(10) unsigned | NO | | 1 | | | due_date | int(10) unsigned | NO | | 1 | | | last_updated | int(10) unsigned | NO | | 1 | | +-------------------+------------------+------+-----+---------------------+----------------+ 29 rows in set (0.00 sec) mysql> */ $sql_table_source= "bugs"; $sql_fields_source = array( "bug_id","assigned_to","bug_severity","bug_status","product_id","creation_ts","creation_ts","priority","reporter", "short_desc", "bug_id" , "component_id","resolution","version"); $sql_table= "mantis_bug_table"; $callback_function = "bz2m_migration_bugs2mantis_bug_table_callback"; $sql_fields = array("id","handler_id","severity","status","project_id","date_submitted","last_updated","priority","reporter_id", "summary", "bug_text_id", "category_id","resolution","version" ); // --- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs2mantis_bug_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; /* Bugzilla Bug, Evolution, Paramétrage, Documentation, Savoir Bas, Haut, ND, Normal, TBas, THaut Mantis $s_severity_enum_string = '10:Feature-Wunsch,20:Trivial,30:Fehler im Text,40:Unschönheit,50:kleinerer Fehler,60:schwerer Fehler,70:Absturz,80:Blocker' $s_status_enum_string = '10:neu,20:Rückmeldung,30:anerkannt,40:bestätigt,50:zugewiesen,80:erledigt,90:geschlossen'; $s_resolution_enum_string = '10:offen,20:erledigt,30:wiedereröffnet,40:nicht reproduzierbar,50:unlösbar,60:doppelt,70:keine Änderung notwendig,80:aufgeschoben,90:wird nicht behoben'; $s_priority_enum_string = '10:keine,20:niedrig,30:normal,40:hoch,50:dringend,60:sofort'; */ $bug_severity_map = array( "enhancement"=>10, "trivial"=>20, "Documentation"=>30, "minor"=>40, "normal"=>50, "major"=>60, "critical"=>70, "blocker"=> 80 ); $bug_status_map = array( "UNCONFIRMED"=>10, "NEW"=>10, "IN PROGRESS"=>50, "REOPENED"=>20, "RESOLVED"=>80, "CLOSED"=>90, "WAITING FOR REPLY"=>20, "CONFIRMED"=>40 ); $bug_resolution_map = array( ""=>10, "FIXED"=>20, "INVALID"=>50, "REJECTED"=>90, "DUPLICATE"=>60, "WORKS FOR ME"=>70, "REVIEW/TESTING"=>20, "READY TO DEPLOY"=>20, "DONE/LIVE"=>20, "FREEZE"=>80, "APPROVED"=>10, "NOT REPRODUCABLE"=>40 ); $bug_priority_map = array( "P5"=>10, "P4"=>20, "P3"=>30, "P2"=>40, "P1"=>60 ); //echo "$key $value "; switch ($key) { case "bug_id": case "assigned_to": case "reporter": case "product_id": case "component_id": $value1 = $value; break; case "short_desc": $value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'utf-8') ); $value1 = "\"".$value."\""; break; case "version": $value = str_replace("\"","'",$value ); $value1 = "\"".$value."\""; break; case "creation_ts": $value1 = strtotime( $value ); break; case "bug_severity": if( isset($bug_severity_map[$value]) ) { $value1 = $bug_severity_map[$value]; } else { $value1 = "VALUE_ERROR_".$value."_VALUE_ERROR"; } break; case "bug_status": if( isset($bug_status_map[$value]) ) { $value1 = $bug_status_map[$value]; } else { $value1 = "VALUE_ERROR_".$value."_VALUE_ERROR"; } break; case "priority": if( isset($bug_priority_map[$value]) ) { $value1 = $bug_priority_map[$value]; } else { $value1 = "VALUE_ERROR_".$value."_VALUE_ERROR"; } break; case "resolution": if( isset($bug_resolution_map[$value]) ) { $value1 = $bug_resolution_map[$value]; } else { $value1 = "VALUE_ERROR_".$value."_VALUE_ERROR"; } break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs_activity2mantis_bug_history_table($con) //BUGS HISTORY { /* BUGS HISTORY ##### mysql> describe bugs_activity; +-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | bug_id | mediumint(9) | NO | MUL | NULL | | | attach_id | mediumint(9) | YES | | NULL | | | who | mediumint(9) | NO | MUL | NULL | | | bug_when | datetime | NO | MUL | NULL | | | fieldid | mediumint(9) | NO | MUL | NULL | | | added | tinytext | YES | | NULL | | | removed | tinytext | YES | | NULL | | | comment_id| int(11) | YES | | NULL | | | id | int(11) | NO | | AUTO | | +-----------+--------------+------+-----+---------+-------+ 9 rows in set (0.00 sec) ##### mysql> describe mantis_bug_history_table; +---------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | user_id | int(10) unsigned | NO | MUL | 0 | | | bug_id | int(10) unsigned | NO | MUL | 0 | | | field_name | varchar(32) | NO | | NULL | | | old_value | varchar(128) | NO | | NULL | | | new_value | varchar(128) | NO | | NULL | | | type | smallint(6) | NO | | 0 | | | date_modified | int | NO | | NULL | | +---------------+------------------+------+-----+---------------------+----------------+ 8 rows in set (0.00 sec) */ $sql_table_source= "bugs_activity"; $sql_fields_source = array( "bug_id","who","bug_when","fieldid","added","removed" ); $sql_table= "mantis_bug_history_table"; $callback_function = "bz2m_migration_bugs_activity2mantis_bug_history_table_callback"; $sql_fields = array("bug_id","user_id","date_modified","field_name","old_value","new_value"); // ---- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs_activity2mantis_bug_history_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "bug_id": case "who": $value1 = $value; break; case "bug_when": $value1 = strtotime( $value ); break; case "fieldid": case "added": case "removed": $value1 = "'".str_replace("'", "''", $value)."'"; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_longdescs2mantis_bugnote_table($con) //BUGS DESCRIPTION { /* BUGS DESCRIPTION ##### | mysql> describe longdescs; +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | comment_id | mediumint(9) | NO | MUL | NULL | | | bug_id | mediumint(9) | NO | MUL | NULL | | | who | mediumint(9) | NO | MUL | NULL | | | bug_when | datetime | NO | MUL | NULL | | | work_time | decimal(5,2) | NO | | 0.00 | | | thetext | mediumtext | YES | MUL | NULL | | | isprivate | tinyint(4) | NO | | 0 | | | already_wrapped | tinyint(4) | NO | | 0 | | | type | smallint(6) | NO | | 0 | | | extra_data | varchar(255) | NO | | 0 | | +-----------------+--------------+------+-----+---------+-------+ 10 rows in set (0.00 sec) ##### mysql> describe mantis_bugnote_table; +-----------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+------------------+------+-----+---------------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | | | bug_id | int(10) unsigned | NO | MUL | 0 | | | reporter_id | int(10) unsigned | NO | | 0 | | | bugnote_text_id | int(10) unsigned | NO | | 0 | | | view_state | smallint(6) | NO | | 10 | | | note_type | int(11) | YES | | 0 | | | note_attr | varchar(250) | YES | | NULL | | | time_tracking | int(10) unsigned | NO | | 0 | | | last_modified | int(10) unsigned | NO | MUL | 1 | | | date_submitted | int(10) unsigned | NO | | 1 | | +-----------------+------------------+------+-----+---------------------+----------------+ 10 rows in set (0.01 sec) mysql> ##### */ $sql_table_source= "longdescs"; $sql_fields_source = array("comment_id", "bug_id","who","bug_when","bug_when","work_time", ); $sql_table= "mantis_bugnote_table"; $callback_function = "bz2m_migration_longdescs2mantis_bugnote_table_callback"; $sql_fields = array("id", "bug_id","reporter_id","date_submitted","last_modified","bugnote_text_id",); // --------- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_longdescs2mantis_bugnote_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "bug_id": case "who": case "comment_id": $value1 = $value; break; case "bug_when": $value1 = strtotime( $value ); break; case "work_time": $value1 = $row_count; break; case "thetext": $value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'utf-8') ); $value = str_replace("\\","\\\\",$value ); $value = str_replace("\n","",$value ); $value1 = "\"".$value."\""; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_longdescs2mantis_bugnote_text_table($con) //BUGS DESCRIPTION { /* BUGS DESCRIPTION ##### | mysql> describe longdescs; +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | comment_id | mediumint(9) | NO | MUL | NULL | | | bug_id | mediumint(9) | NO | MUL | NULL | | | who | mediumint(9) | NO | MUL | NULL | | | bug_when | datetime | NO | MUL | NULL | | | work_time | decimal(5,2) | NO | | 0.00 | | | thetext | mediumtext | YES | MUL | NULL | | | isprivate | tinyint(4) | NO | | 0 | | | already_wrapped | tinyint(4) | NO | | 0 | | | type | smallint(6) | NO | | 0 | | | extra_data | varchar(255) | NO | | 0 | | +-----------------+--------------+------+-----+---------+-------+ 10 rows in set (0.00 sec) mysql> describe mantis_bugnote_text_table; +-------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | | | note | text | NO | | NULL | | +-------+------------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) ##### */ $sql_table_source= "longdescs"; $sql_fields_source = array("comment_id", "thetext" ); $sql_table= "mantis_bugnote_text_table"; $callback_function = "bz2m_migration_longdescs2mantis_bugnote_text_table_callback"; $sql_fields = array("id", "note"); // --------- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_longdescs2mantis_bugnote_text_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "bug_id": case "comment_id": $value1 = $value; break; case "thetext": $value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'utf-8') ); $value = str_replace("\\","\\\\",$value ); $value = str_replace("\n","",$value ); $value1 = "\"".$value."\""; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs2mantis_bug_text_table($con) //BUGS DESCRIPTION { /* BUGS DESCRIPTION ##### mysql> describe bugs; +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | bug_id | mediumint(9) | NO | PRI | NULL | auto_increment | | assigned_to | mediumint(9) | NO | MUL | NULL | | | bug_file_loc | text | YES | | NULL | | | bug_severity | varchar(64) | NO | MUL | NULL | | | bug_status | varchar(64) | NO | MUL | NULL | | | creation_ts | datetime | YES | MUL | NULL | | | delta_ts | datetime | NO | MUL | NULL | | | short_desc | mediumtext | NO | MUL | NULL | | | op_sys | varchar(64) | NO | MUL | NULL | | | priority | varchar(64) | NO | MUL | NULL | | | product_id | smallint(6) | NO | MUL | NULL | | | rep_platform | varchar(64) | NO | | NULL | | | reporter | mediumint(9) | NO | MUL | NULL | | | version | varchar(64) | NO | MUL | NULL | | | component_id | smallint(6) | NO | MUL | NULL | | | resolution | varchar(64) | NO | MUL | NULL | | | target_milestone | varchar(20) | NO | MUL | --- | | | qa_contact | mediumint(9) | YES | MUL | NULL | | | status_whiteboard | mediumtext | NO | | NULL | | | votes | mediumint(9) | NO | MUL | 0 | | | lastdiffed | datetime | YES | | NULL | | | everconfirmed | tinyint(4) | NO | | NULL | | | reporter_accessible | tinyint(4) | NO | | 1 | | | cclist_accessible | tinyint(4) | NO | | 1 | | | estimated_time | decimal(5,2) | NO | | 0.00 | | | remaining_time | decimal(5,2) | NO | | 0.00 | | | deadline | datetime | YES | | NULL | | | cf_client | varchar(255) | NO | | NULL | | | cf_customer | varchar(64) | NO | | NULL | | +---------------------+--------------+------+-----+---------+----------------+ 29 rows in set (0.00 sec) mysql> describe mantis_bug_text_table; +------------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | description | text | NO | | NULL | | | steps_to_reproduce | text | NO | | NULL | | | additional_information | text | NO | | NULL | | +------------------------+------------------+------+-----+---------+----------------+ mysql> ##### */ $sql_table_source= "bugs"; $sql_fields_source = array( "bug_id","short_desc","resolution","votes"); $sql_table= "mantis_bug_text_table"; $callback_function = "bz2m_migration_bugs2mantis_bug_text_table_callback"; $sql_fields = array("id","description","additional_information","steps_to_reproduce"); // --- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_bugs2mantis_bug_text_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write bugs $sql = ""; //echo "$key $value "; switch ($key) { case "bug_id": $value1 = $value; break; case "short_desc": case "resolution": $value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'utf-8') ); $value = str_replace("\\","\\\\",$value ); $value = str_replace("\n","",$value ); $value1 = "\"".$value."\""; break; case "votes": $value1 = "\"\""; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_category_table($con) //BUGS CATEGORY { /* BUGS DESCRIPTION ##### | mysql> describe components; +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | id | mediumint(9) | NO | PRI | NULL | AUTO | | name | varchar(64) | NO | MUL | NULL | | | product_id | smallint(6) | NO | MUL | NULL | | | initialowner | mediumint(9) | NO | MUL | NULL | | | initialqacontact| mediumint(9) | YES | MUL | NULL | | | description | mediumtext | NO | | NULL | | | isactive | tinyint(4) | NO | | 1 | | +-----------------+--------------+------+-----+---------+-------+ 7 rows in set (0.00 sec) mysql> describe mantis_category_table; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | AUTO | | project_id | int(10) unsigned | NO | MUL | 0 | | | user_id | int(10) unsigned | NO | | 0 | | | name | varchar(128) | NO | | | | | status | int(10) unsigned | NO | | 0 | | +-------------+------------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) ##### */ $sql_table_source= "components"; $sql_fields_source = array("id", "name" , "product_id", "isactive"); $sql_table= "mantis_category_table"; $callback_function = "bz2m_migration_mantis_category_table_callback"; $sql_fields = array("id", "name", "project_id", "status"); // --------- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_category_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write category $sql = ""; //echo "$key $value "; switch ($key) { case "id": case "product_id": case "isactive": $value1 = $value; break; case "name": $value = str_replace("\"","'",htmlentities($value, ENT_HTML5, 'utf-8') ); $value = str_replace("\\","\\\\",$value ); $value = str_replace("\n","",$value ); $value1 = "\"".$value."\""; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_bug_file_table($con) //BUGS ATTACHMENTS { /* BUGS DESCRIPTION ##### | mysql> describe attachments; +-------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+--------------+------+-----+---------+----------------+ | attach_id | mediumint(9) | NO | PRI | NULL | auto_increment | | bug_id | mediumint(9) | NO | MUL | NULL | | | creation_ts | datetime | NO | MUL | NULL | | | modification_time | datetime | NO | MUL | NULL | | | description | tinytext | NO | | NULL | | | mimetype | tinytext | NO | | NULL | | | ispatch | tinyint(4) | NO | | 0 | | | filename | varchar(255) | NO | | NULL | | | submitter_id | mediumint(9) | NO | MUL | NULL | | | isobsolete | tinyint(4) | NO | | 0 | | | isprivate | tinyint(4) | NO | | 0 | | +-------------------+--------------+------+-----+---------+----------------+ 11 rows in set (0.00 sec) mysql> describe attach_data; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id | mediumint(9) | NO | PRI | NULL | | | thedata | longblob | NO | | NULL | | +---------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> describe mantis_bug_file_table; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | bug_id | int(10) unsigned | NO | MUL | 0 | | | title | varchar(250) | NO | | | | | description | varchar(250) | NO | | | | | diskfile | varchar(250) | NO | MUL | | | | filename | varchar(250) | NO | | | | | folder | varchar(250) | NO | | | | | filesize | int(11) | NO | | 0 | | | file_type | varchar(250) | NO | | | | | content | longblob | YES | | NULL | | | date_added | int(10) unsigned | NO | | 1 | | | user_id | int(10) unsigned | NO | | 0 | | +-------------+------------------+------+-----+---------+----------------+ 12 rows in set (0.00 sec) ##### */ $sql_table_source= "attachments"; $sql_fields_source = array("attach_id", "bug_id" , "creation_ts", "filename", "description", "mimetype", "submitter_id", "thedata"); $join = "INNER JOIN attach_data ON attach_data.id = attachments.attach_id"; //$limit = "LIMIT 10"; $sql_table= "mantis_bug_file_table"; $callback_function = "bz2m_migration_mantis_bug_file_table_callback"; $sql_fields = array("id", "bug_id", "date_added", "filename", "description", "file_type", "user_id", "content"); // --------- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total, $join, $limit ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_bug_file_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write category $sql = ""; //echo "$key $value "; switch ($key) { case "attach_id": case "bug_id": case "submitter_id": $value1 = $value; break; case "filename": case "description": case "mimetype": $value1 = "'".str_replace("'", "''", $value)."'"; break; case "thedata": $value1 = "'".mysql_escape_string($value)."'"; break; case "creation_ts": $value1 = time($value); break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_customclient_table($con) //BUGS CUSTOMCLIENT { /* BUGS DESCRIPTION ##### mysql> describe bugs; +---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | bug_id | mediumint(9) | NO | PRI | NULL | auto_increment | | assigned_to | mediumint(9) | NO | MUL | NULL | | | bug_file_loc | text | YES | | NULL | | | bug_severity | varchar(64) | NO | MUL | NULL | | | bug_status | varchar(64) | NO | MUL | NULL | | | creation_ts | datetime | YES | MUL | NULL | | | delta_ts | datetime | NO | MUL | NULL | | | short_desc | mediumtext | NO | MUL | NULL | | | op_sys | varchar(64) | NO | MUL | NULL | | | priority | varchar(64) | NO | MUL | NULL | | | product_id | smallint(6) | NO | MUL | NULL | | | rep_platform | varchar(64) | NO | | NULL | | | reporter | mediumint(9) | NO | MUL | NULL | | | version | varchar(64) | NO | MUL | NULL | | | component_id | smallint(6) | NO | MUL | NULL | | | resolution | varchar(64) | NO | MUL | NULL | | | target_milestone | varchar(20) | NO | MUL | --- | | | qa_contact | mediumint(9) | YES | MUL | NULL | | | status_whiteboard | mediumtext | NO | | NULL | | | votes | mediumint(9) | NO | MUL | 0 | | | lastdiffed | datetime | YES | | NULL | | | everconfirmed | tinyint(4) | NO | | NULL | | | reporter_accessible | tinyint(4) | NO | | 1 | | | cclist_accessible | tinyint(4) | NO | | 1 | | | estimated_time | decimal(5,2) | NO | | 0.00 | | | remaining_time | decimal(5,2) | NO | | 0.00 | | | deadline | datetime | YES | | NULL | | | cf_client | varchar(255) | NO | | | | | cf_customer | varchar(64) | NO | | | | +---------------------+--------------+------+-----+---------+----------------+ 29 rows in set (0.00 sec) mysql> describe mantis_custom_field_string_table; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | field_id | int(11) unsigned | NO | PRI | 0 | AUTO | | bug_id | int(11) unsigned | NO | MUL | 0 | | | value | varchar(255) | NO | | | | | text | int(10) unsigned | YES | | | | +-------------+------------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) ##### */ $sql_table_source= "bugs"; $sql_fields_source = array("cf_client", "bug_id", "cf_customer"); $sql_table= "mantis_custom_field_string_table"; $callback_function = "bz2m_migration_mantis_customclient_table_callback"; $sql_fields = array("field_id", "bug_id", "value"); // --------- $data = array(); $total = 0; bz2m_select($con, $sql_fields_source, $sql_table_source, $data, $total ); //echo ""; echo "total:$total"; echo ""; bz2m_migration( $sql_fields_source, $sql_fields, $sql_table, $data, $callback_function ); } // ------------------------------------------------------------------------------------------ function bz2m_migration_mantis_customclient_table_callback( $row_count, $flag_first, $key, $value ) { // MANTIS - write customer $sql = ""; //echo "$key $value "; switch ($key) { case "cf_client": $value1 = 1; break; case "bug_id": $value1 = $value; break; case "cf_customer": if ($value == '---') $value1 = "\"\""; else $value1 = "\"|".htmlentities($value, ENT_HTML5, 'utf-8')."|\""; break; default: $value1 = "DEFAULT_".$key."=".$value."_DEFAULT"; break; } if( isset($value1) ) { if($flag_first ) { $sql = $value1; } else { $sql = ",".$value1; } } //echo ""; echo $sql; return $sql; } // ------------------------------------------------------------------------------------------ { // BUGZILLA - MAIN //echo "/* NB : FIRST CREATE ALL YOUR USER ACCOUNT IN MANTIS WITH THE CORRESPONDING ID FROM BUGZILLA */"; //echo "
"; echo " Migration bugzilla to Mantis "; bz2m_connect($mysqli); //bz2m_migration_profiles2mantis_user_table($mysqli); //bz2m_migration_products2mantis_project_table($mysqli); //bz2m_migration_bugs2mantis_bug_table($mysqli); //bz2m_migration_bugs2mantis_bug_text_table($mysqli); //bz2m_migration_bugs_activity2mantis_bug_history_table($mysqli); //bz2m_migration_longdescs2mantis_bugnote_table($mysqli); //bz2m_migration_longdescs2mantis_bugnote_text_table($mysqli); //bz2m_migration_mantis_category_table($mysqli); //bz2m_migration_mantis_customclient_table($mysqli); bz2m_migration_mantis_bug_file_table($mysqli); echo " "; $mysqli->close(); /********* // PHP version before 5.6.16 bz2m_migration_profiles2mantis_user_table(); bz2m_migration_products2mantis_project_table(); bz2m_migration_bugs2mantis_bug_table(); bz2m_migration_bugs2mantis_bug_text_table(); bz2m_migration_bugs_activity2mantis_bug_history_table(); bz2m_migration_longdescs2mantis_bugnote_table(); bz2m_migration_longdescs2mantis_bugnote_text_table(); mysql_close( $link); *********/ } ?>