diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-07-08 06:59:55 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-07-08 06:59:55 +0200 |
commit | be1f92450788dc89280c9e04a4bf983b5d7fac54 (patch) | |
tree | b5513fd846597fe5f152177dbbda88dca08fdf5f /scripts | |
parent | 9bbd8d368598046c47964ee043620621b6c3634b (diff) | |
parent | 446a08b30b0dbaac9f2b88e0a5cad410f0446140 (diff) | |
download | bugzilla-be1f92450788dc89280c9e04a4bf983b5d7fac54.tar.gz bugzilla-be1f92450788dc89280c9e04a4bf983b5d7fac54.tar.xz |
Merge remote-tracking branch 'bmo/master'
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/bloomfilter-populate.pl | 6 | ||||
-rwxr-xr-x | scripts/generate_conduit_data.pl | 1 | ||||
-rwxr-xr-x | scripts/nagios_blocker_checker.pl | 4 | ||||
-rwxr-xr-x | scripts/remove-non-public-data.pl | 16 | ||||
-rwxr-xr-x | scripts/sanitizeme.pl | 1 | ||||
-rw-r--r-- | scripts/undo.pl | 203 |
6 files changed, 220 insertions, 11 deletions
diff --git a/scripts/bloomfilter-populate.pl b/scripts/bloomfilter-populate.pl index c591a61b3..780e98bd0 100755 --- a/scripts/bloomfilter-populate.pl +++ b/scripts/bloomfilter-populate.pl @@ -14,8 +14,6 @@ use Bugzilla::Bloomfilter; # set Bugzilla usage mode to USAGE_MODE_CMDLINE Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $name = shift @ARGV or die "usage: $0 \$name < list\n"; -my @lines = <STDIN>; -chomp @lines; -Bugzilla::Bloomfilter->populate($name, \@lines); +my $name = shift @ARGV or die "usage: $0 \$name\n"; +Bugzilla::Bloomfilter->populate($name); diff --git a/scripts/generate_conduit_data.pl b/scripts/generate_conduit_data.pl index 50a7379f4..541afb52a 100755 --- a/scripts/generate_conduit_data.pl +++ b/scripts/generate_conduit_data.pl @@ -133,7 +133,6 @@ set_params( password_check_on_login => 0, phabricator_base_uri => 'http://phabricator.test/', phabricator_enabled => 1, - phabricator_sync_groups => 'core-security', ); set_push_connector_options(); diff --git a/scripts/nagios_blocker_checker.pl b/scripts/nagios_blocker_checker.pl index 8c4277507..01a7b7348 100755 --- a/scripts/nagios_blocker_checker.pl +++ b/scripts/nagios_blocker_checker.pl @@ -12,10 +12,10 @@ use warnings; use lib qw(. lib local/lib/perl5); use Bugzilla; +use Bugzilla::Logging; use Bugzilla::Constants; use Bugzilla::Product; use Bugzilla::User; -use Bugzilla::Sentry; use Getopt::Long; use English qw(-no_match_vars); @@ -141,7 +141,7 @@ try { # nagios check does no good, we terminate if we stick around too long. local $SIG{ALRM} = sub { my $message = "$PROGRAM_NAME ran for longer than $config->{max_runtime} seconds and was auto-terminated."; - sentry_handle_error('error', $message); + FATAL($message); die "$message\n"; }; alarm($config->{max_runtime}); diff --git a/scripts/remove-non-public-data.pl b/scripts/remove-non-public-data.pl index fd379af79..ce7948dd0 100755 --- a/scripts/remove-non-public-data.pl +++ b/scripts/remove-non-public-data.pl @@ -9,8 +9,17 @@ use 5.10.1; use strict; use warnings; -use lib qw(. lib local/lib/perl5); +use File::Basename qw(dirname); +use File::Spec::Functions qw(catfile catdir rel2abs); +use Cwd qw(realpath); +BEGIN { + require lib; + my $dir = rel2abs(catdir(dirname(__FILE__), '..')); + lib->import($dir, catdir($dir, 'lib'), catdir($dir, qw(local lib perl5))); +} + +use autodie; use Bugzilla; use Bugzilla::Constants; use List::MoreUtils qw(any); @@ -130,7 +139,8 @@ my $dbh = Bugzilla->dbh; # run sanitiseme.pl print "running sanitizeme.pl\n"; -system "'$RealBin/sanitizeme.pl' --execute"; +my $sanitizeme = catfile(realpath(dirname(__FILE__)), 'sanitizeme.pl'); +system $sanitizeme, '--execute'; if ($dbh->selectrow_array("SELECT COUNT(*) FROM bug_group_map")) { die "sanitization failed\n"; @@ -164,7 +174,7 @@ foreach my $table (@tables) { else { print "dropping $table\n"; drop_referencing($table); - $dbh->do("DROP TABLE $table"); + $dbh->do("DROP TABLE IF EXISTS $table"); } } diff --git a/scripts/sanitizeme.pl b/scripts/sanitizeme.pl index 48a618d12..31418d047 100755 --- a/scripts/sanitizeme.pl +++ b/scripts/sanitizeme.pl @@ -26,7 +26,6 @@ use strict; use warnings; use lib qw(. lib local/lib/perl5); - use Bugzilla; use Bugzilla::Bug; use Bugzilla::Constants; diff --git a/scripts/undo.pl b/scripts/undo.pl new file mode 100644 index 000000000..24d6f594b --- /dev/null +++ b/scripts/undo.pl @@ -0,0 +1,203 @@ +#!/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 5.10.1; +use strict; +use warnings; + +use File::Basename qw(dirname); +use File::Spec::Functions qw(catfile catdir rel2abs); +use Cwd qw(realpath); +BEGIN { + require lib; + my $dir = rel2abs(catdir(dirname(__FILE__), '..')); + lib->import($dir, catdir($dir, 'lib'), catdir($dir, qw(local lib perl5))); +} + +use Bugzilla; +BEGIN { Bugzilla->extensions }; +use Bugzilla::Extension::UserProfile::Util qw(tag_for_recount_from_bug); + +use Try::Tiny; + +# not involved with kmag +my $query = q{ + resolution = 'INACTIVE' + AND NOT ( + triage_owner.login_name = 'mak77@bonardo.net' + AND bugs.priority IN ('P4', 'P5', '--') + ) + AND NOT ( + product.name = 'Toolkit' AND component.name = 'Add-ons Manager' + ) + AND NOT ( + product.name = 'Toolkit' AND component.name LIKE 'WebExtensions%' + ) + AND NOT ( + product.name = 'Core' AND component.name = 'XPConnect' + ) +}; +undo($query); + +sub undo { + my @args = @_; + my $changes = get_changes(@args); + my $comments = get_comments(@args); + + my %action; + while ($_ = $changes->()) { + push @{ $action{$_->{bug_id}}{$_->{bug_when}}{remove_activities} }, { id => $_->{change_id} }; + $action{ $_->{bug_id} }{ $_->{bug_when} }{change}{ $_->{field_name} } = { + replace => $_->{added}, + with => $_->{removed}, + }; + } + + while ($_ = $comments->()) { + push @{ $action{ $_->{bug_id} }{$_->{bug_when}}{remove_comments} }, { + id => $_->{comment_id}, + }; + } + + my $dbh = Bugzilla->dbh; + my @bug_ids = reverse sort { $a <=> $b } keys %action; + say 'Found ', 0 + @bug_ids, ' bugs'; + foreach my $bug_id (@bug_ids) { + $dbh->bz_start_transaction; + say "Fix $bug_id"; + try { + my ($delta_ts) = $dbh->selectrow_array( + 'SELECT delta_ts FROM bugs WHERE bug_id = ?', + undef, + $bug_id); + my ($previous_last_ts) = $dbh->selectrow_array( + q{ + SELECT MAX(bug_when) FROM ( + SELECT bug_when FROM bugs_activity WHERE bug_id = ? AND bug_when < ? + UNION + SELECT bug_when FROM longdescs WHERE bug_id = ? AND bug_when < ? + UNION + SELECT creation_ts AS bug_when FROM bugs WHERE bug_id = ? + ) as changes ORDER BY bug_when DESC + }, + undef, + $bug_id, $delta_ts, + $bug_id, $delta_ts, + $bug_id, + ); + die 'cannot find previous last updated time' unless $previous_last_ts; + my $action = delete $action{$bug_id}{$delta_ts}; + if (keys %{ $action{$bug_id}{$delta_ts}}) { + die "skipping because more than one change\n"; + } + elsif (!$action) { + die "skipping because most recent change newer than automation change\n"; + } + foreach my $field (keys %{ $action->{change} }) { + my $change = $action->{change}{$field}; + if ($field eq 'cf_last_resolved' && !$change->{with}) { + $change->{with} = undef; + } + my $did = $dbh->do( + "UPDATE bugs SET $field = ? WHERE bug_id = ? AND $field = ?", + undef, $change->{with}, $bug_id, $change->{replace}, + ); + die "Failed to set $field to $change->{with}" unless $did; + } + $dbh->do('UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?', undef, + $previous_last_ts, $previous_last_ts, $bug_id ); + my $del_comments = $dbh->prepare('DELETE FROM longdescs WHERE comment_id = ?'); + my $del_activity = $dbh->prepare('DELETE FROM bugs_activity WHERE id = ?'); + foreach my $comment (@{ $action->{remove_comments}}) { + $del_comments->execute($comment->{id}) or die "failed to delete comment $comment->{id}"; + } + foreach my $activity (@{ $action->{remove_activities}}) { + $del_activity->execute($activity->{id}) or die "failed to delete comment $activity->{id}"; + } + tag_for_recount_from_bug($bug_id); + $dbh->bz_commit_transaction; + sleep 1; + } catch { + chomp $_; + say "Error updating $bug_id: $_"; + $dbh->bz_rollback_transaction; + }; + } + say 'Done.'; +} + +sub get_changes { + my ($where, @bind) = @_; + + my $sql = qq{ + SELECT + BA.id AS change_id, + BA.bug_id, + FD.name AS field_name, + BA.removed, + BA.added, + BA.bug_when + FROM + bugs_activity AS BA + JOIN + fielddefs AS FD ON BA.fieldid = FD.id + JOIN + profiles AS changer ON changer.userid = BA.who + JOIN + (SELECT + bug_id + FROM + bugs + JOIN products AS product ON product.id = product_id + JOIN components AS component ON component.id = component_id + LEFT JOIN profiles AS triage_owner ON triage_owner.userid = component.triage_owner_id + WHERE + $where + ) target_bugs ON BA.bug_id = target_bugs.bug_id + WHERE + changer.login_name = 'automation\@bmo.tld' + AND BA.bug_when BETWEEN '2018-05-22' AND '2018-05-26' + }; + my $sth = Bugzilla->dbh->prepare($sql); + $sth->execute(@bind); + + return sub { $sth->fetchrow_hashref }; +} + +sub get_comments { + my ($where, @bind) = @_; + + my $sql = qq{ + SELECT + C.comment_id AS comment_id, + C.bug_id AS bug_id, + C.bug_when + FROM + longdescs AS C + JOIN + profiles AS commenter ON commenter.userid = C.who + JOIN + (SELECT + bug_id + FROM + bugs + JOIN products AS product ON product.id = product_id + JOIN components AS component ON component.id = component_id + LEFT JOIN profiles AS triage_owner ON triage_owner.userid = component.triage_owner_id + WHERE + $where + ) target_bugs ON C.bug_id = target_bugs.bug_id + WHERE + commenter.login_name = 'automation\@bmo.tld' + AND C.bug_when BETWEEN '2018-05-22' AND '2018-05-26' + }; + my $sth = Bugzilla->dbh->prepare($sql); + $sth->execute(@bind); + + return sub { $sth->fetchrow_hashref }; +} |