is true, the above options must be present, and their values are used.
-=head1 FUNCTIONS
+=head1 GENERAL FUNCTIONS
=cut
use Debbugs::Status qw(bug_archiveable :read :hook writebug);
use Debbugs::CGI qw(html_escape);
use Debbugs::Log qw(:misc);
+use Debbugs::Recipients qw(:add);
use Params::Validate qw(validate_with :types);
use File::Path qw(mkpath);
optional => 1,
},
recipients => {type => HASHREF,
- optional => 1,
+ default => {},
+ },
+ limit => {type => HASHREF,
+ default => {},
},
);
);
+# this is just a generic stub for Debbugs::Control functions.
+# sub foo {
+# my %param = validate_with(params => \@_,
+# spec => {bug => {type => SCALAR,
+# regex => qr/^\d+$/,
+# },
+# # specific options here
+# %common_options,
+# %append_action_options,
+# },
+# );
+# our $locks = 0;
+# $locks = 0;
+# local $SIG{__DIE__} = sub {
+# if ($locks) {
+# for (1..$locks) { unfilelock(); }
+# $locks = 0;
+# }
+# };
+# my ($debug,$transcript) = __handle_debug_transcript(%param);
+# my (@data);
+# ($locks, @data) = lock_read_all_merged_bugs($param{bug});
+# add_recipients(data => \@data,
+# recipients => $param{recipients}
+# );
+# }
+
+=head1 OWNER FUNCTIONS
+
+=head2 owner
+
+ eval {
+ owner(bug => $ref,
+ transcript => $transcript,
+ ($dl > 0 ? (debug => $transcript):()),
+ requester => $header{from},
+ request_addr => $controlrequestaddr,
+ message => \@log,
+ recipients => \%recipients,
+ owner => undef,
+ );
+ };
+ if ($@) {
+ $errors++;
+ print {$transcript} "Failed to mark $ref as not having an owner: $@";
+ }
+
+Handles all setting of the owner field; given an owner of undef or of
+no length, indicates that a bug is not owned by anyone.
+
+=cut
+
+sub owner {
+ my %param = validate_with(params => \@_,
+ spec => {bug => {type => SCALAR,
+ regex => qr/^\d+$/,
+ },
+ owner => {type => SCALAR|UNDEF,
+ },
+ %common_options,
+ %append_action_options,
+ },
+ );
+ our $locks = 0;
+ $locks = 0;
+ local $SIG{__DIE__} = sub {
+ if ($locks) {
+ for (1..$locks) { unfilelock(); }
+ $locks = 0;
+ }
+ };
+ my ($debug,$transcript) = __handle_debug_transcript(%param);
+ my (@data);
+ ($locks, @data) = lock_read_all_merged_bugs($param{bug});
+ @data and defined $data[0] or die "No bug found for $param{bug}";
+ add_recipients(data => \@data,
+ recipients => $param{recipients}
+ );
+ my $action = '';
+ for my $data (@data) {
+ if (not defined $param{owner} or not length $param{owner}) {
+ $param{owner} = '';
+ $action = "Removed annotation that $gBug was owned by " .
+ "$data->{owner}.";
+ }
+ else {
+ if (length $data->{owner}) {
+ $action = "Owner changed from $data->{owner} to $param{owner}.";
+ }
+ else {
+ $action = "Owner recorded as $param{owner}."
+ }
+ }
+ $data->{owner} = $param{owner};
+ append_action_to_log(bug => $data->{bug_num},
+ get_lock => 0,
+ __return_append_to_log_options(
+ %param,
+ action => $action,
+ ),
+ )
+ if not exists $param{append_log} or $param{append_log};
+ }
+ if ($locks) {
+ for (1..$locks) { unfilelock(); }
+ }
+}
+
+
+=head1 ARCHIVE FUNCTIONS
+
+
=head2 bug_archive
my $error = '';
},
);
our $locks = 0;
+ $locks = 0;
local $SIG{__DIE__} = sub {
if ($locks) {
for (1..$locks) { unfilelock(); }
die "Bug $param{bug} cannot be archived";
}
print {$debug} "$param{bug} considering\n";
- my ($data);
- ($locks, $data) = lockreadbugmerge($param{bug});
+ my (@data);
+ ($locks, @data) = lock_read_all_merged_bugs($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";
+ @data and defined $data[0] or die "No bug found for $param{bug}";
print {$debug} "$param{bug} read done\n";
if (not $param{archive_unarchived} and
- not exists $data->{unarchived}
+ not exists $data[0]{unarchived}
) {
print {$transcript} "$param{bug} has not been archived previously\n";
die "$param{bug} has not been archived previously";
}
-
- my @bugs = ($param{bug});
- # my %bugs;
- # @bugs{@bugs} = (1) x @bugs;
- if (length($data->{mergedwith})) {
- push(@bugs,split / /,$data->{mergedwith});
- }
+ add_recipients(recipients => $param{recipients},
+ data => \@data,
+ );
+ my @bugs = map {$_->{bug_num}} @data;
print {$debug} "$param{bug} bugs ".join(' ',@bugs)."\n";
for my $bug (@bugs) {
- my $newdata;
- print {$debug} "$param{bug} $bug check\n";
- if ($bug != $param{bug}) {
- print {$debug} "$param{bug} $bug reading\n";
- $newdata = lockreadbug($bug) || die "huh $bug ?";
- print {$debug} "$param{bug} $bug read ok\n";
- $locks++;
- } else {
- $newdata = $data;
- }
- print {$debug} "$param{bug} $bug read/not\n";
- my $expectmerge= join(' ',grep($_ != $bug, sort { $a <=> $b } @bugs));
- $newdata->{mergedwith} eq $expectmerge ||
- die "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (".join(' ',@bugs).")";
- print {$debug} "$param{bug} $bug merge-ok\n";
- if ($param{check_archiveable}) {
- die "Bug $bug cannot be archived (but $param{bug} can?)"
- unless bug_archiveable(bug=>$bug,
- ignore_time => $param{ignore_time},
- );
- }
+ if ($param{check_archiveable}) {
+ die "Bug $bug cannot be archived (but $param{bug} can?)"
+ unless bug_archiveable(bug=>$bug,
+ ignore_time => $param{ignore_time},
+ );
+ }
}
# If we get here, we can archive/remove this bug
print {$debug} "$param{bug} removing\n";
%append_action_options,
},
);
+ our $locks = 0;
+ local $SIG{__DIE__} = sub {
+ if ($locks) {
+ for (1..$locks) { unfilelock(); }
+ $locks = 0;
+ }
+ };
my $action = "$config{bug} unarchived.";
my ($debug,$transcript) = __handle_debug_transcript(%param);
print {$debug} "$param{bug} considering\n";
- my ($locks, $data) = lockreadbugmerge($param{bug},'archive');
+ my @data = ();
+ ($locks, @data) = lock_read_all_merged_bugs($param{bug},'archive');
print {$debug} "$param{bug} read $locks\n";
- if (not defined $data) {
- print {$transcript} "No bug found for $param{bug}\n";
- die "No bug found for $param{bug}";
+ if (not @data or not defined $data[0]) {
+ print {$transcript} "No bug found for $param{bug}\n";
+ die "No bug found for $param{bug}";
}
- print {$debug} "$param{bug} read ok (done $data->{done})\n";
print {$debug} "$param{bug} read done\n";
- my @bugs = ($param{bug});
- # my %bugs;
- # @bugs{@bugs} = (1) x @bugs;
- if (length($data->{mergedwith})) {
- push(@bugs,split / /,$data->{mergedwith});
- }
+ my @bugs = map {$_->{bug_num}} @data;
print {$debug} "$param{bug} bugs ".join(' ',@bugs)."\n";
- for my $bug (@bugs) {
- my $newdata;
- print {$debug} "$param{bug} $bug check\n";
- if ($bug != $param{bug}) {
- print {$debug} "$param{bug} $bug reading\n";
- $newdata = lockreadbug($bug,'archive') or die "huh $bug ?";
- print {$debug} "$param{bug} $bug read ok\n";
- $locks++;
- } else {
- $newdata = $data;
- }
- print {$debug} "$param{bug} $bug read/not\n";
- my $expectmerge= join(' ',grep($_ != $bug, sort { $a <=> $b } @bugs));
- if ($newdata->{mergedwith} ne $expectmerge ) {
- print {$transcript} "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (@bugs)";
- die "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (@bugs)";
- }
- print {$debug} "$param{bug} $bug merge-ok\n";
- }
- # If we get here, we can archive/remove this bug
- print {$debug} "$param{bug} removing\n";
+ print {$debug} "$param{bug} unarchiving\n";
my @files_to_remove;
for my $bug (@bugs) {
print {$debug} "$param{bug} removing $bug\n";
)
if not exists $param{append_log} or $param{append_log};
writebug($bug,$newdata);
+ add_recipients(recipients => $param{recipients},
+ data => $newdata,
+ );
}
print {$debug} "$param{bug} unlocking $locks\n";
if ($locks) {