summaryrefslogtreecommitdiffstats
path: root/extensions/TrackingFlags/bin/bulk_flag_clear.pl
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/TrackingFlags/bin/bulk_flag_clear.pl')
-rwxr-xr-xextensions/TrackingFlags/bin/bulk_flag_clear.pl80
1 files changed, 36 insertions, 44 deletions
diff --git a/extensions/TrackingFlags/bin/bulk_flag_clear.pl b/extensions/TrackingFlags/bin/bulk_flag_clear.pl
index 305fbf883..470269f13 100755
--- a/extensions/TrackingFlags/bin/bulk_flag_clear.pl
+++ b/extensions/TrackingFlags/bin/bulk_flag_clear.pl
@@ -13,8 +13,8 @@ use 5.10.1;
use lib qw(. lib local/lib/perl5);
BEGIN {
- use Bugzilla;
- Bugzilla->extensions;
+ use Bugzilla;
+ Bugzilla->extensions;
}
use Bugzilla::Constants;
@@ -27,21 +27,14 @@ use Getopt::Long;
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
my $config = {};
-GetOptions(
- $config,
- "trace=i",
- "update_db",
- "flag=s",
- "modified_before=s",
- "modified_after=s",
- "value=s"
-) or exit;
+GetOptions($config, "trace=i", "update_db", "flag=s", "modified_before=s",
+ "modified_after=s", "value=s")
+ or exit;
unless ($config->{flag}
- && ($config->{modified_before}
- || $config->{modified_after}
- || $config->{value}))
+ && ($config->{modified_before} || $config->{modified_after} || $config->{value})
+ )
{
- die <<EOF;
+ die <<EOF;
$0
clears tracking flags matching the specified criteria.
the last-modified will be updated, however bugmail will not be generated.
@@ -64,23 +57,24 @@ EOF
my (@where, @values);
-my $flag = Bugzilla::Extension::TrackingFlags::Flag->check({ name => $config->{flag} });
-push @where, 'tracking_flags_bugs.tracking_flag_id = ?';
+my $flag
+ = Bugzilla::Extension::TrackingFlags::Flag->check({name => $config->{flag}});
+push @where, 'tracking_flags_bugs.tracking_flag_id = ?';
push @values, $flag->flag_id;
if ($config->{modified_before}) {
- push @where, 'bugs.delta_ts < ?';
- push @values, $config->{modified_before};
+ push @where, 'bugs.delta_ts < ?';
+ push @values, $config->{modified_before};
}
if ($config->{modified_after}) {
- push @where, 'bugs.delta_ts > ?';
- push @values, $config->{modified_after};
+ push @where, 'bugs.delta_ts > ?';
+ push @values, $config->{modified_after};
}
if ($config->{value}) {
- push @where, 'tracking_flags_bugs.value = ?';
- push @values, $config->{value};
+ push @where, 'tracking_flags_bugs.value = ?';
+ push @values, $config->{value};
}
my $sql = "
@@ -99,37 +93,35 @@ $dbh->{TraceLevel} = $config->{trace} if $config->{trace};
my $bug_ids = $dbh->selectcol_arrayref($sql, undef, @values);
if (!@$bug_ids) {
- die "no matching bugs found\n";
+ die "no matching bugs found\n";
}
if (!$config->{update_db}) {
- print "bugs found: ", scalar(@$bug_ids), "\n\n", join(',', @$bug_ids), "\n\n";
- print "--update_db not provided, no changes made to the database\n";
- exit;
+ print "bugs found: ", scalar(@$bug_ids), "\n\n", join(',', @$bug_ids), "\n\n";
+ print "--update_db not provided, no changes made to the database\n";
+ exit;
}
# update bugs
-my $nobody = Bugzilla::User->check({ name => Bugzilla->params->{'nobody_user'} });
+my $nobody = Bugzilla::User->check({name => Bugzilla->params->{'nobody_user'}});
+
# put our nobody user into all groups to avoid permissions issues
$nobody->{groups} = [Bugzilla::Group->get_all];
Bugzilla->set_user($nobody);
foreach my $bug_id (@$bug_ids) {
- print "updating bug $bug_id\n";
- $dbh->bz_start_transaction;
-
- # update the bug
- # this will deal with history for us but not send bugmail
- my $bug = Bugzilla::Bug->check({ id => $bug_id });
- $bug->set_all({ $flag->name => '---' });
- $bug->update;
-
- # update lastdiffed to skip bugmail for this change
- $dbh->do(
- "UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?",
- undef,
- $bug->id
- );
- $dbh->bz_commit_transaction;
+ print "updating bug $bug_id\n";
+ $dbh->bz_start_transaction;
+
+ # update the bug
+ # this will deal with history for us but not send bugmail
+ my $bug = Bugzilla::Bug->check({id => $bug_id});
+ $bug->set_all({$flag->name => '---'});
+ $bug->update;
+
+ # update lastdiffed to skip bugmail for this change
+ $dbh->do("UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?",
+ undef, $bug->id);
+ $dbh->bz_commit_transaction;
}