]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Control.pm
merge changes from dla source
[debbugs.git] / Debbugs / Control.pm
index 1003e9c1662ece47a05f43e6282ffe63c8cf39c2..aaba6d54c8334325e56dcb59603b31da65cb47a8 100644 (file)
@@ -90,15 +90,22 @@ BEGIN{
 
 use Debbugs::Config qw(:config);
 use Debbugs::Common qw(:lock buglog make_list get_hashname);
-use Debbugs::Status qw(bug_archiveable :read :hook);
+use Debbugs::Status qw(bug_archiveable :read :hook writebug);
 use Debbugs::CGI qw(html_escape);
 use Debbugs::Log qw(:misc);
 
 use Params::Validate qw(validate_with :types);
 use File::Path qw(mkpath);
 use IO::File;
+use IO::Scalar;
 
-# These are a set of options which are common to all of these functions 
+use Debbugs::Text qw(:templates);
+
+use Debbugs::Mail qw(rfc822_date);
+
+use POSIX qw(strftime);
+
+# These are a set of options which are common to all of these functions
 
 my %common_options = (debug       => {type => SCALARREF,
                                      optional => 1,
@@ -161,7 +168,7 @@ This routine archives a bug
 sub bug_archive {
      my %param = validate_with(params => \@_,
                               spec   => {bug => {type   => SCALAR,
-                                                 regex  => qr/^\d+/,
+                                                 regex  => qr/^\d+$/,
                                                 },
                                          check_archiveable => {type => BOOLEAN,
                                                                default => 1,
@@ -173,6 +180,13 @@ sub bug_archive {
                                          %append_action_options,
                                         },
                              );
+     our $locks = 0;
+     local $SIG{__DIE__} = sub {
+         if ($locks) {
+              for (1..$locks) { unfilelock(); }
+              $locks = 0;
+         }
+     };
      my $action = "$config{bug} archived.";
      my ($debug,$transcript) = __handle_debug_transcript(%param);
      if ($param{check_archiveable} and
@@ -183,7 +197,8 @@ sub bug_archive {
          die "Bug $param{bug} cannot be archived";
      }
      print {$debug} "$param{bug} considering\n";
-     my ($locks, $data) = lockreadbugmerge($param{bug});
+     my ($data);
+     ($locks, $data) = lockreadbugmerge($param{bug});
      print {$debug} "$param{bug} read $locks\n";
      defined $data or die "No bug found for $param{bug}";
      print {$debug} "$param{bug} read ok (done $data->{done})\n";
@@ -245,8 +260,8 @@ sub bug_archive {
          }
          unlink(map {"db-h/$dir/$_"} @files_to_remove);
          print {$transcript} "deleted $bug (from $param{bug})\n";
-         bughook_archive($bug);
      }
+     bughook_archive(@bugs);
      if (exists $param{bugs_affected}) {
          @{$param{bugs_affected}}{@bugs} = (1) x @bugs;
      }
@@ -460,27 +475,14 @@ sub __return_append_to_log_options{
      }
      if (not exists $param{message}) {
          $action = $param{action} if exists $param{action};
-         $param{message} = <<END;
-To: $param{request_addr}
-From: $param{requester}
-Subject: Internal Control
-Message-Id: $action
-User-Agent: Fakemail v42.6.9
-
-# A New Hope
-# A log time ago, in a galaxy far, far away
-# something happened.
-#
-# Magically this resulted in the following
-# action being taken, but this fake control
-# message doesn't tell you why it happened
-#
-# The action:
-# $action
-thanks
-# This fakemail brought to you by your local debbugs
-# administrator
-END
+         my $date = rfc822_date();
+         $param{message} = fill_in_template(template  => 'mail/fake_control_message',
+                                            variables => {request_addr => $param{request_addr},
+                                                          requester    => $param{requester},
+                                                          date         => $date,
+                                                          action       => $action
+                                                         },
+                                           );
      }
      return (action => $action,
             %param);