1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
use strict;
use warnings;
use FindBin '$RealBin';
use lib "$RealBin/../..", "$RealBin/../../lib";
use Bugzilla;
use Bugzilla::User;
use Bugzilla::Constants;
use Bugzilla::Util qw(detaint_natural);
use Bugzilla::Install::Util qw(indicate_progress);
use Pod::Usage;
BEGIN { Bugzilla->extensions(); }
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
pod2usage(1) unless @ARGV;
my $dbh = Bugzilla->dbh;
# Allow nobody@mozilla.org to edit bugs
my $user = Bugzilla::User->check({ name => 'nobody@mozilla.org' });
Bugzilla->set_user($user);
$user->{'groups'} = [ Bugzilla::Group->new({ name => 'editbugs' }) ];
my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
foreach my $dupe_of_bug (@ARGV) {
detaint_natural($dupe_of_bug) || pod2usage(1);
my $duped_bugs = $dbh->selectcol_arrayref("
SELECT DISTINCT dupe FROM duplicates WHERE dupe_of = ?",
undef, $dupe_of_bug);
my $bug_count = @$duped_bugs;
die "There are no duplicate bugs to move for bug $dupe_of_bug.\n"
if $bug_count == 0;
print STDERR <<EOF;
Moving $bug_count duplicate bugs from bug $dupe_of_bug to the 'Invalid Bugs' product.
Press <Ctrl-C> to stop or <Enter> to continue...
EOF
getc();
$dbh->bz_start_transaction;
my $count = 0;
foreach my $duped_bug_id (@$duped_bugs) {
# Change product to "Invalid Bugs" and component to "General"
# Change resolution to "INVALID" instead of duplicate
# Change version to "unspecified" and milestone to "---"
# Reset assignee to default
# Reset QA contact to default
my $bug_obj = Bugzilla::Bug->new($duped_bug_id);
my $params = {
product => 'Invalid Bugs',
component => 'General',
resolution => 'INVALID',
version => 'unspecified',
target_milestone => '---',
reset_assigned_to => 1,
reset_qa_contact => 1
};
$params->{bug_status} = 'RESOLVED' if $bug_obj->status->is_open;
$bug_obj->set_all($params);
$bug_obj->update($timestamp);
$dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?",
undef, $timestamp, $timestamp, $duped_bug_id);
$count++;
indicate_progress({ current => $count, total => $bug_count, every => 1 });
}
Bugzilla::Hook::process('reorg_move_bugs', { bug_ids => [ $dupe_of_bug, @$duped_bugs ] });
$dbh->bz_commit_transaction();
}
# It's complex to determine which items now need to be flushed from memcached.
# As this is expected to be a rare event, we just flush the entire cache.
Bugzilla->memcached->clear_all();
__END__
=head1 NAME
move_dupes_to_invalid.pl - Script used to move dupes of a given bug to the 'Invalid Bugs' product.
=head1 SYNOPSIS
move_dupes_to_invalid.pl <bug_id> [<bug_id> ...]
|