diff options
-rw-r--r-- | extensions/TrackingFlags/Extension.pm | 17 | ||||
-rw-r--r-- | extensions/TrackingFlags/bin/bug_825946.pl | 80 |
2 files changed, 97 insertions, 0 deletions
diff --git a/extensions/TrackingFlags/Extension.pm b/extensions/TrackingFlags/Extension.pm index 0c70c54f6..33792dc38 100644 --- a/extensions/TrackingFlags/Extension.pm +++ b/extensions/TrackingFlags/Extension.pm @@ -26,6 +26,7 @@ use Bugzilla::Install::Filesystem; use Bugzilla::Product; use JSON; +use List::MoreUtils qw(none); our $VERSION = '1'; @@ -637,12 +638,28 @@ sub bug_end_of_update { is_active => 1, }); + my $product_id = $bug->product_id; + my $component_id = $bug->component_id; + my $is_visible = sub { + $_->product_id == $product_id && (!$_->component_id || $_->component_id == $component_id); + }; + my (@flag_changes); foreach my $flag (@$tracking_flags) { my $flag_name = $flag->name; my $new_value = $bug->$flag_name; my $old_value = $old_bug->$flag_name; + if ($flag->bug_flag->id) { + my $visibility = $flag->visibility; + if (none { $is_visible->() } @$visibility) { + push(@flag_changes, { flag => $flag, + added => '---', + removed => $new_value }); + next; + } + } + if ($new_value ne $old_value) { # Do not allow if the user cannot set the old value or the new value if (!$flag->can_set_value($new_value)) { diff --git a/extensions/TrackingFlags/bin/bug_825946.pl b/extensions/TrackingFlags/bin/bug_825946.pl new file mode 100644 index 000000000..2531228de --- /dev/null +++ b/extensions/TrackingFlags/bin/bug_825946.pl @@ -0,0 +1,80 @@ +#!/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 qw($RealBin); +use lib "$RealBin/../../.."; + +BEGIN { + use Bugzilla; + Bugzilla->extensions; +} + +use Bugzilla::Constants qw( USAGE_MODE_CMDLINE ); +use Bugzilla::Extension::TrackingFlags::Flag; +use Bugzilla::User; +use Bugzilla::Bug qw(LogActivityEntry); + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); +my $dbh = Bugzilla->dbh; +my $user = Bugzilla::User->check({name => 'nobody@mozilla.org'}); + +my $tf_vis = $dbh->selectall_arrayref(<<SQL); + SELECT + tracking_flag_id, + product_id, + component_id + FROM + tracking_flags_visibility +SQL + +my $tf_bugs = $dbh->selectall_arrayref(<<SQL); + SELECT + tf.name, + tf_bugs.value, + bugs.bug_id, + tf_bugs.tracking_flag_id, + bugs.product_id, + bugs.component_id + FROM + tracking_flags_bugs AS tf_bugs + JOIN bugs USING (bug_id) + JOIN tracking_flags AS tf ON tf.id = tf_bugs.tracking_flag_id +SQL + +my %visible; +foreach my $row (@$tf_vis) { + my ($tracking_flag_id, $product_id, $component_id) = @$row; + $visible{$tracking_flag_id}{$product_id}{$component_id // 'ALL'} = 1; +} + +my %bugs = map { $_->[0] => 1 } @$tf_bugs; +my $bugs = keys %bugs; + +printf "About to check %d tracking flags on %d bugs\n", @$tf_bugs + 0, $bugs; +print "Press <Ctrl-C> to stop or <Enter> to continue...\n"; +getc(); + +my $removed = 0; +$dbh->bz_start_transaction(); +my ($timestamp) = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); +foreach my $tf_bug (@$tf_bugs) { + my ($flag_name, $value, $bug_id, $tf_id, $product_id, $component_id) = @$tf_bug; + unless ($visible{$tf_id}{$product_id}{$component_id} || $visible{$tf_id}{$product_id}{ALL}) { + $dbh->do("DELETE FROM tracking_flags_bugs WHERE tracking_flag_id = ? AND bug_id = ?", + undef, $tf_id, $bug_id); + LogActivityEntry($bug_id, $flag_name, $value, '---', $user->id, $timestamp); + $removed++; + } +} +$dbh->bz_commit_transaction(); + +print "Removed $removed tracking flags\n"; +print "Done.\n"; |