]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 303401: move the move.pl code into process_bug.cgi - Patch by Frédéric Buclin...
authorlpsolit%gmail.com <>
Mon, 22 Aug 2005 00:36:50 +0000 (00:36 +0000)
committerlpsolit%gmail.com <>
Mon, 22 Aug 2005 00:36:50 +0000 (00:36 +0000)
move.pl [deleted file]
process_bug.cgi
template/en/default/bug/process/results.html.tmpl
template/en/default/global/user-error.html.tmpl

diff --git a/move.pl b/move.pl
deleted file mode 100755 (executable)
index 82c4003..0000000
--- a/move.pl
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/usr/bin/perl -wT
-# -*- 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>
-#                 Terry Weissman <terry@mozilla.org>
-#                 Dave Miller    <justdave@bugzilla.org>
-
-use strict;
-
-use lib qw(.);
-
-require "globals.pl";
-
-use vars qw($template $userid);
-
-use Bugzilla;
-use Bugzilla::Constants;
-use Bugzilla::Bug;
-use Bugzilla::Config qw(:DEFAULT $datadir);
-use Bugzilla::BugMail;
-
-unless ( Param("move-enabled") ) {
-  print "\n<P>Sorry. Bug moving is not enabled here. ";
-  print "If you need to move a bug, contact " . Param("maintainer");
-  exit;
-}
-
-Bugzilla->login(LOGIN_REQUIRED);
-
-my $cgi = Bugzilla->cgi;
-
-if (!defined $cgi->param('buglist')) {
-  print $cgi->header();
-  $template->put_header("Move Bugs");
-  print "Move bugs either from the bug display page or perform a ";
-  print "<A HREF=\"query.cgi\">query</A> and change several bugs at once.\n";
-  print "If you don't see the move button, then you either aren't ";
-  print "logged in or aren't permitted to.";
-  $template->put_footer();
-  exit;
-}
-
-my $exporter = Bugzilla->user->login;
-my $movers = Param("movers");
-$movers =~ s/\s?,\s?/|/g;
-$movers =~ s/@/\@/g;
-unless ($exporter =~ /($movers)/) {
-  print $cgi->header();
-  $template->put_header("Move Bugs");
-  print "<P>You do not have permission to move bugs<P>\n";
-  $template->put_footer();
-  exit;
-}
-
-my @bugs;
-
-print "<P>\n";
-foreach my $id (split(/:/, scalar($cgi->param('buglist')))) {
-  my $bug = new Bugzilla::Bug($id, $::userid);
-  push @bugs, $bug;
-  if (!$bug->error) {
-    my $exporterid = DBNameToIdAndCheck($exporter);
-
-    my $fieldid = GetFieldID("bug_status");
-    my $cur_status= $bug->bug_status;
-    SendSQL("INSERT INTO bugs_activity " .
-            "(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
-            "($id,$exporterid,now(),$fieldid,'$cur_status','RESOLVED')");
-    $fieldid = GetFieldID("resolution");
-    my $cur_res= $bug->resolution;
-    SendSQL("INSERT INTO bugs_activity " .
-            "(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
-            "($id,$exporterid,now(),$fieldid,'$cur_res','MOVED')");
-
-    SendSQL("UPDATE bugs SET bug_status =\"RESOLVED\",
-                             resolution =\"MOVED\",
-                             delta_ts = NOW()
-              WHERE bug_id=\"$id\"");
-
-    my $comment = "";
-    if (defined $cgi->param('comment') && $cgi->param('comment') !~ /^\s*$/) {
-        $comment .= $cgi->param('comment') . "\n\n";
-    }
-    $comment .= "Bug moved to " . Param("move-to-url") . ".\n\n";
-    $comment .= "If the move succeeded, $exporter will receive a mail\n";
-    $comment .= "containing the number of the new bug in the other database.\n";
-    $comment .= "If all went well,  please mark this bug verified, and paste\n";
-    $comment .= "in a link to the new bug. Otherwise, reopen this bug.\n";
-    SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext) VALUES " .
-        "($id,  $exporterid, now(), " . SqlQuote($comment) . ")");
-
-    print "<P>Bug $id moved to " . Param("move-to-url") . ".<BR>\n";
-    Bugzilla::BugMail::Send($id, { 'changer' => $exporter });
-  }
-}
-print "<P>\n";
-
-my $buglist = $cgi->param('buglist');
-$buglist =~ s/:/,/g;
-my $host = Param("urlbase");
-$host =~ s#http://([^/]+)/.*#$1#;
-my $to = Param("move-to-address");
-$to =~ s/@/\@/;
-my $msg = "To: $to\n";
-my $from = Param("moved-from-address");
-$from =~ s/@/\@/;
-$msg .= "From: Bugzilla <" . $from . ">\n";
-$msg .= "Subject: Moving bug(s) $buglist\n\n";
-
-my @fieldlist = (Bugzilla::Bug::fields(), 'group', 'long_desc', 'attachment');
-my %displayfields;
-foreach (@fieldlist) {
-    $displayfields{$_} = 1;
-}
-
-$template->process("bug/show.xml.tmpl", { bugs => \@bugs,
-                                          displayfields => \%displayfields,
-                                        }, \$msg)
-  || ThrowTemplateError($template->error());
-
-$msg .= "\n";
-
-Bugzilla::BugMail::MessageToMTA($msg);
index 157a73a2c0a5dff7a0b2a6f218ab874c34f1b9f5..b60f5aa6061d0ee989d064bb8629e6fea15a49bf 100755 (executable)
@@ -50,6 +50,7 @@ require "globals.pl";
 use Bugzilla;
 use Bugzilla::Constants;
 use Bugzilla::Bug;
