2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Netscape Communications
17 # Corporation. Portions created by Netscape are
18 # Copyright (C) 1998 Netscape Communications Corporation. All
21 # Contributor(s): Dawn Endico <endico@mozilla.org>
22 # Terry Weissman <terry@mozilla.org>
23 # Dave Miller <justdave@bugzilla.org>
31 use vars
qw($template $userid);
34 use Bugzilla::Constants;
36 use Bugzilla::Config qw(:DEFAULT $datadir);
37 use Bugzilla::BugMail;
39 my $cgi = Bugzilla->cgi;
41 unless ( Param("move-enabled") ) {
43 PutHeader("Move Bugs");
44 print "\n<P>Sorry. Bug moving is not enabled here. ";
45 print "If you need to move a bug, contact " . Param("maintainer");
50 my $user = Bugzilla->login(LOGIN_REQUIRED);
52 if (!defined $cgi->param('buglist')) {
54 PutHeader("Move Bugs");
55 print "Move bugs either from the bug display page or perform a ";
56 print "<A HREF=\"query.cgi\">query</A> and change several bugs at once.\n";
57 print "If you don't see the move button, then you either aren't ";
58 print "logged in or aren't permitted to.";
63 unless ($user->is_mover) {
65 PutHeader("Move Bugs");
66 print "<P>You do not have permission to move bugs<P>\n";
72 my $exporterid = $user->id;
75 PutHeader("Move Bugs");
77 foreach my $id (split(/:/, scalar($cgi->param('buglist')))) {
78 my $bug = new Bugzilla::Bug($id, $exporterid);
81 my $fieldid = GetFieldID("bug_status");
82 my $cur_status= $bug->bug_status;
83 SendSQL("INSERT INTO bugs_activity " .
84 "(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
85 "($id,$exporterid,now(),$fieldid,'$cur_status','RESOLVED')");
86 $fieldid = GetFieldID("resolution");
87 my $cur_res= $bug->resolution;
88 SendSQL("INSERT INTO bugs_activity " .
89 "(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
90 "($id,$exporterid,now(),$fieldid,'$cur_res','MOVED')");
92 SendSQL("UPDATE bugs SET bug_status =\"RESOLVED\",
93 resolution =\"MOVED\",
95 WHERE bug_id=\"$id\"");
98 if (defined $cgi->param('comment') && $cgi->param('comment') !~ /^\s*$/) {
99 $comment .= $cgi->param('comment') . "\n\n";
101 $comment .= "Bug moved to " . Param("move-to-url") . ".\n\n";
102 $comment .= "If the move succeeded, " . $user->login . " will receive a mail\n";
103 $comment .= "containing the number of the new bug in the other database.\n";
104 $comment .= "If all went well, please mark this bug verified, and paste\n";
105 $comment .= "in a link to the new bug. Otherwise, reopen this bug.\n";
106 SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext) VALUES " .
107 "($id, $exporterid, now(), " . SqlQuote($comment) . ")");
109 print "<P>Bug $id moved to " . Param("move-to-url") . ".<BR>\n";
110 Bugzilla::BugMail::Send($id, { 'changer' => $user->login });
114 my $buglist = $cgi->param('buglist');
116 my $host = Param("urlbase");
117 $host =~ s#http://([^/]+)/.*#$1#;
118 my $to = Param("move-to-address");
120 my $msg = "To: $to\n";
121 my $from = Param("moved-from-address");
123 $msg .= "From: Bugzilla <" . $from . ">\n";
124 $msg .= "Subject: Moving bug(s) $buglist\n\n";
126 my @fieldlist = (Bugzilla::Bug::fields(), 'group', 'long_desc', 'attachment');
128 foreach (@fieldlist) {
129 $displayfields{$_} = 1;
132 $template->process("bug/show.xml.tmpl", { bugs => \@bugs,
133 displayfields => \%displayfields,
135 || ThrowTemplateError($template->error());
139 Bugzilla::BugMail::MessageToMTA($msg);