2003-03-27 03:07:02 +03:00
|
|
|
#!/usr/bin/perl -w
|
2000-05-16 11:10:45 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (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.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Dawn Endico <endico@mozilla.org>
|
|
|
|
|
|
|
|
|
|
|
|
# This script reads in xml bug data from standard input and inserts
|
|
|
|
# a new bug into bugzilla. Everything before the beginning <?xml line
|
|
|
|
# is removed so you can pipe in email messages.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2000-06-24 04:13:55 +04:00
|
|
|
#####################################################################
|
|
|
|
#
|
|
|
|
# This script is used import bugs from another installation of bugzilla.
|
|
|
|
# Moving a bug on another system will send mail to an alias provided by
|
|
|
|
# the administrator of the target installation (you). Set up an alias
|
|
|
|
# similar to the one given below so this mail will be automatically
|
|
|
|
# run by this script and imported into your database. Run 'newaliases'
|
|
|
|
# after adding this alias to your aliases file. Make sure your sendmail
|
|
|
|
# installation is configured to allow mail aliases to execute code.
|
|
|
|
#
|
|
|
|
# bugzilla-import: "|/usr/bin/perl /opt/bugzilla/importxml.pl"
|
|
|
|
#
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
|
2000-06-24 02:43:21 +04:00
|
|
|
# figure out which path this script lives in. Set the current path to
|
|
|
|
# this and add it to @INC so this will work when run as part of mail
|
|
|
|
# alias by the mailer daemon
|
2001-06-01 14:03:52 +04:00
|
|
|
# since "use lib" is run at compile time, we need to enclose the
|
|
|
|
# $::path declaration in a BEGIN block so that it is executed before
|
|
|
|
# the rest of the file is compiled.
|
|
|
|
BEGIN {
|
|
|
|
$::path = $0;
|
2001-07-26 00:12:00 +04:00
|
|
|
$::path =~ m#(.*)/[^/]+#;
|
|
|
|
$::path = $1;
|
2001-10-05 04:42:06 +04:00
|
|
|
$::path ||= '.'; # $0 is empty at compile time. This line will
|
|
|
|
# have no effect on this script at runtime.
|
2001-06-01 14:03:52 +04:00
|
|
|
}
|
2001-10-05 04:42:06 +04:00
|
|
|
|
2001-06-01 14:03:52 +04:00
|
|
|
chdir $::path;
|
|
|
|
use lib ($::path);
|
2000-06-24 02:43:21 +04:00
|
|
|
|
2003-05-05 05:15:38 +04:00
|
|
|
use Bugzilla;
|
2003-11-22 06:50:42 +03:00
|
|
|
use Bugzilla::Config qw(:DEFAULT $datadir);
|
2005-01-01 16:44:16 +03:00
|
|
|
use Bugzilla::BugMail;
|
2003-05-05 05:15:38 +04:00
|
|
|
|
2000-06-24 03:52:32 +04:00
|
|
|
use XML::Parser;
|
|
|
|
use Data::Dumper;
|
|
|
|
$Data::Dumper::Useqq = 1;
|
2003-02-10 09:26:39 +03:00
|
|
|
use Bugzilla::BugMail;
|
2005-02-25 02:42:48 +03:00
|
|
|
use Bugzilla::User;
|
2000-06-24 03:52:32 +04:00
|
|
|
|
|
|
|
require "globals.pl";
|
|
|
|
|
2002-08-25 20:38:13 +04:00
|
|
|
GetVersionTable();
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-24 02:43:21 +04:00
|
|
|
|
2000-05-16 11:10:45 +04:00
|
|
|
sub sillyness {
|
|
|
|
my $zz;
|
2001-07-04 09:33:37 +04:00
|
|
|
$zz = $Data::Dumper::Useqq;
|
2000-05-16 11:10:45 +04:00
|
|
|
$zz = %::versions;
|
2000-07-14 03:12:52 +04:00
|
|
|
$zz = %::keywordsbyname;
|
2000-05-16 11:10:45 +04:00
|
|
|
$zz = @::legal_bug_status;
|
|
|
|
$zz = @::legal_opsys;
|
|
|
|
$zz = @::legal_platform;
|
|
|
|
$zz = @::legal_priority;
|
|
|
|
$zz = @::legal_severity;
|
|
|
|
$zz = @::legal_resolution;
|
|
|
|
$zz = %::target_milestone;
|
|
|
|
}
|
|
|
|
|
2001-11-26 17:16:10 +03:00
|
|
|
# XML::Parser automatically unquotes characters when it
|
|
|
|
# parses the XML, so this routine shouldn't be needed
|
|
|
|
# for anything (see bug 109530).
|
2000-05-16 11:10:45 +04:00
|
|
|
sub UnQuoteXMLChars {
|
|
|
|
$_[0] =~ s/&/&/g;
|
|
|
|
$_[0] =~ s/</</g;
|
|
|
|
$_[0] =~ s/>/>/g;
|
2001-11-26 17:16:10 +03:00
|
|
|
$_[0] =~ s/'/'/g; # ' # Darned emacs colors
|
|
|
|
$_[0] =~ s/"/"/g; # " # Darned emacs colors
|
2000-05-16 11:10:45 +04:00
|
|
|
# $_[0] =~ s/([\x80-\xFF])/&XmlUtf8Encode(ord($1))/ge;
|
|
|
|
return($_[0]);
|
|
|
|
}
|
|
|
|
|
2000-06-23 00:00:14 +04:00
|
|
|
sub MailMessage {
|
|
|
|
my $subject = shift @_;
|
|
|
|
my $message = shift @_;
|
|
|
|
my @recipients = @_;
|
|
|
|
|
|
|
|
my $to = join (", ", @recipients);
|
|
|
|
my $header = "To: $to\n";
|
2000-07-14 03:12:52 +04:00
|
|
|
my $from = Param("moved-from-address");
|
|
|
|
$from =~ s/@/\@/g;
|
|
|
|
$header.= "From: Bugzilla <$from>\n";
|
2000-06-23 00:00:14 +04:00
|
|
|
$header.= "Subject: $subject\n\n";
|
|
|
|
|
2005-01-01 16:44:16 +03:00
|
|
|
my $sendmessage = $header . $message . "\n";
|
|
|
|
Bugzilla::BugMail::MessageToMTA($sendmessage);
|
2000-06-23 00:00:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-16 11:10:45 +04:00
|
|
|
my $xml;
|
|
|
|
while (<>) {
|
|
|
|
$xml .= $_;
|
|
|
|
}
|
|
|
|
# remove everything in file before xml header (i.e. remove the mail header)
|
|
|
|
$xml =~ s/^.+(<\?xml version.+)$/$1/s;
|
|
|
|
|
|
|
|
my $parser = new XML::Parser(Style => 'Tree');
|
|
|
|
my $tree = $parser->parse($xml);
|
2005-02-18 19:01:48 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2000-05-16 11:10:45 +04:00
|
|
|
|
|
|
|
my $maintainer;
|
|
|
|
if (defined $tree->[1][0]->{'maintainer'}) {
|
|
|
|
$maintainer= $tree->[1][0]->{'maintainer'};
|
|
|
|
} else {
|
2000-06-23 00:00:14 +04:00
|
|
|
my $subject = "Bug import error: no maintainer";
|
|
|
|
my $message = "Cannot import these bugs because no maintainer for ";
|
|
|
|
$message .= "the exporting db is given.\n";
|
2000-06-23 23:41:38 +04:00
|
|
|
$message .= "\n\nPlease re-open the original bug.\n";
|
2000-06-23 00:00:14 +04:00
|
|
|
$message .= "\n\n$xml";
|
|
|
|
my @to = (Param("maintainer"));
|
|
|
|
MailMessage ($subject, $message, @to);
|
2000-05-16 11:10:45 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $exporter;
|
|
|
|
if (defined $tree->[1][0]->{'exporter'}) {
|
|
|
|
$exporter = $tree->[1][0]->{'exporter'};
|
|
|
|
} else {
|
2000-06-23 00:00:14 +04:00
|
|
|
my $subject = "Bug import error: no exporter";
|
|
|
|
my $message = "Cannot import these bugs because no exporter is given.\n";
|
2000-06-23 23:41:38 +04:00
|
|
|
$message .= "\n\nPlease re-open the original bug.\n";
|
2000-06-23 00:00:14 +04:00
|
|
|
$message .= "\n\n$xml";
|
|
|
|
my @to = (Param("maintainer"), $maintainer);
|
|
|
|
MailMessage ($subject, $message, @to);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
|
|
|
|
unless ( Param("move-enabled") ) {
|
|
|
|
my $subject = "Error: bug importing is disabled here";
|
|
|
|
my $message = "Cannot import these bugs because importing is disabled\n";
|
|
|
|
$message .= "at this site. For more info, contact ";
|
|
|
|
$message .= Param("maintainer") . ".\n";
|
|
|
|
my @to = (Param("maintainer"), $maintainer, $exporter);
|
|
|
|
MailMessage ($subject, $message, @to);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-02-25 02:42:48 +03:00
|
|
|
my $exporterid = login_to_id($exporter);
|
2000-06-23 00:00:14 +04:00
|
|
|
if ( ! $exporterid ) {
|
|
|
|
my $subject = "Bug import error: invalid exporter";
|
|
|
|
my $message = "The user <$tree->[1][0]->{'exporter'}> who tried to move\n";
|
|
|
|
$message .= "bugs here does not have an account in this database.\n";
|
2000-06-23 23:41:38 +04:00
|
|
|
$message .= "\n\nPlease re-open the original bug.\n";
|
2000-06-23 00:00:14 +04:00
|
|
|
$message .= "\n\n$xml";
|
2000-07-14 03:12:52 +04:00
|
|
|
my @to = (Param("maintainer"), $maintainer, $exporter);
|
2000-06-23 00:00:14 +04:00
|
|
|
MailMessage ($subject, $message, @to);
|
2000-05-16 11:10:45 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $urlbase;
|
|
|
|
if (defined $tree->[1][0]->{'urlbase'}) {
|
|
|
|
$urlbase= $tree->[1][0]->{'urlbase'};
|
|
|
|
} else {
|
2000-06-23 00:00:14 +04:00
|
|
|
my $subject = "Bug import error: invalid exporting database";
|
|
|
|
my $message = "Cannot import these bugs because the name of the exporting db was not given.\n";
|
2000-06-23 23:41:38 +04:00
|
|
|
$message .= "\n\nPlease re-open the original bug.\n";
|
2000-06-23 00:00:14 +04:00
|
|
|
$message .= "\n\n$xml";
|
|
|
|
my @to = (Param("maintainer"), $maintainer, $exporter);
|
|
|
|
MailMessage ($subject, $message, @to);
|
2000-05-16 11:10:45 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-25 08:16:01 +04:00
|
|
|
my $bugqty = ($#{$tree->[1]} +1 -3) / 4;
|
2000-06-24 03:54:35 +04:00
|
|
|
my $log = "Imported $bugqty bug(s) from $urlbase,\n sent by $exporter.\n\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
for (my $k=1 ; $k <= $bugqty ; $k++) {
|
|
|
|
my $cur = $k*4;
|
|
|
|
|
|
|
|
if (defined $tree->[1][$cur][0]->{'error'}) {
|
2000-06-23 00:00:14 +04:00
|
|
|
$log .= "\nError in bug $tree->[1][$cur][4][2]\@$urlbase:";
|
|
|
|
$log .= " $tree->[1][$cur][0]->{'error'}\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
if ($tree->[1][$cur][0]->{'error'} =~ /NotFound/) {
|
2000-06-23 00:00:14 +04:00
|
|
|
$log .= "$exporter tried to move bug $tree->[1][$cur][4][2] here";
|
|
|
|
$log .= " but $urlbase reports that this bug does not exist.\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
} elsif ( $tree->[1][$cur][0]->{'error'} =~ /NotPermitted/) {
|
2000-06-23 00:00:14 +04:00
|
|
|
$log .= "$exporter tried to move bug $tree->[1][$cur][4][2] here";
|
|
|
|
$log .= " but $urlbase reports that $exporter does not have access";
|
|
|
|
$log .= " to that bug.\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %multiple_fields;
|
|
|
|
foreach my $field (qw (dependson cc long_desc blocks)) {
|
|
|
|
$multiple_fields{$field} = "x";
|
|
|
|
}
|
|
|
|
my %all_fields;
|
|
|
|
foreach my $field (qw (dependson product bug_status priority cc version
|
2000-06-21 11:52:25 +04:00
|
|
|
bug_id rep_platform short_desc assigned_to bug_file_loc resolution
|
2000-06-09 00:30:10 +04:00
|
|
|
delta_ts component reporter urlbase target_milestone bug_severity
|
2000-07-14 03:12:52 +04:00
|
|
|
creation_ts qa_contact keywords status_whiteboard op_sys blocks)) {
|
2000-06-09 00:30:10 +04:00
|
|
|
$all_fields{$field} = "x";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
my %bug_fields;
|
|
|
|
my $err = "";
|
2003-04-25 08:16:01 +04:00
|
|
|
for (my $i=3 ; $i < $#{$tree->[1][$cur]} ; $i=$i+4) {
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined $multiple_fields{$tree->[1][$cur][$i]}) {
|
|
|
|
if (defined $bug_fields{$tree->[1][$cur][$i]}) {
|
|
|
|
$bug_fields{$tree->[1][$cur][$i]} .= " " . $tree->[1][$cur][$i+1][2];
|
|
|
|
} else {
|
|
|
|
$bug_fields{$tree->[1][$cur][$i]} = $tree->[1][$cur][$i+1][2];
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
2000-06-09 00:30:10 +04:00
|
|
|
} elsif (defined $all_fields{$tree->[1][$cur][$i]}) {
|
|
|
|
$bug_fields{$tree->[1][$cur][$i]} = $tree->[1][$cur][$i+1][2];
|
2000-05-16 11:10:45 +04:00
|
|
|
} else {
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "---\n";
|
|
|
|
$err .= "Unknown bug field \"$tree->[1][$cur][$i]\"";
|
|
|
|
$err .= " encountered while moving bug\n";
|
|
|
|
$err .= "<$tree->[1][$cur][$i]>";
|
|
|
|
if (defined $tree->[1][$cur][$i+1][3]) {
|
|
|
|
$err .= "\n";
|
2003-04-25 08:16:01 +04:00
|
|
|
for (my $j=3 ; $j < $#{$tree->[1][$cur][$i+1]} ; $j=$j+4) {
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= " <". $tree->[1][$cur][$i+1][$j] . ">";
|
|
|
|
$err .= " $tree->[1][$cur][$i+1][$j+1][2] ";
|
|
|
|
$err .= "</". $tree->[1][$cur][$i+1][$j] . ">\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$err .= " $tree->[1][$cur][$i+1][2] ";
|
|
|
|
}
|
|
|
|
$err .= "</$tree->[1][$cur][$i]>\n";
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
my @long_descs;
|
2003-04-25 08:16:01 +04:00
|
|
|
for (my $i=3 ; $i < $#{$tree->[1][$cur]} ; $i=$i+4) {
|
2000-06-09 00:30:10 +04:00
|
|
|
if ($tree->[1][$cur][$i] =~ /long_desc/) {
|
|
|
|
my %long_desc;
|
|
|
|
$long_desc{'who'} = $tree->[1][$cur][$i+1][4][2];
|
|
|
|
$long_desc{'bug_when'} = $tree->[1][$cur][$i+1][8][2];
|
|
|
|
$long_desc{'thetext'} = $tree->[1][$cur][$i+1][12][2];
|
|
|
|
push @long_descs, \%long_desc;
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
# instead of giving each comment its own item in the longdescs
|
|
|
|
# table like it should have, lets cat them all into one big
|
|
|
|
# comment otherwise we would have to lie often about who
|
|
|
|
# authored the comment since commenters in one bugzilla probably
|
|
|
|
# don't have accounts in the other one.
|
|
|
|
sub by_date {my @a; my @b; $a->{'bug_when'} cmp $b->{'bug_when'}; }
|
|
|
|
my @sorted_descs = sort by_date @long_descs;
|
|
|
|
my $long_description = "";
|
|
|
|
for (my $z=0 ; $z <= $#sorted_descs ; $z++) {
|
|
|
|
unless ( $z==0 ) {
|
|
|
|
$long_description .= "\n\n\n------- Additional Comments From ";
|
|
|
|
$long_description .= "$sorted_descs[$z]->{'who'} ";
|
|
|
|
$long_description .= "$sorted_descs[$z]->{'bug_when'}";
|
|
|
|
$long_description .= " ----\n\n";
|
|
|
|
}
|
2001-11-26 17:16:10 +03:00
|
|
|
$long_description .= $sorted_descs[$z]->{'thetext'};
|
2000-07-14 03:12:52 +04:00
|
|
|
$long_description .= "\n";
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
my $comments;
|
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
$comments .= "\n\n------- Bug moved to this database by $exporter ";
|
2000-06-09 00:30:10 +04:00
|
|
|
$comments .= time2str("%Y-%m-%d %H:%M", time);
|
|
|
|
$comments .= " -------\n\n";
|
|
|
|
$comments .= "This bug previously known as bug $bug_fields{'bug_id'} at ";
|
|
|
|
$comments .= $urlbase . "\n";
|
|
|
|
$comments .= $urlbase . "show_bug.cgi?";
|
|
|
|
$comments .= "id=" . $bug_fields{'bug_id'} . "\n";
|
|
|
|
$comments .= "Originally filed under the $bug_fields{'product'} ";
|
|
|
|
$comments .= "product and $bug_fields{'component'} component.\n";
|
|
|
|
if (defined $bug_fields{'dependson'}) {
|
|
|
|
$comments .= "Bug depends on bug(s) $bug_fields{'dependson'}.\n";
|
|
|
|
}
|
|
|
|
if (defined $bug_fields{'blocks'}) {
|
|
|
|
$comments .= "Bug blocks bug(s) $bug_fields{'blocks'}.\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
my @query = ();
|
|
|
|
my @values = ();
|
2005-02-08 19:51:03 +03:00
|
|
|
foreach my $field ( qw(creation_ts status_whiteboard) ) {
|
2000-06-09 00:30:10 +04:00
|
|
|
if ( (defined $bug_fields{$field}) && ($bug_fields{$field}) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "$field");
|
|
|
|
push (@values, SqlQuote($bug_fields{$field}));
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2005-02-08 19:51:03 +03:00
|
|
|
push (@query, "delta_ts");
|
|
|
|
if ( (defined $bug_fields{'delta_ts'}) && ($bug_fields{'delta_ts'}) ){
|
|
|
|
push (@values, SqlQuote($bug_fields{'delta_ts'}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push (@values, "NOW()");
|
|
|
|
}
|
|
|
|
|
2000-06-21 11:52:25 +04:00
|
|
|
if ( (defined $bug_fields{'bug_file_loc'}) && ($bug_fields{'bug_file_loc'}) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "bug_file_loc");
|
2001-11-26 17:16:10 +03:00
|
|
|
push (@values, SqlQuote($bug_fields{'bug_file_loc'}));
|
2000-06-21 11:52:25 +04:00
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if ( (defined $bug_fields{'short_desc'}) && ($bug_fields{'short_desc'}) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "short_desc");
|
2001-11-26 17:16:10 +03:00
|
|
|
push (@values, SqlQuote($bug_fields{'short_desc'}) );
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
|
|
|
|
my $prod;
|
|
|
|
my $comp;
|
|
|
|
my $default_prod = Param("moved-default-product");
|
|
|
|
my $default_comp = Param("moved-default-component");
|
|
|
|
if ( (defined ($bug_fields{'product'})) &&
|
|
|
|
(defined ($bug_fields{'component'})) ) {
|
|
|
|
$prod = $bug_fields{'product'};
|
|
|
|
$comp = $bug_fields{'component'};
|
|
|
|
} else {
|
|
|
|
$prod = $default_prod;
|
|
|
|
$comp = $default_comp;
|
|
|
|
}
|
|
|
|
|
2002-08-25 16:32:49 +04:00
|
|
|
# XXX - why are these arrays??
|
2000-06-09 00:30:10 +04:00
|
|
|
my @product;
|
2000-07-14 03:12:52 +04:00
|
|
|
my @component;
|
2002-08-25 16:32:49 +04:00
|
|
|
my $prod_id;
|
|
|
|
my $comp_id;
|
|
|
|
|
|
|
|
# First, try the given product/component
|
|
|
|
$prod_id = get_product_id($prod);
|
|
|
|
$comp_id = get_component_id($prod_id, $comp) if $prod_id;
|
|
|
|
|
|
|
|
if ($prod_id && $comp_id) {
|
|
|
|
$product[0] = $prod;
|
|
|
|
$component[0] = $comp;
|
|
|
|
} else {
|
|
|
|
# Second, try the defaults
|
|
|
|
$prod_id = get_product_id($default_prod);
|
|
|
|
$comp_id = get_component_id($prod_id, $default_comp) if $prod_id;
|
|
|
|
if ($prod_id && $comp_id) {
|
|
|
|
$product[0] = $default_prod;
|
|
|
|
$component[0] = $default_comp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($prod_id && $comp_id) {
|
|
|
|
push (@query, "product_id");
|
|
|
|
push (@values, $prod_id );
|
|
|
|
push (@query, "component_id");
|
|
|
|
push (@values, $comp_id );
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
my $subject = "Bug import error: invalid default product or component";
|
|
|
|
my $message = "Cannot import these bugs because an invalid default ";
|
|
|
|
$message .= "product and/or component was defined for the target db.\n";
|
|
|
|
$message .= Param("maintainer") . " needs to fix the definitions of ";
|
|
|
|
$message .= "moved-default-product and moved-default-component.\n";
|
|
|
|
$message .= "\n\nPlease re-open the original bug.\n";
|
|
|
|
$message .= "\n\n$xml";
|
|
|
|
my @to = (Param("maintainer"), $maintainer, $exporter);
|
|
|
|
MailMessage ($subject, $message, @to);
|
|
|
|
exit;
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined ($::versions{$product[0]} ) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @version = grep(lc($_) eq lc($bug_fields{'version'}),
|
|
|
|
@{$::versions{$product[0]}})) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($version[0]) );
|
|
|
|
push (@query, "version");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "version");
|
2003-04-25 08:16:01 +04:00
|
|
|
push (@values, SqlQuote($::versions{$product[0]}->[0]));
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown version $bug_fields{'version'} in product $product[0]. ";
|
2003-04-25 08:16:01 +04:00
|
|
|
$err .= "Setting version to \"$::versions{$product[0]}->[0]\".\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined ($bug_fields{'priority'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @priority = grep(lc($_) eq lc($bug_fields{'priority'}), @::legal_priority)) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($priority[0]) );
|
|
|
|
push (@query, "priority");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("P3"));
|
|
|
|
push (@query, "priority");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown priority ";
|
|
|
|
$err .= (defined $bug_fields{'priority'})?$bug_fields{'priority'}:"unknown";
|
|
|
|
$err .= ". Setting to default priority \"P3\".\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined ($bug_fields{'rep_platform'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @platform = grep(lc($_) eq lc($bug_fields{'rep_platform'}), @::legal_platform)) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($platform[0]) );
|
|
|
|
push (@query, "rep_platform");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("Other") );
|
|
|
|
push (@query, "rep_platform");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown platform ";
|
|
|
|
$err .= (defined $bug_fields{'rep_platform'})?
|
|
|
|
$bug_fields{'rep_platform'}:"unknown";
|
|
|
|
$err .= ". Setting to default platform \"Other\".\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined ($bug_fields{'op_sys'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @opsys = grep(lc($_) eq lc($bug_fields{'op_sys'}), @::legal_opsys)) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($opsys[0]) );
|
|
|
|
push (@query, "op_sys");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("other"));
|
|
|
|
push (@query, "op_sys");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown operating system ";
|
|
|
|
$err .= (defined $bug_fields{'op_sys'})?$bug_fields{'op_sys'}:"unknown";
|
|
|
|
$err .= ". Setting to default OS \"other\".\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (Param("usetargetmilestone")) {
|
|
|
|
if (defined ($::target_milestone{$product[0]} ) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @tm = grep(lc($_) eq lc($bug_fields{'target_milestone'}),
|
|
|
|
@{$::target_milestone{$product[0]}})) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($tm[0]) );
|
|
|
|
push (@query, "target_milestone");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
|
|
|
SendSQL("SELECT defaultmilestone FROM products " .
|
2002-12-20 06:37:49 +03:00
|
|
|
"WHERE name = " . SqlQuote($product[0]));
|
2000-06-09 00:30:10 +04:00
|
|
|
my $tm = FetchOneColumn();
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($tm));
|
|
|
|
push (@query, "target_milestone");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown milestone \"";
|
|
|
|
$err .= (defined $bug_fields{'target_milestone'})?
|
|
|
|
$bug_fields{'target_milestone'}:"unknown";
|
|
|
|
$err .= "\" in product \"$product[0]\".\n";
|
|
|
|
$err .= " Setting to default milestone for this product, ";
|
|
|
|
$err .= "\'" . $tm . "\'\n";
|
|
|
|
}
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (defined ($bug_fields{'bug_severity'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @severity= grep(lc($_) eq lc($bug_fields{'bug_severity'}),
|
|
|
|
@::legal_severity)) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($severity[0]) );
|
|
|
|
push (@query, "bug_severity");
|
2000-05-16 11:10:45 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("normal"));
|
|
|
|
push (@query, "bug_severity");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown severity ";
|
|
|
|
$err .= (defined $bug_fields{'bug_severity'})?
|
|
|
|
$bug_fields{'bug_severity'}:"unknown";
|
|
|
|
$err .= ". Setting to default severity \"normal\".\n";
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
|
2005-02-25 02:42:48 +03:00
|
|
|
my $reporterid = login_to_id($bug_fields{'reporter'});
|
2000-06-21 11:52:25 +04:00
|
|
|
if ( ($bug_fields{'reporter'}) && ( $reporterid ) ) {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($reporterid));
|
|
|
|
push (@query, "reporter");
|
2000-06-21 11:52:25 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($exporterid));
|
|
|
|
push (@query, "reporter");
|
2000-06-21 11:52:25 +04:00
|
|
|
$err .= "The original reporter of this bug does not have\n";
|
|
|
|
$err .= " an account here. Reassigning to the person who moved\n";
|
|
|
|
$err .= " it here, $exporter.\n";
|
|
|
|
if ( $bug_fields{'reporter'} ) {
|
|
|
|
$err .= " Previous reporter was $bug_fields{'reporter'}.\n";
|
|
|
|
} else {
|
|
|
|
$err .= " Previous reporter is unknown.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
my $changed_owner = 0;
|
|
|
|
if ( ($bug_fields{'assigned_to'}) &&
|
2005-02-25 02:42:48 +03:00
|
|
|
( login_to_id($bug_fields{'assigned_to'})) ) {
|
|
|
|
push (@values, SqlQuote(login_to_id($bug_fields{'assigned_to'})));
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "assigned_to");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($exporterid) );
|
|
|
|
push (@query, "assigned_to");
|
2000-06-09 00:30:10 +04:00
|
|
|
$changed_owner = 1;
|
2005-06-20 23:16:34 +04:00
|
|
|
$err .= "The original assignee of this bug does not have\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= " an account here. Reassigning to the person who moved\n";
|
2000-06-21 11:52:25 +04:00
|
|
|
$err .= " it here, $exporter.\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
if ( $bug_fields{'assigned_to'} ) {
|
2005-06-20 23:16:34 +04:00
|
|
|
$err .= " Previous assignee was $bug_fields{'assigned_to'}.\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2005-06-20 23:16:34 +04:00
|
|
|
$err .= " Previous assignee is unknown.\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
my @resolution;
|
|
|
|
if (defined ($bug_fields{'resolution'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(@resolution= grep(lc($_) eq lc($bug_fields{'resolution'}), @::legal_resolution)) ){
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($resolution[0]) );
|
|
|
|
push (@query, "resolution");
|
2000-06-09 00:30:10 +04:00
|
|
|
} elsif ( (defined $bug_fields{'resolution'}) && (!$resolution[0]) ){
|
|
|
|
$err .= "Unknown resolution \"$bug_fields{'resolution'}\".\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2005-06-20 23:16:34 +04:00
|
|
|
# if the bug's assignee changed, mark the bug NEW, unless a valid
|
2000-06-09 00:30:10 +04:00
|
|
|
# resolution is set, which indicates that the bug should be closed.
|
|
|
|
#
|
|
|
|
if ( ($changed_owner) && (!$resolution[0]) ) {
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("NEW"));
|
|
|
|
push (@query, "bug_status");
|
2005-06-20 23:16:34 +04:00
|
|
|
$err .= "Bug reassigned, setting status to \"NEW\".\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= " Previous status was \"";
|
|
|
|
$err .= (defined $bug_fields{'bug_status'})?
|
|
|
|
$bug_fields{'bug_status'}:"unknown";
|
|
|
|
$err .= "\".\n";
|
|
|
|
} elsif ( (defined ($bug_fields{'resolution'})) && (!$resolution[0]) ){
|
|
|
|
#if the resolution was illegal then set status to NEW
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("NEW"));
|
|
|
|
push (@query, "bug_status");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Resolution was invalid. Setting status to \"NEW\".\n";
|
|
|
|
$err .= " Previous status was \"";
|
|
|
|
$err .= (defined $bug_fields{'bug_status'})?
|
|
|
|
$bug_fields{'bug_status'}:"unknown";
|
|
|
|
$err .= "\".\n";
|
|
|
|
} elsif (defined ($bug_fields{'bug_status'}) &&
|
2005-03-18 07:21:29 +03:00
|
|
|
(my @status = grep(lc($_) eq lc($bug_fields{'bug_status'}), @::legal_bug_status)) ){
|
2000-06-09 00:30:10 +04:00
|
|
|
#if a bug status was set then use it, if its legal
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote($status[0]));
|
|
|
|
push (@query, "bug_status");
|
2000-05-16 11:10:45 +04:00
|
|
|
} else {
|
2000-06-09 00:30:10 +04:00
|
|
|
# if all else fails, make the bug new
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@values, SqlQuote("NEW"));
|
|
|
|
push (@query, "bug_status");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Unknown status ";
|
|
|
|
$err .= (defined $bug_fields{'bug_status'})?
|
|
|
|
$bug_fields{'bug_status'}:"unknown";
|
|
|
|
$err .= ". Setting to default status \"NEW\".\n";
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
if (Param("useqacontact")) {
|
|
|
|
my $qa_contact;
|
|
|
|
if ( (defined $bug_fields{'qa_contact'}) &&
|
2005-02-25 02:42:48 +03:00
|
|
|
($qa_contact = login_to_id($bug_fields{'qa_contact'})) ){
|
2003-07-18 21:11:01 +04:00
|
|
|
push (@values, $qa_contact);
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "qa_contact");
|
2000-06-09 00:30:10 +04:00
|
|
|
} else {
|
2002-08-19 05:06:56 +04:00
|
|
|
SendSQL("SELECT initialqacontact FROM components, products " .
|
2002-08-12 09:43:05 +04:00
|
|
|
"WHERE components.product_id = products.id" .
|
|
|
|
" AND products.name = " . SqlQuote($product[0]) .
|
|
|
|
" AND components.name = " . SqlQuote($component[0]) );
|
2000-06-09 00:30:10 +04:00
|
|
|
$qa_contact = FetchOneColumn();
|
2003-07-18 21:11:01 +04:00
|
|
|
push (@values, $qa_contact);
|
2000-07-14 03:12:52 +04:00
|
|
|
push (@query, "qa_contact");
|
2000-06-09 00:30:10 +04:00
|
|
|
$err .= "Setting qa contact to the default for this product.\n";
|
|
|
|
$err .= " This bug either had no qa contact or an invalid one.\n";
|
|
|
|
}
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
|
|
|
|
my $query = "INSERT INTO bugs (\n"
|
|
|
|
. join (",\n", @query)
|
|
|
|
. "\n) VALUES (\n"
|
|
|
|
. join (",\n", @values)
|
|
|
|
. "\n)\n";
|
2000-06-09 00:30:10 +04:00
|
|
|
SendSQL($query);
|
2005-02-18 19:01:48 +03:00
|
|
|
my $id = $dbh->bz_last_key('bugs', 'bug_id');
|
2000-06-09 00:30:10 +04:00
|
|
|
|
|
|
|
if (defined $bug_fields{'cc'}) {
|
|
|
|
foreach my $person (split(/[ ,]/, $bug_fields{'cc'})) {
|
|
|
|
my $uid;
|
2005-02-25 02:42:48 +03:00
|
|
|
if ( ($person ne "") && ($uid = login_to_id($person)) ) {
|
2000-06-09 00:30:10 +04:00
|
|
|
SendSQL("insert into cc (bug_id, who) values ($id, " . SqlQuote($uid) .")");
|
|
|
|
}
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
}
|
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
if (defined ($bug_fields{'keywords'})) {
|
|
|
|
my %keywordseen;
|
|
|
|
foreach my $keyword (split(/[\s,]+/, $bug_fields{'keywords'})) {
|
|
|
|
if ($keyword eq '') {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
my $i = $::keywordsbyname{$keyword};
|
|
|
|
if (!$i) {
|
|
|
|
$err .= "Skipping unknown keyword: $keyword.\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (!$keywordseen{$i}) {
|
|
|
|
SendSQL("INSERT INTO keywords (bug_id, keywordid) VALUES ($id, $i)");
|
|
|
|
$keywordseen{$i} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
$long_description .= "\n" . $comments;
|
|
|
|
if ($err) {
|
|
|
|
$long_description .= "\n$err\n";
|
|
|
|
}
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-06-09 00:30:10 +04:00
|
|
|
SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext) VALUES " .
|
|
|
|
"($id, $exporterid, now(), " . SqlQuote($long_description) . ")");
|
2000-05-16 11:10:45 +04:00
|
|
|
|
2000-07-14 03:12:52 +04:00
|
|
|
$log .= "Bug $urlbase/show_bug.cgi?id=$bug_fields{'bug_id'} ";
|
|
|
|
$log .= "imported as bug $id.\n";
|
|
|
|
$log .= Param("urlbase") . "/show_bug.cgi?id=$id\n\n";
|
2000-06-24 02:56:45 +04:00
|
|
|
if ($err) {
|
2000-07-14 03:12:52 +04:00
|
|
|
$log .= "The following problems were encountered creating bug $id.\n";
|
|
|
|
$log .= "You may have to set certain fields in the new bug by hand.\n\n";
|
2000-06-24 02:56:45 +04:00
|
|
|
$log .= $err;
|
2000-07-14 03:12:52 +04:00
|
|
|
$log .= "\n\n\n";
|
2000-06-24 02:56:45 +04:00
|
|
|
}
|
2000-07-14 03:12:52 +04:00
|
|
|
|
2003-02-10 09:26:39 +03:00
|
|
|
Bugzilla::BugMail::Send($id, { 'changer' => $exporter });
|
2000-06-09 00:30:10 +04:00
|
|
|
}
|
2000-06-23 00:00:14 +04:00
|
|
|
|
2000-06-23 23:41:38 +04:00
|
|
|
my $subject = "$bugqty bug(s) successfully moved from $urlbase to "
|
|
|
|
. Param("urlbase") ;
|
2000-06-23 00:00:14 +04:00
|
|
|
my @to = ($exporter);
|
|
|
|
MailMessage ($subject, $log, @to);
|