+use Bugzilla::BugMail;
 use Bugzilla::User;
 use Bugzilla::Util;
 use Bugzilla::Field;
@@ -586,15 +587,110 @@ if (defined $cgi->param('id')) {
     }
 }
 
-my $action = '';
-if (defined $cgi->param('action')) {
-  $action = trim($cgi->param('action'));
-}
-if (Param("move-enabled") && $action eq Param("move-button-text")) {
-  $cgi->param('buglist', join (":", @idlist));
-  do "move.pl" || die "Error executing move.cgi: $!";
-  $template->put_footer();
-  exit;
+my $action = trim($cgi->param('action') || '');
+
+if ($action eq Param('move-button-text')) {
+    Param('move-enabled') || ThrowUserError("move_bugs_disabled");
+
+    my $exporter = $user->login;
+    my $movers = Param('movers');
+    $movers =~ s/\s?,\s?/|/g;
+    $movers =~ s/@/\@/g;
+    if ($exporter !~ /($movers)/) {
+        ThrowUserError("auth_failure", {action => 'move',
+                                        object => 'bugs'});
+    }
+
+    # Moved bugs are marked as RESOLVED MOVED.
+    my $sth = $dbh->prepare("UPDATE bugs
+                                SET bug_status = 'RESOLVED',
+                                    resolution = 'MOVED',
+                                    delta_ts = ?
+                              WHERE bug_id = ?");
+    # Bugs cannot be a dupe and moved at the same time.
+    my $sth2 = $dbh->prepare("DELETE FROM duplicates WHERE dupe = ?");
+
+    my $comment = "";
+    if (defined $cgi->param('comment') && $cgi->param('comment') !~ /^\s*$/) {
+        $comment = $cgi->param('comment') . "\n\n";
+    }
+    $comment .= "Bug moved to " . Param('move-to-url') . ".\n\n";
+    $comment .= "If the move succeeded, $exporter will receive a mail\n";
+    $comment .= "containing the number of the new bug in the other database.\n";
+    $comment .= "If all went well,  please mark this bug verified, and paste\n";
+    $comment .= "in a link to the new bug. Otherwise, reopen this bug.\n";
+
+    # $user->derive_groups() has already been called by Bugzilla->login(),
+    # so the related tables do not need to be locked.
+    $dbh->bz_lock_tables('bugs WRITE', 'bugs_activity WRITE', 'duplicates WRITE',
+                         'longdescs WRITE', 'profiles READ', 'groups READ',
+                         'bug_group_map READ', 'group_group_map READ',
+                         'user_group_map READ', 'classifications READ',
+                         'products READ', 'components READ', 'votes READ',
+                         'cc READ', 'fielddefs READ');
+
+    my $timestamp = $dbh->selectrow_array("SELECT NOW()");
+    my @bugs;
+    # First update all moved bugs.
+    foreach my $id (@idlist) {
+        my $bug = new Bugzilla::Bug($id, $whoid);
+        push(@bugs, $bug);
+
+        $sth->execute($timestamp, $id);
+        $sth2->execute($id);
+
+        AppendComment($id, $whoid, $comment, 0, $timestamp);
+
+        if ($bug->bug_status ne 'RESOLVED') {
+            LogActivityEntry($id, 'bug_status', $bug->bug_status,
+                             'RESOLVED', $whoid, $timestamp);
+        }
+        if ($bug->resolution ne 'MOVED') {
+            LogActivityEntry($id, 'resolution', $bug->resolution,
+                             'MOVED', $whoid, $timestamp);
+        }
+    }
+    $dbh->bz_unlock_tables();
+
+    # Now send emails.
+    foreach my $id (@idlist) {
+        $vars->{'mailrecipients'} = { 'changer' => $exporter };
+        $vars->{'id'} = $id;
+        $vars->{'type'} = "move";
+
+        $template->process("bug/process/results.html.tmpl", $vars)
+          || ThrowTemplateError($template->error());
+        $vars->{'header_done'} = 1;
+    }
+    # Prepare and send all data about these bugs to the new database
+    my $to = Param('move-to-address');
+    $to =~ s/@/\@/;
+    my $from = Param('moved-from-address');
+    $from =~ s/@/\@/;
+    my $msg = "To: $to\n";
+    $msg .= "From: Bugzilla <" . $from . ">\n";
+    $msg .= "Subject: Moving bug(s) " . join(', ', @idlist) . "\n\n";
+
+    my @fieldlist = (Bugzilla::Bug::fields(), 'group', 'long_desc', 'attachment');
+    my %displayfields;
+    foreach (@fieldlist) {
+        $displayfields{$_} = 1;
+    }
+
+    $template->process("bug/show.xml.tmpl", { bugs => \@bugs,
+                                              displayfields => \%displayfields,
+                                            }, \$msg)
+      || ThrowTemplateError($template->error());
+
+    $msg .= "\n";
+    Bugzilla::BugMail::MessageToMTA($msg);
+
+    # End the response page.
+    $template->process("bug/navigate.html.tmpl", $vars)
+      || ThrowTemplateError($template->error());
+    $template->process("global/footer.html.tmpl", $vars)
+      || ThrowTemplateError($template->error());
+    exit;
 }
 
 
index 711776419abdf71c431b3efa464d7395d8fb57c4..a21858792930830bca4d24e212877932ae4858b7 100644 (file)
@@ -44,6 +44,7 @@
     'dep' => "Checking for dependency changes on $terms.bug $id" ,
     'votes' => "$terms.Bug $id confirmed by number of votes" ,
     'created' => "$terms.Bug $id has been added to the database" ,
+    'move' => "$terms.Bug $id has been moved to another database" ,
   }
 
   linktext = {
@@ -52,6 +53,7 @@
     'dep' => "Go To $terms.Bug $id" ,
     'votes' => "Go To $terms.Bug $id" ,
     'created' => "Go To $terms.Bug $id" ,
+    'move' => "Back To $terms.Bug $id" ,
   }
 %]
 
index 6c449bd6949b35e1e91ffd70cb457189f9fe84ed..d86befd5db6dbf3afdf6381ebc1d76e6062f9894 100644 (file)
       delete
     [% ELSIF action == "edit" %]
       add, modify or delete
+    [% ELSIF action == "move" %]
+      move
     [% ELSIF action == "run" %]
       run
     [% ELSIF action == "schedule" %]
 
     [% IF object == "attachment" %]
       this attachment
+    [% ELSIF object == "bugs" %]
+      [%+ terms.bugs %]
     [% ELSIF object == "charts" %]
       the "New Charts" feature
     [% ELSIF object == "classifications" %]
     [% title = "Missing Search" %]
     The search named <em>[% queryname FILTER html %]</em> does not
     exist.
-        
+
+  [% ELSIF error == "move_bugs_disabled" %]
+    [% title = BLOCK %][% terms.Bug %] Moving Disabled[% END %]
+    Sorry, [% terms.bug %] moving has been disabled. If you need
+    to move [% terms.abug %], please contact [% Param("maintainer") %].
+
   [% ELSIF error == "must_be_patch" %]
     [% title = "Attachment Must Be Patch" %]
     Attachment #[% attach_id FILTER html %] must be a patch.