diff options
author | Perl Tidy <perltidy@bugzilla.org> | 2018-12-05 21:38:52 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-12-05 23:49:08 +0100 |
commit | 8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch) | |
tree | 9d270f173330ca19700e0ba9f2ee931300646de1 /scripts | |
parent | a7bb5a65b71644d9efce5fed783ed545b9336548 (diff) | |
download | bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz |
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'scripts')
57 files changed, 3453 insertions, 3248 deletions
diff --git a/scripts/1298978.pl b/scripts/1298978.pl index 9320e080e..6b3fef2fa 100755 --- a/scripts/1298978.pl +++ b/scripts/1298978.pl @@ -19,31 +19,27 @@ use Bugzilla::Group; use Bugzilla::Search; use constant QUERY => { - 'keywords' => 'intermittent-failure', - 'keywords_type' => 'allwords', - 'priority' => '--', - 'product' => [ - 'Core', - 'Firefox', - 'Firefox for Android', - 'Firefox for iOS', - 'Toolkit', - ], - 'resolution' => '---', - 'short_desc' => '^intermittent', - 'short_desc_type' => 'regexp', + 'keywords' => 'intermittent-failure', + 'keywords_type' => 'allwords', + 'priority' => '--', + 'product' => + ['Core', 'Firefox', 'Firefox for Android', 'Firefox for iOS', 'Toolkit',], + 'resolution' => '---', + 'short_desc' => '^intermittent', + 'short_desc_type' => 'regexp', }; -use constant COMMENT => "Bulk assigning P3 to all open intermittent bugs without a priority set in Firefox components per bug 1298978."; +use constant COMMENT => + "Bulk assigning P3 to all open intermittent bugs without a priority set in Firefox components per bug 1298978."; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $dbh = Bugzilla->dbh; # Make all changes as the automation user -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); -$auto_user->{groups} = [ Bugzilla::Group->get_all ]; -$auto_user->{bless_groups} = [ Bugzilla::Group->get_all ]; +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); +$auto_user->{groups} = [Bugzilla::Group->get_all]; +$auto_user->{bless_groups} = [Bugzilla::Group->get_all]; Bugzilla->set_user($auto_user); my $search = new Bugzilla::Search(fields => ['bug_id'], params => QUERY); @@ -51,8 +47,8 @@ my ($data) = $search->data; my $bug_count = @$data; if ($bug_count == 0) { - warn "There are no bugs to update.\n"; - exit 1; + warn "There are no bugs to update.\n"; + exit 1; } print STDERR <<EOF; @@ -66,14 +62,14 @@ my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); $dbh->bz_start_transaction; foreach my $row (@$data) { - my $bug_id = shift @$row; - warn "Updating bug $bug_id\n"; - my $bug = Bugzilla::Bug->new($bug_id); - $bug->set_priority('P3'); - $bug->add_comment(COMMENT); - $bug->update($timestamp); - $dbh->do("UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $bug_id); + my $bug_id = shift @$row; + warn "Updating bug $bug_id\n"; + my $bug = Bugzilla::Bug->new($bug_id); + $bug->set_priority('P3'); + $bug->add_comment(COMMENT); + $bug->update($timestamp); + $dbh->do("UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $bug_id); } $dbh->bz_commit_transaction; diff --git a/scripts/addcustomfield.pl b/scripts/addcustomfield.pl index b5ee0cd43..ff707b01c 100755 --- a/scripts/addcustomfield.pl +++ b/scripts/addcustomfield.pl @@ -29,21 +29,22 @@ use Bugzilla::Field; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my %types = ( - 'freetext' => FIELD_TYPE_FREETEXT, + 'freetext' => FIELD_TYPE_FREETEXT, 'single_select' => FIELD_TYPE_SINGLE_SELECT, - 'multi_select' => FIELD_TYPE_MULTI_SELECT, - 'textarea' => FIELD_TYPE_TEXTAREA, - 'datetime' => FIELD_TYPE_DATETIME, - 'date' => FIELD_TYPE_DATE, - 'bug_id' => FIELD_TYPE_BUG_ID, - 'bug_urls' => FIELD_TYPE_BUG_URLS, - 'keywords' => FIELD_TYPE_KEYWORDS, + 'multi_select' => FIELD_TYPE_MULTI_SELECT, + 'textarea' => FIELD_TYPE_TEXTAREA, + 'datetime' => FIELD_TYPE_DATETIME, + 'date' => FIELD_TYPE_DATE, + 'bug_id' => FIELD_TYPE_BUG_ID, + 'bug_urls' => FIELD_TYPE_BUG_URLS, + 'keywords' => FIELD_TYPE_KEYWORDS, ); -my $syntax = - "syntax: addcustomfield.pl <field name> [field type]\n\n" . - "valid field types:\n " . join("\n ", sort keys %types) . "\n\n" . - "the default field type is single_select\n"; +my $syntax + = "syntax: addcustomfield.pl <field name> [field type]\n\n" + . "valid field types:\n " + . join("\n ", sort keys %types) . "\n\n" + . "the default field type is single_select\n"; my $name = shift || die $syntax; my $type = lc(shift || 'single_select'); @@ -51,16 +52,17 @@ exists $types{$type} || die "Invalid field type '$type'.\n\n$syntax"; $type = $types{$type}; Bugzilla::Field->create({ - name => $name, - description => 'Please give me a description!', - type => $type, - mailhead => 0, - enter_bug => 0, - obsolete => 1, - custom => 1, - buglist => 1, + name => $name, + description => 'Please give me a description!', + type => $type, + mailhead => 0, + enter_bug => 0, + obsolete => 1, + custom => 1, + buglist => 1, }); print "Done!\n"; my $urlbase = Bugzilla->localconfig->{urlbase}; -print "Please visit ${urlbase}editfields.cgi?action=edit&name=$name to finish setting up this field.\n"; +print + "Please visit ${urlbase}editfields.cgi?action=edit&name=$name to finish setting up this field.\n"; diff --git a/scripts/attachment-data.pl b/scripts/attachment-data.pl index 4a3a1b414..3599ace91 100755 --- a/scripts/attachment-data.pl +++ b/scripts/attachment-data.pl @@ -13,9 +13,13 @@ use File::Basename; use File::Spec; BEGIN { - require lib; - my $dir = File::Spec->rel2abs( File::Spec->catdir( dirname(__FILE__), '..' ) ); - lib->import( $dir, File::Spec->catdir( $dir, 'lib' ), File::Spec->catdir( $dir, qw(local lib perl5) ) ); + require lib; + my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..')); + lib->import( + $dir, + File::Spec->catdir($dir, 'lib'), + File::Spec->catdir($dir, qw(local lib perl5)) + ); } use Bugzilla; @@ -31,85 +35,84 @@ BEGIN { Bugzilla->extensions } Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($help, $file); -GetOptions( - 'help|h' => \$help, - 'file|f=s' => \$file, -); +GetOptions('help|h' => \$help, 'file|f=s' => \$file,); pod2usage(1) if $help || !$file; my $archive = Bugzilla::Attachment::Archive->new(file => $file); my $cmd = shift @ARGV; if ($cmd eq 'export') { - while ( my $attach_id = <ARGV> ) { - chomp $attach_id; - my $attachment = Bugzilla::Attachment->new($attach_id); - unless ($attachment) { - warn "No attachment: $attach_id\n"; - next; - } - warn "writing $attach_id\n"; - $archive->write_attachment($attachment); + while (my $attach_id = <ARGV>) { + chomp $attach_id; + my $attachment = Bugzilla::Attachment->new($attach_id); + unless ($attachment) { + warn "No attachment: $attach_id\n"; + next; } - $archive->write_checksum; + warn "writing $attach_id\n"; + $archive->write_attachment($attachment); + } + $archive->write_checksum; } elsif ($cmd eq 'import') { - while ( my $mem = $archive->read_member ) { - warn "read $mem->{attach_id}\n"; + while (my $mem = $archive->read_member) { + warn "read $mem->{attach_id}\n"; - my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); - next unless $mem->{data_len}; - next unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); + my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); + next unless $mem->{data_len}; + next unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); - Bugzilla::Attachment::current_storage()->store( $attachment->id, $mem->{data} ); - } + Bugzilla::Attachment::current_storage()->store($attachment->id, $mem->{data}); + } } elsif ($cmd eq 'check') { - while ( my $mem = $archive->read_member() ) { - warn "checking $mem->{attach_id}\n"; - my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); - next unless $mem->{data_len}; - die "bad attachment\n" unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); - } + while (my $mem = $archive->read_member()) { + warn "checking $mem->{attach_id}\n"; + my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); + next unless $mem->{data_len}; + die "bad attachment\n" + unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); + } } elsif ($cmd eq 'remove') { - my %remove_ok; - while ( my $mem = $archive->read_member ) { - warn "checking $mem->{attach_id}\n"; - - my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); - die "bad attachment\n" unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); - $remove_ok{$mem->{attach_id}} = 1; + my %remove_ok; + while (my $mem = $archive->read_member) { + warn "checking $mem->{attach_id}\n"; + + my $attachment = Bugzilla::Attachment->new($mem->{attach_id}); + die "bad attachment\n" + unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len}); + $remove_ok{$mem->{attach_id}} = 1; + } + while (my $attach_id = <ARGV>) { + chomp $attach_id; + if ($remove_ok{$attach_id}) { + warn "removing $attach_id\n"; + Bugzilla::Attachment::current_storage()->remove($attach_id); } - while ( my $attach_id = <ARGV> ) { - chomp $attach_id; - if ($remove_ok{$attach_id}) { - warn "removing $attach_id\n"; - Bugzilla::Attachment::current_storage()->remove( $attach_id ); - } - else { - warn "Unable to remove $attach_id, as it did not occur in the archive.\n"; - } + else { + warn "Unable to remove $attach_id, as it did not occur in the archive.\n"; } + } } sub check_attachment { - my ($attachment, $bug_id, $data_len) = @_; - - unless ($attachment) { - warn "No attachment found. Skipping record.\n"; - return 0; - } - unless ( $attachment->bug_id == $bug_id ) { - warn 'Wrong bug id (should be ' . $attachment->bug_id . ")\n"; - return 0; - } - unless ( $attachment->datasize == $data_len ) { - warn 'Wrong size (should be ' . $attachment->datasize . ")\n"; - return 0; - } - - return 1; + my ($attachment, $bug_id, $data_len) = @_; + + unless ($attachment) { + warn "No attachment found. Skipping record.\n"; + return 0; + } + unless ($attachment->bug_id == $bug_id) { + warn 'Wrong bug id (should be ' . $attachment->bug_id . ")\n"; + return 0; + } + unless ($attachment->datasize == $data_len) { + warn 'Wrong size (should be ' . $attachment->datasize . ")\n"; + return 0; + } + + return 1; } diff --git a/scripts/block-ip.pl b/scripts/block-ip.pl index 3fa66d336..bfbf88fd7 100755 --- a/scripts/block-ip.pl +++ b/scripts/block-ip.pl @@ -26,9 +26,10 @@ pod2usage("No IPs given") unless @ARGV; my $app = Bugzilla::Quantum->new; if ($unblock) { - $app->unblock_ip($_) for @ARGV; -} else { - $app->block_ip($_) for @ARGV; + $app->unblock_ip($_) for @ARGV; +} +else { + $app->block_ip($_) for @ARGV; } =head1 NAME diff --git a/scripts/build-bmo-push-data.pl b/scripts/build-bmo-push-data.pl index e3cefe533..dcce29652 100755 --- a/scripts/build-bmo-push-data.pl +++ b/scripts/build-bmo-push-data.pl @@ -8,10 +8,10 @@ use File::Spec::Functions qw(catdir rel2abs); use Cwd qw(realpath); BEGIN { - require lib; - my $dir = realpath( catdir(dirname(__FILE__), '..') ); - lib->import( $dir, catdir( $dir, 'lib' ), catdir( $dir, qw(local lib perl5) ) ); - chdir $dir or die "chdir $dir failed: $!"; + require lib; + my $dir = realpath(catdir(dirname(__FILE__), '..')); + lib->import($dir, catdir($dir, 'lib'), catdir($dir, qw(local lib perl5))); + chdir $dir or die "chdir $dir failed: $!"; } use autodie; @@ -37,53 +37,51 @@ chomp @log; my @revisions; foreach my $line (@log) { - say $line; - my ($revision, $message); - unless ( ( $revision, $message ) = $line =~ /^(\S+) (.+)$/ ) { - warn "skipping $line\n"; - next; + say $line; + my ($revision, $message); + unless (($revision, $message) = $line =~ /^(\S+) (.+)$/) { + warn "skipping $line\n"; + next; + } + + my @bug_ids; + if ($message =~ /\bBug (\d+)/i) { + push @bug_ids, $1; + } + + if (!@bug_ids) { + warn "skipping $line (no bug)\n"; + next; + } + + foreach my $bug_id (@bug_ids) { + my $duplicate = 0; + foreach my $revisions (@revisions) { + if ($revisions->{bug_id} == $bug_id) { + $duplicate = 1; + last; + } } + next if $duplicate; - my @bug_ids; - if ($message =~ /\bBug (\d+)/i) { - push @bug_ids, $1; + my $bug = fetch_bug($bug_id); + if ($bug->{status} eq 'RESOLVED' && $bug->{resolution} ne 'FIXED') { + next; } - - if (!@bug_ids) { - warn "skipping $line (no bug)\n"; - next; - } - - foreach my $bug_id (@bug_ids) { - my $duplicate = 0; - foreach my $revisions (@revisions) { - if ($revisions->{bug_id} == $bug_id) { - $duplicate = 1; - last; - } - } - next if $duplicate; - - my $bug = fetch_bug($bug_id); - if ($bug->{status} eq 'RESOLVED' && $bug->{resolution} ne 'FIXED') { - next; - } - if ($bug->{summary} =~ /\bbackport\s+(?:upstream\s+)?bug\s+(\d+)/i) { - my $upstream = $1; - $bug->{summary} = fetch_bug($upstream)->{summary}; - } - push @revisions, { - hash => $revision, - bug_id => $bug_id, - summary => $bug->{summary}, - }; + if ($bug->{summary} =~ /\bbackport\s+(?:upstream\s+)?bug\s+(\d+)/i) { + my $upstream = $1; + $bug->{summary} = fetch_bug($upstream)->{summary}; } + push @revisions, + {hash => $revision, bug_id => $bug_id, summary => $bug->{summary},}; + } } if (!@revisions) { - die "no new revisions. make sure you run this script before production is updated.\n"; + die + "no new revisions. make sure you run this script before production is updated.\n"; } else { - @revisions = reverse @revisions; + @revisions = reverse @revisions; } my $first_revision = $revisions[0]->{hash}; @@ -100,10 +98,11 @@ close $tag_fh; say 'write bug.push.txt'; open my $bug_fh, '>', 'bug.push.txt'; -say $bug_fh 'https://bugzilla.mozilla.org/enter_bug.cgi?product=bugzilla.mozilla.org&component=Infrastructure&short_desc=push+updated+bugzilla.mozilla.org+live'; +say $bug_fh + 'https://bugzilla.mozilla.org/enter_bug.cgi?product=bugzilla.mozilla.org&component=Infrastructure&short_desc=push+updated+bugzilla.mozilla.org+live'; say $bug_fh "revisions: $first_revision - $last_revision"; foreach my $revision (@revisions) { - say $bug_fh "bug $revision->{bug_id} : $revision->{summary}"; + say $bug_fh "bug $revision->{bug_id} : $revision->{summary}"; } close $bug_fh; @@ -111,22 +110,28 @@ say 'write blog.push.txt'; open my $blog_fh, '>', 'blog.push.txt'; say $blog_fh "[release tag]($tag_url)\n"; -say $blog_fh "the following changes have been pushed to bugzilla.mozilla.org:\n<ul>"; +say $blog_fh + "the following changes have been pushed to bugzilla.mozilla.org:\n<ul>"; foreach my $revision (@revisions) { - printf $blog_fh '<li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=%s" target="_blank">%s</a>] %s</li>%s', - $revision->{bug_id}, $revision->{bug_id}, html_escape($revision->{summary}), "\n"; + printf $blog_fh + '<li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=%s" target="_blank">%s</a>] %s</li>%s', + $revision->{bug_id}, $revision->{bug_id}, html_escape($revision->{summary}), + "\n"; } say $blog_fh '</ul>'; -say $blog_fh q{discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.}; +say $blog_fh + q{discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.}; close $blog_fh; say 'write email.push.txt'; open my $email_fh, '>', 'email.push.txt'; -say $email_fh "the following changes have been pushed to bugzilla.mozilla.org:\n"; +say $email_fh + "the following changes have been pushed to bugzilla.mozilla.org:\n"; say $email_fh "(tag: $tag_url)\n"; foreach my $revision (@revisions) { - printf $email_fh "https://bugzil.la/%s : %s\n", $revision->{bug_id}, $revision->{summary}; + printf $email_fh "https://bugzil.la/%s : %s\n", $revision->{bug_id}, + $revision->{summary}; } close $email_fh; @@ -137,19 +142,20 @@ say $wiki_fh 'https://wiki.mozilla.org/BMO/Recent_Changes'; say $wiki_fh '== ' . DateTime->now->set_time_zone('UTC')->ymd('-') . " ==\n"; say $wiki_fh "[$tag_url $tag]"; foreach my $revision (@revisions) { - printf $wiki_fh "* {{bug|%s}} %s\n", $revision->{bug_id}, $revision->{summary}; + printf $wiki_fh "* {{bug|%s}} %s\n", $revision->{bug_id}, $revision->{summary}; } close $wiki_fh; sub html_escape { - my ($s) = @_; - $s =~ s/&/&/g; - $s =~ s/</</g; - $s =~ s/>/>/g; - return $s; + my ($s) = @_; + $s =~ s/&/&/g; + $s =~ s/</</g; + $s =~ s/>/>/g; + return $s; } -use constant BUG_FIELDS => [qw( +use constant BUG_FIELDS => [ + qw( id product version @@ -158,46 +164,47 @@ use constant BUG_FIELDS => [qw( status resolution assigned_to -)]; + ) +]; sub fetch_bug { - my ($bug_id) = @_; - die 'missing id' unless $bug_id; + my ($bug_id) = @_; + die 'missing id' unless $bug_id; - my $response = _get( 'bug/' . $bug_id, { include_fields => BUG_FIELDS, } ); - return $response->{bugs}->[0]; + my $response = _get('bug/' . $bug_id, {include_fields => BUG_FIELDS,}); + return $response->{bugs}->[0]; } sub _get { - my ($endpoint, $args) = @_; - my $ua = LWP::UserAgent->new( agent => $PROGRAM_NAME ); - $args //= {}; - - if (exists $args->{include_fields} && ref($args->{include_fields})) { - $args->{include_fields} = join ',', @{ $args->{include_fields} }; - } - - my $uri = URI->new('https://bugzilla.mozilla.org/rest/' . $endpoint); - foreach my $name (sort keys %$args) { - $uri->query_param($name => $args->{$name}); - } - - my $request = HTTP::Request->new('GET', $uri->as_string); - $request->header( Content_Type => 'application/json' ); - $request->header( Accept => 'application/json' ); - if ( $ENV{BMO_API_KEY} ) { - $request->header( X_Bugzilla_API_Key => $ENV{BMO_API_KEY} ); - } - - my $response = $ua->request($request); - if ($response->code !~ /^2/) { - my $error = $response->message; - my $ok = eval { - $error = decode_json($response->decoded_content)->{message}; - 1; - }; - $error = $@ unless $ok; - die $error . "\n"; - } - return decode_json($response->decoded_content); + my ($endpoint, $args) = @_; + my $ua = LWP::UserAgent->new(agent => $PROGRAM_NAME); + $args //= {}; + + if (exists $args->{include_fields} && ref($args->{include_fields})) { + $args->{include_fields} = join ',', @{$args->{include_fields}}; + } + + my $uri = URI->new('https://bugzilla.mozilla.org/rest/' . $endpoint); + foreach my $name (sort keys %$args) { + $uri->query_param($name => $args->{$name}); + } + + my $request = HTTP::Request->new('GET', $uri->as_string); + $request->header(Content_Type => 'application/json'); + $request->header(Accept => 'application/json'); + if ($ENV{BMO_API_KEY}) { + $request->header(X_Bugzilla_API_Key => $ENV{BMO_API_KEY}); + } + + my $response = $ua->request($request); + if ($response->code !~ /^2/) { + my $error = $response->message; + my $ok = eval { + $error = decode_json($response->decoded_content)->{message}; + 1; + }; + $error = $@ unless $ok; + die $error . "\n"; + } + return decode_json($response->decoded_content); } diff --git a/scripts/bulk_index.pl b/scripts/bulk_index.pl index cd249a55c..d9aedb3f9 100755 --- a/scripts/bulk_index.pl +++ b/scripts/bulk_index.pl @@ -11,11 +11,16 @@ use 5.10.1; use File::Basename; use File::Spec; + BEGIN { - require lib; - my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), "..")); - lib->import($dir, File::Spec->catdir($dir, "lib"), File::Spec->catdir($dir, qw(local lib perl5))); - chdir($dir); + require lib; + my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), "..")); + lib->import( + $dir, + File::Spec->catdir($dir, "lib"), + File::Spec->catdir($dir, qw(local lib perl5)) + ); + chdir($dir); } use Bugzilla; @@ -32,48 +37,48 @@ my ($debug_sql, $progress_bar, $once); my $verbose = 0; GetOptions( - 'verbose|v+' => \$verbose, - 'debug-sql' => \$debug_sql, - 'progress-bar' => \$progress_bar, - 'once|n' => \$once, + 'verbose|v+' => \$verbose, + 'debug-sql' => \$debug_sql, + 'progress-bar' => \$progress_bar, + 'once|n' => \$once, ); if ($progress_bar) { - $progress_bar = eval { require Term::ProgressBar; 1}; + $progress_bar = eval { require Term::ProgressBar; 1 }; } my $indexer = Bugzilla::Elastic::Indexer->new( - $debug_sql ? ( debug_sql => 1 ) : (), - $progress_bar ? ( progress_bar => 'Term::ProgressBar' ) : (), + $debug_sql ? (debug_sql => 1) : (), + $progress_bar ? (progress_bar => 'Term::ProgressBar') : (), ); my $run_time = time; -my $loop = IO::Async::Loop->new; -my $timer = IO::Async::Timer::Periodic->new( - first_interval => 0, - interval => 15, - reschedule => 'skip', - - on_tick => sub { - printf "Running after %d seconds\n", time - $run_time; - my $start_users = time; - say "indexing users" if $verbose; - my $users = $indexer->bulk_load('Bugzilla::User'); - bulk_load_stats($start_users, $users) if $verbose > 1; - - my $start_bugs = time; - say "indexing bugs" if $verbose; - my $bugs = $indexer->bulk_load('Bugzilla::Bug'); - bulk_load_stats($start_bugs, $bugs) if $verbose > 1; - - my $start_comments = time; - say "indexing comments" if $verbose; - my $comments = $indexer->bulk_load('Bugzilla::Comment'); - bulk_load_stats($start_comments, $comments) if $verbose > 1; - - $loop->stop if $once; - $run_time = time; - }, +my $loop = IO::Async::Loop->new; +my $timer = IO::Async::Timer::Periodic->new( + first_interval => 0, + interval => 15, + reschedule => 'skip', + + on_tick => sub { + printf "Running after %d seconds\n", time - $run_time; + my $start_users = time; + say "indexing users" if $verbose; + my $users = $indexer->bulk_load('Bugzilla::User'); + bulk_load_stats($start_users, $users) if $verbose > 1; + + my $start_bugs = time; + say "indexing bugs" if $verbose; + my $bugs = $indexer->bulk_load('Bugzilla::Bug'); + bulk_load_stats($start_bugs, $bugs) if $verbose > 1; + + my $start_comments = time; + say "indexing comments" if $verbose; + my $comments = $indexer->bulk_load('Bugzilla::Comment'); + bulk_load_stats($start_comments, $comments) if $verbose > 1; + + $loop->stop if $once; + $run_time = time; + }, ); $timer->start(); @@ -81,6 +86,7 @@ $loop->add($timer); $loop->run; sub bulk_load_stats { - my ($start_time, $info) = @_; - printf " %d seconds (%d new, %d update)\n", time - $start_time, $info->{new}, $info->{updated}; + my ($start_time, $info) = @_; + printf " %d seconds (%d new, %d update)\n", time - $start_time, + $info->{new}, $info->{updated}; } diff --git a/scripts/cereal.pl b/scripts/cereal.pl index bc4d8abd4..4ca8df351 100755 --- a/scripts/cereal.pl +++ b/scripts/cereal.pl @@ -12,10 +12,15 @@ use warnings; use File::Basename; use File::Spec; + BEGIN { - require lib; - my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..')); - lib->import($dir, File::Spec->catdir($dir, 'lib'), File::Spec->catdir($dir, qw(local lib perl5))); + require lib; + my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..')); + lib->import( + $dir, + File::Spec->catdir($dir, 'lib'), + File::Spec->catdir($dir, qw(local lib perl5)) + ); } use Bugzilla::DaemonControl qw(catch_signal); @@ -28,25 +33,25 @@ $ENV{LOGGING_PORT} //= 5880; STDOUT->autoflush(1); -my $loop = IO::Async::Loop->new; +my $loop = IO::Async::Loop->new; my $on_stream = sub { - my ($stream) = @_; - my $protocol = IO::Async::Protocol::LineStream->new( - transport => $stream, - on_read_line => sub { - my ( $self, $line ) = @_; - say $line; - }, - ); - $loop->add($protocol); + my ($stream) = @_; + my $protocol = IO::Async::Protocol::LineStream->new( + transport => $stream, + on_read_line => sub { + my ($self, $line) = @_; + say $line; + }, + ); + $loop->add($protocol); }; my @signals = qw( TERM INT KILL ); $loop->listen( - host => '127.0.0.1', - service => $ENV{LOGGING_PORT}, - socktype => 'stream', - on_stream => $on_stream, + host => '127.0.0.1', + service => $ENV{LOGGING_PORT}, + socktype => 'stream', + on_stream => $on_stream, )->get; exit Future->wait_any(map { catch_signal($_, 0) } @signals)->get; diff --git a/scripts/clear-memcached.pl b/scripts/clear-memcached.pl index bbf8f1cca..cd1b02f24 100755 --- a/scripts/clear-memcached.pl +++ b/scripts/clear-memcached.pl @@ -12,16 +12,15 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Constants; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (Bugzilla->memcached->{memcached}) { - Bugzilla->memcached->clear_all(); - print "memcached cleared\n"; -} else { - print "memcached is not enabled\n"; + Bugzilla->memcached->clear_all(); + print "memcached cleared\n"; +} +else { + print "memcached is not enabled\n"; } diff --git a/scripts/clear-templates.pl b/scripts/clear-templates.pl index 9deb2e47d..cab854abb 100755 --- a/scripts/clear-templates.pl +++ b/scripts/clear-templates.pl @@ -12,7 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - use Bugzilla; use Bugzilla::Constants; use Bugzilla::Install::Filesystem qw(fix_dir_permissions); @@ -24,17 +23,16 @@ $| = 1; # rename the current directory and create a new empty one # the templates will lazy-compile on demand -my $path = bz_locations()->{'template_cache'}; +my $path = bz_locations()->{'template_cache'}; my $delete_path = "$path.deleteme"; print "clearing $path\n"; rmtree("$delete_path") if -e "$delete_path"; rename($path, $delete_path) - or die "renaming '$path' to '$delete_path' failed: $!\n"; + or die "renaming '$path' to '$delete_path' failed: $!\n"; -mkpath($path) - or die "creating '$path' failed: $!\n"; +mkpath($path) or die "creating '$path' failed: $!\n"; fix_dir_permissions($path); # delete the temp directory (it's ok if this fails) diff --git a/scripts/convert_datetime.pl b/scripts/convert_datetime.pl index 279eb84b8..8118ab674 100755 --- a/scripts/convert_datetime.pl +++ b/scripts/convert_datetime.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Constants; use Bugzilla::DB; @@ -27,35 +25,40 @@ my $root_mysql_pw = shift; defined $root_mysql_pw || die "MySQL root password required.\n"; my $mysql_dbh = Bugzilla::DB::_connect({ - db_driver => $localconfig->{db_driver}, - db_host => $localconfig->{db_host}, - db_name => 'mysql', - db_user => 'root', - db_pass => $root_mysql_pw + db_driver => $localconfig->{db_driver}, + db_host => $localconfig->{db_host}, + db_name => 'mysql', + db_user => 'root', + db_pass => $root_mysql_pw }); # Check that the mysql timezones are populated and up to date my $mysql_tz_install = "Please populate using instuctions at http://dev.mysql.com/doc/refman/5.6/en/time-zone-support.html#time-zone-installation and re-run this script."; -my $mysql_tz_count = $mysql_dbh->selectrow_array("SELECT COUNT(*) FROM mysql.time_zone_name"); +my $mysql_tz_count + = $mysql_dbh->selectrow_array("SELECT COUNT(*) FROM mysql.time_zone_name"); $mysql_tz_count - || die "The timezone table mysql.time_zone_name has not been populated.\n$mysql_tz_install\n"; -my $mysql_tz_date1 = $mysql_dbh->selectrow_array("SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central')"); -my $mysql_tz_date2 = $mysql_dbh->selectrow_array("SELECT CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central')"); + || die + "The timezone table mysql.time_zone_name has not been populated.\n$mysql_tz_install\n"; +my $mysql_tz_date1 = $mysql_dbh->selectrow_array( + "SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central')"); +my $mysql_tz_date2 = $mysql_dbh->selectrow_array( + "SELECT CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central')"); ($mysql_tz_date1 eq $mysql_tz_date2) - || die "The timezone table mysql.time_zone_name needs to be updated.\n$mysql_tz_install\n"; + || die + "The timezone table mysql.time_zone_name needs to be updated.\n$mysql_tz_install\n"; my $rows = $mysql_dbh->selectall_arrayref( - "SELECT TABLE_NAME, COLUMN_NAME + "SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ? - AND DATA_TYPE='datetime'", - undef, Bugzilla->localconfig->{db_name}); + AND DATA_TYPE='datetime'", undef, Bugzilla->localconfig->{db_name} +); my $total = scalar @$rows; if (!$total) { - print "No DATETIME columns found.\n"; - exit; + print "No DATETIME columns found.\n"; + exit; } print STDERR <<EOF; @@ -68,62 +71,66 @@ getc(); # Store any indexes we may need to drop/add later my %indexes; foreach my $row (@$rows) { - my ($table, $column) = @$row; - next if exists $indexes{$table} && exists $indexes{$table}{$column}; - my $table_info = $bugs_dbh->bz_table_info($table); - next if !exists $table_info->{INDEXES}; - my $table_indexes = $table_info->{INDEXES}; - for (my $i = 0; $i < @$table_indexes; $i++) { - my $name = $table_indexes->[$i]; - my $definition = $table_indexes->[$i+1]; - if ((ref $definition eq 'HASH' && grep($column eq $_, @{ $definition->{FIELDS} })) - || (ref $definition eq 'ARRAY' && grep($column eq $_, @$definition))) - { - $indexes{$table} ||= {}; - $indexes{$table}->{$column} = { name => $name, definition => $definition }; - last; - } + my ($table, $column) = @$row; + next if exists $indexes{$table} && exists $indexes{$table}{$column}; + my $table_info = $bugs_dbh->bz_table_info($table); + next if !exists $table_info->{INDEXES}; + my $table_indexes = $table_info->{INDEXES}; + for (my $i = 0; $i < @$table_indexes; $i++) { + my $name = $table_indexes->[$i]; + my $definition = $table_indexes->[$i + 1]; + if ((ref $definition eq 'HASH' && grep($column eq $_, @{$definition->{FIELDS}})) + || (ref $definition eq 'ARRAY' && grep($column eq $_, @$definition))) + { + $indexes{$table} ||= {}; + $indexes{$table}->{$column} = {name => $name, definition => $definition}; + last; } + } } my @errors; foreach my $row (@$rows) { - my ($table, $column) = @$row; + my ($table, $column) = @$row; - if (my $column_info = $bugs_dbh->bz_column_info($table, $column)) { - say "Converting $table.$column to TIMESTAMP..."; + if (my $column_info = $bugs_dbh->bz_column_info($table, $column)) { + say "Converting $table.$column to TIMESTAMP..."; - # Drop any indexes first - if (exists $indexes{$table} && exists $indexes{$table}->{$column}) { - my $index_name = $indexes{$table}->{$column}->{name}; - $bugs_dbh->bz_drop_index($table, $index_name); - } + # Drop any indexes first + if (exists $indexes{$table} && exists $indexes{$table}->{$column}) { + my $index_name = $indexes{$table}->{$column}->{name}; + $bugs_dbh->bz_drop_index($table, $index_name); + } - # Rename current column to PST - $bugs_dbh->bz_rename_column($table, $column, $column . "_pst"); + # Rename current column to PST + $bugs_dbh->bz_rename_column($table, $column, $column . "_pst"); - # Create the new UTC column - $column_info->{TYPE} = 'TIMESTAMP'; - $column_info->{DEFAULT} = 'CURRENT_TIMESTAMP' if $column_info->{NOTNULL} && !$column_info->{DEFAULT}; - $bugs_dbh->bz_add_column($table, $column, $column_info); + # Create the new UTC column + $column_info->{TYPE} = 'TIMESTAMP'; + $column_info->{DEFAULT} = 'CURRENT_TIMESTAMP' + if $column_info->{NOTNULL} && !$column_info->{DEFAULT}; + $bugs_dbh->bz_add_column($table, $column, $column_info); - # Migrate the PST value to UTC - $bugs_dbh->do("UPDATE $table SET $column = CONVERT_TZ(" . $column . '_pst' . ", 'America/Los_Angeles', 'UTC')"); + # Migrate the PST value to UTC + $bugs_dbh->do("UPDATE $table SET $column = CONVERT_TZ(" + . $column . '_pst' + . ", 'America/Los_Angeles', 'UTC')"); - # Drop the old PST column - $bugs_dbh->bz_drop_column($table, $column . '_pst'); + # Drop the old PST column + $bugs_dbh->bz_drop_column($table, $column . '_pst'); - # And finally recreate the index if one existed for this column - if (exists $indexes{$table} && exists $indexes{$table}->{$column}) { - my $index_info = $indexes{$table}->{$column}; - $bugs_dbh->bz_add_index($table, $index_info->{name}, $index_info->{definition}); - } - } - else { - push(@errors, "$table.$column does not exist in bz_schema and will need to fixed manually."); + # And finally recreate the index if one existed for this column + if (exists $indexes{$table} && exists $indexes{$table}->{$column}) { + my $index_info = $indexes{$table}->{$column}; + $bugs_dbh->bz_add_index($table, $index_info->{name}, $index_info->{definition}); } + } + else { + push(@errors, + "$table.$column does not exist in bz_schema and will need to fixed manually."); + } } if (@errors) { - print "Errors:\n" . join("\n", @errors) . "\n"; + print "Errors:\n" . join("\n", @errors) . "\n"; } diff --git a/scripts/cpanfile_fixed_versions.pl b/scripts/cpanfile_fixed_versions.pl index dd2fc0a0c..028382a69 100755 --- a/scripts/cpanfile_fixed_versions.pl +++ b/scripts/cpanfile_fixed_versions.pl @@ -12,118 +12,118 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla::Constants; use Bugzilla::Install::Requirements; use Bugzilla::Install::Util; sub _check_vers { - my ($params) = @_; - my $module = $params->{module}; - my $package = $params->{package}; - if (!$package) { - $package = $module; - $package =~ s/::/-/g; + my ($params) = @_; + my $module = $params->{module}; + my $package = $params->{package}; + if (!$package) { + $package = $module; + $package =~ s/::/-/g; + } + + my $wanted = $params->{version}; + + eval "require $module;"; + + # Don't let loading a module change the output-encoding of STDOUT + # or STDERR. (CGI.pm tries to set "binmode" on these file handles when + # it's loaded, and other modules may do the same in the future.) + Bugzilla::Install::Util::set_output_encoding(); + + # VERSION is provided by UNIVERSAL::, and can be called even if + # the module isn't loaded. We eval'uate ->VERSION because it can die + # when the version is not valid (yes, this happens from time to time). + # In that case, we use an uglier method to get the version. + my $vnum = eval { $module->VERSION }; + if ($@) { + no strict 'refs'; + $vnum = ${"${module}::VERSION"}; + + # If we come here, then the version is not a valid one. + # We try to sanitize it. + if ($vnum =~ /^((\d+)(\.\d+)*)/) { + $vnum = $1; } + } + $vnum ||= -1; - my $wanted = $params->{version}; - - eval "require $module;"; - # Don't let loading a module change the output-encoding of STDOUT - # or STDERR. (CGI.pm tries to set "binmode" on these file handles when - # it's loaded, and other modules may do the same in the future.) - Bugzilla::Install::Util::set_output_encoding(); - - # VERSION is provided by UNIVERSAL::, and can be called even if - # the module isn't loaded. We eval'uate ->VERSION because it can die - # when the version is not valid (yes, this happens from time to time). - # In that case, we use an uglier method to get the version. - my $vnum = eval { $module->VERSION }; - if ($@) { - no strict 'refs'; - $vnum = ${"${module}::VERSION"}; - - # If we come here, then the version is not a valid one. - # We try to sanitize it. - if ($vnum =~ /^((\d+)(\.\d+)*)/) { - $vnum = $1; - } - } - $vnum ||= -1; - - # Must do a string comparison as $vnum may be of the form 5.10.1. - my $vok = ($vnum ne '-1' && version->new($vnum) >= version->new($wanted)) ? 1 : 0; - if ($vok && $params->{blacklist}) { - $vok = 0 if grep($vnum =~ /$_/, @{$params->{blacklist}}); - } + # Must do a string comparison as $vnum may be of the form 5.10.1. + my $vok + = ($vnum ne '-1' && version->new($vnum) >= version->new($wanted)) ? 1 : 0; + if ($vok && $params->{blacklist}) { + $vok = 0 if grep($vnum =~ /$_/, @{$params->{blacklist}}); + } - return { - module => $module, - ok => $vok, - wanted => $wanted, - found => $vnum, - }; + return {module => $module, ok => $vok, wanted => $wanted, found => $vnum,}; } my $cpanfile; + # Required modules -foreach my $module (@{ REQUIRED_MODULES() }) { - my $current = _check_vers($module); - my $requires = "requires '" . $current->{module} . "'"; - $requires .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; - $requires .= ";\n"; - $cpanfile .= $requires; +foreach my $module (@{REQUIRED_MODULES()}) { + my $current = _check_vers($module); + my $requires = "requires '" . $current->{module} . "'"; + $requires + .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; + $requires .= ";\n"; + $cpanfile .= $requires; } # Recommended modules $cpanfile .= "\n# Optional\n"; my %features; -foreach my $module (@{ OPTIONAL_MODULES() }) { - next if $module->{package} eq 'mod_perl'; # Skip mod_perl since this would be installed by distro - my $current = _check_vers($module); - if (exists $module->{feature}) { - foreach my $feature (@{ $module->{feature} }) { - # cpanm requires that each feature only be defined in the cpanfile - # once, so we use an intermediate hash to consolidate/de-dupe the - # modules associated with each feature. - $features{$feature}{$module->{module}} - = ($current->{ok} ? $current->{found} : $current->{wanted}); - } - } - else { - my $recommends = ""; - $recommends .= "recommends '" . $module->{module} . "'"; - $recommends .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; - $recommends .= ";\n"; - $cpanfile .= $recommends; +foreach my $module (@{OPTIONAL_MODULES()}) { + next if $module->{package} eq 'mod_perl'; # Skip mod_perl since this would be installed by distro + my $current = _check_vers($module); + if (exists $module->{feature}) { + foreach my $feature (@{$module->{feature}}) { + + # cpanm requires that each feature only be defined in the cpanfile + # once, so we use an intermediate hash to consolidate/de-dupe the + # modules associated with each feature. + $features{$feature}{$module->{module}} + = ($current->{ok} ? $current->{found} : $current->{wanted}); } + } + else { + my $recommends = ""; + $recommends .= "recommends '" . $module->{module} . "'"; + $recommends + .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; + $recommends .= ";\n"; + $cpanfile .= $recommends; + } } foreach my $feature (sort keys %features) { - my $recommends = ""; - $recommends .= "feature '" . $feature . "' => sub {\n"; - foreach my $module (sort keys %{ $features{$feature} }) { - my $version = $features{$feature}{$module}; - $recommends .= " recommends '" . $module . "'"; - $recommends .= ", '$version'" if $version; - $recommends .= ";\n"; - } - $recommends .= "};\n"; - $cpanfile .= $recommends; + my $recommends = ""; + $recommends .= "feature '" . $feature . "' => sub {\n"; + foreach my $module (sort keys %{$features{$feature}}) { + my $version = $features{$feature}{$module}; + $recommends .= " recommends '" . $module . "'"; + $recommends .= ", '$version'" if $version; + $recommends .= ";\n"; + } + $recommends .= "};\n"; + $cpanfile .= $recommends; } # Database modules $cpanfile .= "\n# Database support\n"; -foreach my $db (keys %{ DB_MODULE() }) { - next if !exists DB_MODULE->{$db}->{dbd}; - my $dbd = DB_MODULE->{$db}->{dbd}; - my $current = _check_vers($dbd); - my $recommends .= "feature '$db' => sub {\n"; - $recommends .= " recommends '" . $dbd->{module} . "'"; - $recommends .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; - $recommends .= ";\n};\n"; - $cpanfile .= $recommends; +foreach my $db (keys %{DB_MODULE()}) { + next if !exists DB_MODULE->{$db}->{dbd}; + my $dbd = DB_MODULE->{$db}->{dbd}; + my $current = _check_vers($dbd); + my $recommends .= "feature '$db' => sub {\n"; + $recommends .= " recommends '" . $dbd->{module} . "'"; + $recommends + .= ", '" . ($current->{ok} ? $current->{found} : $current->{wanted}) . "'"; + $recommends .= ";\n};\n"; + $cpanfile .= $recommends; } # Write out the cpanfile to STDOUT diff --git a/scripts/create_app_id.pl b/scripts/create_app_id.pl index d2efc33cc..45ac224ae 100755 --- a/scripts/create_app_id.pl +++ b/scripts/create_app_id.pl @@ -24,7 +24,7 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($callback, $description) = @ARGV; if (!$callback || !$description) { - die "Usage: scripts/create_app_key.pl <callback_url> <description>\n"; + die "Usage: scripts/create_app_key.pl <callback_url> <description>\n"; } print sha256_hex($callback, $description); diff --git a/scripts/delete_comments_csv.pl b/scripts/delete_comments_csv.pl index 5e3c0c3df..826c92d1d 100755 --- a/scripts/delete_comments_csv.pl +++ b/scripts/delete_comments_csv.pl @@ -19,7 +19,7 @@ use Text::CSV_XS; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); Bugzilla->set_user($auto_user); my $dbh = Bugzilla->dbh; @@ -33,21 +33,22 @@ $dbh->bz_start_transaction; my $csv = Text::CSV_XS->new(); while (my $line = <CSV>) { - $csv->parse($line); - my @values = $csv->fields(); - next if !@values; - my ($bug_id, $comment_id) = @values; - next if $bug_id !~ /^\d+$/; - print "Deleting comment '$comment_id' from bug '$bug_id' "; - my $bug = Bugzilla::Bug->check({ id => $bug_id }); - my $comment = Bugzilla::Comment->new($comment_id); - if (!$comment || $comment->bug_id ne $bug_id) { - print "... commment '$comment_id' does not exist ... skipping.\n"; - next; - } - $comment->remove_from_db(); - $bug->_sync_fulltext( update_comments => 1 ); - print "... done.\n"; + $csv->parse($line); + my @values = $csv->fields(); + next if !@values; + my ($bug_id, $comment_id) = @values; + next if $bug_id !~ /^\d+$/; + print "Deleting comment '$comment_id' from bug '$bug_id' "; + my $bug = Bugzilla::Bug->check({id => $bug_id}); + my $comment = Bugzilla::Comment->new($comment_id); + + if (!$comment || $comment->bug_id ne $bug_id) { + print "... commment '$comment_id' does not exist ... skipping.\n"; + next; + } + $comment->remove_from_db(); + $bug->_sync_fulltext(update_comments => 1); + print "... done.\n"; } $dbh->bz_commit_transaction; diff --git a/scripts/eject-users-from-groups.pl b/scripts/eject-users-from-groups.pl index 4b27be83d..63fe9e6b1 100755 --- a/scripts/eject-users-from-groups.pl +++ b/scripts/eject-users-from-groups.pl @@ -11,7 +11,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - use Getopt::Long; use Bugzilla; @@ -24,33 +23,34 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $dbh = Bugzilla->dbh; my @remove_group_names; my $nobody_name = Bugzilla->params->{'nobody_user'}; -my $admin_name = 'automation@bmo.tld'; +my $admin_name = 'automation@bmo.tld'; GetOptions( - 'nobody=s' => \$nobody_name, - 'admin=s' => \$admin_name, - 'group|G=s@' => \@remove_group_names, + 'nobody=s' => \$nobody_name, + 'admin=s' => \$admin_name, + 'group|G=s@' => \@remove_group_names, ); my @user_names = @ARGV; unless (@remove_group_names) { - die "usage: $0 [--admin=$admin_name] [--nobody=$nobody_name] ", - "-G legal -G finance dylan\@mozilla.com bob\@example.net\n"; + die "usage: $0 [--admin=$admin_name] [--nobody=$nobody_name] ", + "-G legal -G finance dylan\@mozilla.com bob\@example.net\n"; } $dbh->bz_start_transaction(); my ($timestamp) = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); -my $admin_user = Bugzilla::User->check({ name => $admin_name }); -my $nobody_user = Bugzilla::User->check({ name => $nobody_name }); +my $admin_user = Bugzilla::User->check({name => $admin_name}); +my $nobody_user = Bugzilla::User->check({name => $nobody_name}); Bugzilla->set_user($admin_user); -my @remove_groups = map { Bugzilla::Group->check({name => $_}) } @remove_group_names; +my @remove_groups + = map { Bugzilla::Group->check({name => $_}) } @remove_group_names; foreach my $user_name (@user_names) { - my $user = Bugzilla::User->check({name => $user_name}); - say 'Working on ', $user->identity; + my $user = Bugzilla::User->check({name => $user_name}); + say 'Working on ', $user->identity; - $user->force_bug_dissociation($nobody_user, \@remove_groups, $timestamp); + $user->force_bug_dissociation($nobody_user, \@remove_groups, $timestamp); } $dbh->bz_commit_transaction(); diff --git a/scripts/entrypoint.pl b/scripts/entrypoint.pl index f5c52f6a6..4a3cb2183 100755 --- a/scripts/entrypoint.pl +++ b/scripts/entrypoint.pl @@ -9,10 +9,10 @@ use Bugzilla::Install::Localconfig (); use Bugzilla::Install::Util qw(install_string); use Bugzilla::Test::Util qw(create_user); use Bugzilla::DaemonControl qw( - run_cereal_and_httpd - run_cereal_and_jobqueue - assert_httpd assert_database assert_selenium - on_finish on_exception + run_cereal_and_httpd + run_cereal_and_jobqueue + assert_httpd assert_database assert_selenium + on_finish on_exception ); use DBI; @@ -30,23 +30,24 @@ use Sys::Hostname; use User::pwent; BEGIN { - STDOUT->autoflush(1); - STDERR->autoflush(1); + STDOUT->autoflush(1); + STDERR->autoflush(1); } use constant CI => $ENV{CI}; my $cmd = shift @ARGV; -my $opts = __PACKAGE__->can("opt_$cmd") // sub { @ARGV }; +my $opts = __PACKAGE__->can("opt_$cmd") // sub {@ARGV}; my $func = __PACKAGE__->can("cmd_$cmd") // sub { - check_data_dir(); - wait_for_db(); - run($cmd, @_); + check_data_dir(); + wait_for_db(); + run($cmd, @_); }; fix_path(); check_user(); -check_env(qw( +check_env( + qw( LOCALCONFIG_ENV BMO_db_host BMO_db_name @@ -55,231 +56,237 @@ check_env(qw( BMO_memcached_namespace BMO_memcached_servers BMO_urlbase -)); + ) +); $func->($opts->()); sub cmd_demo { - unless (-f '/app/data/params') { - cmd_load_test_data(); - check_env(qw( - PHABRICATOR_BOT_LOGIN - PHABRICATOR_BOT_PASSWORD - PHABRICATOR_BOT_API_KEY - CONDUIT_USER_LOGIN - CONDUIT_USER_PASSWORD - CONDUIT_USER_API_KEY - )); - run( 'perl', 'scripts/generate_conduit_data.pl' ); - } - cmd_httpd(); + unless (-f '/app/data/params') { + cmd_load_test_data(); + check_env( + qw( + PHABRICATOR_BOT_LOGIN + PHABRICATOR_BOT_PASSWORD + PHABRICATOR_BOT_API_KEY + CONDUIT_USER_LOGIN + CONDUIT_USER_PASSWORD + CONDUIT_USER_API_KEY + ) + ); + run('perl', 'scripts/generate_conduit_data.pl'); + } + cmd_httpd(); } -sub cmd_httpd { - check_data_dir(); - wait_for_db(); +sub cmd_httpd { + check_data_dir(); + wait_for_db(); - my $httpd_exit_f = run_cereal_and_httpd(); - assert_httpd()->get(); - exit $httpd_exit_f->get(); + my $httpd_exit_f = run_cereal_and_httpd(); + assert_httpd()->get(); + exit $httpd_exit_f->get(); } sub cmd_jobqueue { - my (@args) = @_; - check_data_dir(); - wait_for_db(); - exit run_cereal_and_jobqueue(@args)->get; + my (@args) = @_; + check_data_dir(); + wait_for_db(); + exit run_cereal_and_jobqueue(@args)->get; } sub cmd_dev_httpd { - my $have_params = -f "/app/data/params"; - assert_database->get(); - - run( 'perl', 'checksetup.pl', '--no-template', $ENV{BZ_ANSWERS_FILE} ); - if ( not $have_params ) { - run( 'perl', 'scripts/generate_bmo_data.pl', '--param' => 'use_mailer_queue=0', 'vagrant@bmo-web.vm' ); - } + my $have_params = -f "/app/data/params"; + assert_database->get(); + + run('perl', 'checksetup.pl', '--no-template', $ENV{BZ_ANSWERS_FILE}); + if (not $have_params) { + run( + 'perl', 'scripts/generate_bmo_data.pl', + '--param' => 'use_mailer_queue=0', + 'vagrant@bmo-web.vm' + ); + } - my $httpd_exit_f = run_cereal_and_httpd('-DACCESS_LOGS'); - assert_httpd()->get; - exit $httpd_exit_f->get; + my $httpd_exit_f = run_cereal_and_httpd('-DACCESS_LOGS'); + assert_httpd()->get; + exit $httpd_exit_f->get; } sub cmd_checksetup_gen_files { - my (@args) = @_; - run( 'perl', 'checksetup.pl', '--no-database', @args); + my (@args) = @_; + run('perl', 'checksetup.pl', '--no-database', @args); } sub cmd_checksetup { - check_data_dir(); - wait_for_db(); - run( 'perl', 'checksetup.pl', '--no-template', '--no-permissions' ); + check_data_dir(); + wait_for_db(); + run('perl', 'checksetup.pl', '--no-template', '--no-permissions'); } sub cmd_load_test_data { - wait_for_db(); - - die 'BZ_QA_ANSWERS_FILE is not set' unless $ENV{BZ_QA_ANSWERS_FILE}; - run( 'perl', 'checksetup.pl', '--no-template', $ENV{BZ_QA_ANSWERS_FILE} ); - - if ($ENV{BZ_QA_LEGACY_MODE}) { - run( 'perl', 'scripts/generate_bmo_data.pl', - '--user-pref', 'ui_experiments=off' ); - chdir '/app/qa/config'; - say 'chdir(/app/qa/config)'; - run( 'perl', 'generate_test_data.pl' ); - } - else { - run( 'perl', 'scripts/generate_bmo_data.pl', '--param' => 'use_mailer_queue=0' ); - } + wait_for_db(); + + die 'BZ_QA_ANSWERS_FILE is not set' unless $ENV{BZ_QA_ANSWERS_FILE}; + run('perl', 'checksetup.pl', '--no-template', $ENV{BZ_QA_ANSWERS_FILE}); + + if ($ENV{BZ_QA_LEGACY_MODE}) { + run('perl', 'scripts/generate_bmo_data.pl', '--user-pref', + 'ui_experiments=off'); + chdir '/app/qa/config'; + say 'chdir(/app/qa/config)'; + run('perl', 'generate_test_data.pl'); + } + else { + run('perl', 'scripts/generate_bmo_data.pl', '--param' => 'use_mailer_queue=0'); + } } sub cmd_test_webservices { - my $conf = require $ENV{BZ_QA_CONF_FILE}; - - check_data_dir(); - copy_qa_extension(); - assert_database()->get; - my $httpd_exit_f = run_cereal_and_httpd('-DHTTPD_IN_SUBDIR'); - my $prove_exit_f = run_prove( - httpd_url => $conf->{browser_url}, - prove_cmd => [ - 'prove', '-qf', '-I/app', - '-I/app/local/lib/perl5', - sub { glob 'webservice_*.t' }, - ], - prove_dir => '/app/qa/t', - ); - exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; + my $conf = require $ENV{BZ_QA_CONF_FILE}; + + check_data_dir(); + copy_qa_extension(); + assert_database()->get; + my $httpd_exit_f = run_cereal_and_httpd('-DHTTPD_IN_SUBDIR'); + my $prove_exit_f = run_prove( + httpd_url => $conf->{browser_url}, + prove_cmd => [ + 'prove', '-qf', '-I/app', '-I/app/local/lib/perl5', + sub { glob 'webservice_*.t' }, + ], + prove_dir => '/app/qa/t', + ); + exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; } sub cmd_test_selenium { - my $conf = require $ENV{BZ_QA_CONF_FILE}; - $ENV{HTTP_BACKEND} = 'simple'; - - check_data_dir(); - copy_qa_extension(); - - assert_database()->get; - assert_selenium()->get; - my $httpd_exit_f = run_cereal_and_httpd('-DHTTPD_IN_SUBDIR'); - my $prove_exit_f = run_prove( - httpd_url => $conf->{browser_url}, - prove_dir => '/app/qa/t', - prove_cmd => [ - 'prove', '-qf', '-Ilib', '-I/app', - '-I/app/local/lib/perl5', - sub { glob 'test_*.t' } - ], - ); - exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; + my $conf = require $ENV{BZ_QA_CONF_FILE}; + $ENV{HTTP_BACKEND} = 'simple'; + + check_data_dir(); + copy_qa_extension(); + + assert_database()->get; + assert_selenium()->get; + my $httpd_exit_f = run_cereal_and_httpd('-DHTTPD_IN_SUBDIR'); + my $prove_exit_f = run_prove( + httpd_url => $conf->{browser_url}, + prove_dir => '/app/qa/t', + prove_cmd => [ + 'prove', '-qf', '-Ilib', '-I/app', '-I/app/local/lib/perl5', + sub { glob 'test_*.t' } + ], + ); + exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; } -sub cmd_shell { run( 'bash', '-l' ); } -sub cmd_prove { - my (@args) = @_; - run( 'prove', '-I/app', '-I/app/local/lib/perl5', @args ); +sub cmd_shell { run('bash', '-l'); } + +sub cmd_prove { + my (@args) = @_; + run('prove', '-I/app', '-I/app/local/lib/perl5', @args); } -sub cmd_version { run( 'cat', '/app/version.json' ); } +sub cmd_version { run('cat', '/app/version.json'); } sub cmd_test_bmo { - my (@prove_args) = @_; - check_data_dir(); - - assert_database()->get; - assert_selenium()->get; - $ENV{BZ_TEST_NEWBIE} = 'newbie@mozilla.example'; - $ENV{BZ_TEST_NEWBIE_PASS} = 'captain.space.bagel.ROBOT!'; - create_user($ENV{BZ_TEST_NEWBIE}, $ENV{BZ_TEST_NEWBIE_PASS}, realname => 'Newbie User'); - - $ENV{BZ_TEST_NEWBIE2} = 'newbie2@mozilla.example'; - $ENV{BZ_TEST_NEWBIE2_PASS} = 'captain.space.pants.time.lord'; - - my $httpd_exit_f = run_cereal_and_httpd(); - my $prove_exit_f = run_prove( - httpd_url => $ENV{BZ_BASE_URL}, - prove_cmd => [ 'prove', '-I/app', '-I/app/local/lib/perl5', @prove_args ], - ); - - exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; + my (@prove_args) = @_; + check_data_dir(); + + assert_database()->get; + assert_selenium()->get; + $ENV{BZ_TEST_NEWBIE} = 'newbie@mozilla.example'; + $ENV{BZ_TEST_NEWBIE_PASS} = 'captain.space.bagel.ROBOT!'; + create_user( + $ENV{BZ_TEST_NEWBIE}, + $ENV{BZ_TEST_NEWBIE_PASS}, + realname => 'Newbie User' + ); + + $ENV{BZ_TEST_NEWBIE2} = 'newbie2@mozilla.example'; + $ENV{BZ_TEST_NEWBIE2_PASS} = 'captain.space.pants.time.lord'; + + my $httpd_exit_f = run_cereal_and_httpd(); + my $prove_exit_f = run_prove( + httpd_url => $ENV{BZ_BASE_URL}, + prove_cmd => ['prove', '-I/app', '-I/app/local/lib/perl5', @prove_args], + ); + + exit Future->wait_any($prove_exit_f, $httpd_exit_f)->get; } sub run_prove { - my (%param) = @_; - - my $prove_cmd = $param{prove_cmd}; - my $prove_dir = $param{prove_dir}; - assert_httpd()->then(sub { - my $loop = IO::Async::Loop->new; - $loop->connect( - socktype => 'stream', - host => 'localhost', - service => 5880, - )->then(sub { - my $socket = shift; - my $prove_exit_f = $loop->new_future; - my $prove = IO::Async::Process->new( - code => sub { - chdir $prove_dir if $prove_dir; - my @cmd = (map { ref $_ eq 'CODE' ? $_->() : $_ } @$prove_cmd); - warn "run @cmd\n"; - exec @cmd; - }, - setup => [ - stdin => ['close'], - stdout => [ 'dup', $socket ], - ], - on_finish => on_finish($prove_exit_f), - on_exception => on_exception('prove', $prove_exit_f), - ); - $prove_exit_f->on_cancel(sub { $prove->kill('TERM') }); - $loop->add($prove); - return $prove_exit_f; - }); - }); + my (%param) = @_; + + my $prove_cmd = $param{prove_cmd}; + my $prove_dir = $param{prove_dir}; + assert_httpd()->then(sub { + my $loop = IO::Async::Loop->new; + $loop->connect(socktype => 'stream', host => 'localhost', service => 5880,) + ->then(sub { + my $socket = shift; + my $prove_exit_f = $loop->new_future; + my $prove = IO::Async::Process->new( + code => sub { + chdir $prove_dir if $prove_dir; + my @cmd = (map { ref $_ eq 'CODE' ? $_->() : $_ } @$prove_cmd); + warn "run @cmd\n"; + exec @cmd; + }, + setup => [stdin => ['close'], stdout => ['dup', $socket],], + on_finish => on_finish($prove_exit_f), + on_exception => on_exception('prove', $prove_exit_f), + ); + $prove_exit_f->on_cancel(sub { $prove->kill('TERM') }); + $loop->add($prove); + return $prove_exit_f; + }); + }); } sub copy_qa_extension { - say 'copying the QA extension...'; - dircopy('/app/qa/extensions/QA', '/app/extensions/QA'); + say 'copying the QA extension...'; + dircopy('/app/qa/extensions/QA', '/app/extensions/QA'); } sub cmd_wait_for_db { - wait_for_db(); + wait_for_db(); } sub wait_for_db { - assert_database()->get; + assert_database()->get; } sub check_user { - die 'Effective UID must be 10001!' unless $EUID == 10_001; - my $user = getpwuid($EUID)->name; - die "Name of EUID must be app, not $user" unless $user eq 'app'; + die 'Effective UID must be 10001!' unless $EUID == 10_001; + my $user = getpwuid($EUID)->name; + die "Name of EUID must be app, not $user" unless $user eq 'app'; } sub check_data_dir { - die "/app/data must be writable by user 'app' (id: $EUID)" unless -w '/app/data'; - die '/app/data/params must exist' unless -f '/app/data/params'; + die "/app/data must be writable by user 'app' (id: $EUID)" + unless -w '/app/data'; + die '/app/data/params must exist' unless -f '/app/data/params'; } sub check_env { - my (@require_env) = @_; - my @missing_env = grep { not exists $ENV{$_} } @require_env; - if (@missing_env) { - die 'Missing required environmental variables: ', join(', ', @missing_env), "\n"; - } + my (@require_env) = @_; + my @missing_env = grep { not exists $ENV{$_} } @require_env; + if (@missing_env) { + die 'Missing required environmental variables: ', join(', ', @missing_env), + "\n"; + } } sub fix_path { - $ENV{PATH} = "/app/local/bin:$ENV{PATH}"; + $ENV{PATH} = "/app/local/bin:$ENV{PATH}"; } sub run { - my (@cmd) = @_; - say "+ @cmd"; - my $rv = system @cmd; - if ($rv != 0) { - exit 1; - } + my (@cmd) = @_; + say "+ @cmd"; + my $rv = system @cmd; + if ($rv != 0) { + exit 1; + } } diff --git a/scripts/fix-attachment-sizes.pl b/scripts/fix-attachment-sizes.pl index 6c5a3a39c..c946d49ca 100755 --- a/scripts/fix-attachment-sizes.pl +++ b/scripts/fix-attachment-sizes.pl @@ -21,21 +21,22 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction(); -my $attachment_sizes = $dbh->selectall_arrayref(q{ +my $attachment_sizes = $dbh->selectall_arrayref( + q{ SELECT attachments.attach_id, length(thedata) FROM attach_data INNER JOIN attachments ON attachments.attach_id = attach_data.id WHERE attachments.attach_size != 0 AND attachments.mimetype = 'image/png' - AND length(thedata) != attachments.attach_size }); + AND length(thedata) != attachments.attach_size } +); say "Found ", scalar @$attachment_sizes, " attachments to fix"; foreach my $attachment_size (@$attachment_sizes) { - say "Setting size for $attachment_size->[0] to $attachment_size->[1]"; + say "Setting size for $attachment_size->[0] to $attachment_size->[1]"; - $dbh->do("UPDATE attachments SET attach_size = ? WHERE attach_id = ?", undef, - $attachment_size->[1], - $attachment_size->[0]); + $dbh->do("UPDATE attachments SET attach_size = ? WHERE attach_id = ?", + undef, $attachment_size->[1], $attachment_size->[0]); } -$dbh->bz_commit_transaction();
\ No newline at end of file +$dbh->bz_commit_transaction(); diff --git a/scripts/fix_all_open_status_queries.pl b/scripts/fix_all_open_status_queries.pl index 1ba7c66c6..51f453fc4 100755 --- a/scripts/fix_all_open_status_queries.pl +++ b/scripts/fix_all_open_status_queries.pl @@ -30,87 +30,88 @@ USAGE } sub do_namedqueries { - my ($new_status) = @_; - my $dbh = Bugzilla->dbh; - my $replace_count = 0; + my ($new_status) = @_; + my $dbh = Bugzilla->dbh; + my $replace_count = 0; - my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); + my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); - if ($query) { - $dbh->bz_start_transaction(); + if ($query) { + $dbh->bz_start_transaction(); - my $sth = $dbh->prepare("UPDATE namedqueries SET query = ? WHERE id = ?"); + my $sth = $dbh->prepare("UPDATE namedqueries SET query = ? WHERE id = ?"); - foreach my $row (@$query) { - my ($id, $old_query) = @$row; - my $new_query = all_open_states($new_status, $old_query); - if ($new_query) { - trick_taint($new_query); - $sth->execute($new_query, $id); - $replace_count++; - } - } - - $dbh->bz_commit_transaction(); + foreach my $row (@$query) { + my ($id, $old_query) = @$row; + my $new_query = all_open_states($new_status, $old_query); + if ($new_query) { + trick_taint($new_query); + $sth->execute($new_query, $id); + $replace_count++; + } } - print "namedqueries: $replace_count replacements made.\n"; + $dbh->bz_commit_transaction(); + } + + print "namedqueries: $replace_count replacements made.\n"; } # series sub do_series { - my ($new_status) = @_; - my $dbh = Bugzilla->dbh; - my $replace_count = 0; - - my $query = $dbh->selectall_arrayref("SELECT series_id, query FROM series"); + my ($new_status) = @_; + my $dbh = Bugzilla->dbh; + my $replace_count = 0; - if ($query) { - $dbh->bz_start_transaction(); + my $query = $dbh->selectall_arrayref("SELECT series_id, query FROM series"); - my $sth = $dbh->prepare("UPDATE series SET query = ? WHERE series_id = ?"); + if ($query) { + $dbh->bz_start_transaction(); - foreach my $row (@$query) { - my ($series_id, $old_query) = @$row; - my $new_query = all_open_states($new_status, $old_query); - if ($new_query) { - trick_taint($new_query); - $sth->execute($new_query, $series_id); - $replace_count++; - } - } + my $sth = $dbh->prepare("UPDATE series SET query = ? WHERE series_id = ?"); - $dbh->bz_commit_transaction(); + foreach my $row (@$query) { + my ($series_id, $old_query) = @$row; + my $new_query = all_open_states($new_status, $old_query); + if ($new_query) { + trick_taint($new_query); + $sth->execute($new_query, $series_id); + $replace_count++; + } } - print "series: $replace_count replacements made.\n"; + $dbh->bz_commit_transaction(); + } + + print "series: $replace_count replacements made.\n"; } sub all_open_states { - my ($new_status, $query) = @_; + my ($new_status, $query) = @_; - my @open_states = Bugzilla::Status::BUG_STATE_OPEN(); - my $cgi = Bugzilla::CGI->new($query); - my @query_states = $cgi->param('bug_status'); + my @open_states = Bugzilla::Status::BUG_STATE_OPEN(); + my $cgi = Bugzilla::CGI->new($query); + my @query_states = $cgi->param('bug_status'); - my ($removed, $added) = diff_arrays(\@query_states, \@open_states); + my ($removed, $added) = diff_arrays(\@query_states, \@open_states); - if (scalar @$added == 1 && $added->[0] eq $new_status) { - push(@query_states, $new_status); - $cgi->param('bug_status', @query_states); - return $cgi->canonicalise_query(); - } + if (scalar @$added == 1 && $added->[0] eq $new_status) { + push(@query_states, $new_status); + $cgi->param('bug_status', @query_states); + return $cgi->canonicalise_query(); + } - return ''; + return ''; } sub validate_status { - my ($status) = @_; - my $dbh = Bugzilla->dbh; - my $exists = $dbh->selectrow_array("SELECT 1 FROM bug_status - WHERE value = ?", - undef, $status); - return $exists ? 1 : 0; + my ($status) = @_; + my $dbh = Bugzilla->dbh; + my $exists = $dbh->selectrow_array( + "SELECT 1 FROM bug_status + WHERE value = ?", undef, $status + ); + return $exists ? 1 : 0; } ############################################################################# @@ -120,8 +121,8 @@ sub validate_status { Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 1) { - usage(); - exit(1); + usage(); + exit(1); } my ($new_status) = @ARGV; @@ -129,9 +130,9 @@ my ($new_status) = @ARGV; $new_status = uc($new_status); if (!validate_status($new_status)) { - print "Invalid status: $new_status\n\n"; - usage(); - exit(1); + print "Invalid status: $new_status\n\n"; + usage(); + exit(1); } print "Adding new status '$new_status'.\n\n"; diff --git a/scripts/fixgroupqueries.pl b/scripts/fixgroupqueries.pl index 23d86268d..23fcfb9f0 100755 --- a/scripts/fixgroupqueries.pl +++ b/scripts/fixgroupqueries.pl @@ -42,61 +42,70 @@ USAGE } sub do_namedqueries($$) { - my ($old, $new) = @_; - $old = url_quote($old); - $new = url_quote($new); - - my $dbh = Bugzilla->dbh; - - my $replace_count = 0; - my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); - if ($query) { - my $sth = $dbh->prepare("UPDATE namedqueries SET query = ? - WHERE id = ?"); - - foreach my $row (@$query) { - my ($id, $query) = @$row; - if (($query =~ /field\d+-\d+-\d+=bug_group/) && - ($query =~ /(?:^|&|;)value\d+-\d+-\d+=$old(?:;|&|$)/)) { - $query =~ s/((?:^|&|;)value\d+-\d+-\d+=)$old(;|&|$)/$1$new$2/; - $sth->execute($query, $id); - $replace_count++; - } - } + my ($old, $new) = @_; + $old = url_quote($old); + $new = url_quote($new); + + my $dbh = Bugzilla->dbh; + + my $replace_count = 0; + my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); + if ($query) { + my $sth = $dbh->prepare( + "UPDATE namedqueries SET query = ? + WHERE id = ?" + ); + + foreach my $row (@$query) { + my ($id, $query) = @$row; + if ( ($query =~ /field\d+-\d+-\d+=bug_group/) + && ($query =~ /(?:^|&|;)value\d+-\d+-\d+=$old(?:;|&|$)/)) + { + $query =~ s/((?:^|&|;)value\d+-\d+-\d+=)$old(;|&|$)/$1$new$2/; + $sth->execute($query, $id); + $replace_count++; + } } + } - print "namedqueries: $replace_count replacements made.\n"; + print "namedqueries: $replace_count replacements made.\n"; } # series sub do_series($$) { - my ($old, $new) = @_; - $old = url_quote($old); - $new = url_quote($new); - - my $dbh = Bugzilla->dbh; - #$dbh->bz_start_transaction(); - - my $replace_count = 0; - my $query = $dbh->selectall_arrayref("SELECT series_id, query - FROM series"); - if ($query) { - my $sth = $dbh->prepare("UPDATE series SET query = ? - WHERE series_id = ?"); - foreach my $row (@$query) { - my ($series_id, $query) = @$row; - - if (($query =~ /field\d+-\d+-\d+=bug_group/) && - ($query =~ /(?:^|&|;)value\d+-\d+-\d+=$old(?:;|&|$)/)) { - $query =~ s/((?:^|&|;)value\d+-\d+-\d+=)$old(;|&|$)/$1$new$2/; - $sth->execute($query, $series_id); - $replace_count++; - } - } + my ($old, $new) = @_; + $old = url_quote($old); + $new = url_quote($new); + + my $dbh = Bugzilla->dbh; + + #$dbh->bz_start_transaction(); + + my $replace_count = 0; + my $query = $dbh->selectall_arrayref( + "SELECT series_id, query + FROM series" + ); + if ($query) { + my $sth = $dbh->prepare( + "UPDATE series SET query = ? + WHERE series_id = ?" + ); + foreach my $row (@$query) { + my ($series_id, $query) = @$row; + + if ( ($query =~ /field\d+-\d+-\d+=bug_group/) + && ($query =~ /(?:^|&|;)value\d+-\d+-\d+=$old(?:;|&|$)/)) + { + $query =~ s/((?:^|&|;)value\d+-\d+-\d+=)$old(;|&|$)/$1$new$2/; + $sth->execute($query, $series_id); + $replace_count++; + } } + } - #$dbh->bz_commit_transaction(); - print "series: $replace_count replacements made.\n"; + #$dbh->bz_commit_transaction(); + print "series: $replace_count replacements made.\n"; } ############################################################################# @@ -106,8 +115,8 @@ sub do_series($$) { Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 2) { - usage(); - exit(); + usage(); + exit(); } my ($old, $new) = @ARGV; diff --git a/scripts/fixperms.pl b/scripts/fixperms.pl index 43b11af08..418bcd1ee 100755 --- a/scripts/fixperms.pl +++ b/scripts/fixperms.pl @@ -24,7 +24,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - use Bugzilla; use Bugzilla::Install::Filesystem qw(fix_all_file_permissions); fix_all_file_permissions(1); diff --git a/scripts/fixqueries.pl b/scripts/fixqueries.pl index c26165160..d29ba03a1 100755 --- a/scripts/fixqueries.pl +++ b/scripts/fixqueries.pl @@ -42,72 +42,79 @@ USAGE } sub do_namedqueries($$$) { - my ($field, $old, $new) = @_; - $old = url_quote($old); - $new = url_quote($new); - - my $dbh = Bugzilla->dbh; - #$dbh->bz_start_transaction(); - - my $replace_count = 0; - my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); - if ($query) { - my $sth = $dbh->prepare("UPDATE namedqueries SET query = ? - WHERE id = ?"); - - foreach my $row (@$query) { - my ($id, $query) = @$row; - if ($query =~ /(?:^|&|;)$field=$old(?:&|$|;)/) { - $query =~ s/((?:^|&|;)$field=)$old(;|&|$)/$1$new$2/; - $sth->execute($query, $id); - $replace_count++; - } - } + my ($field, $old, $new) = @_; + $old = url_quote($old); + $new = url_quote($new); + + my $dbh = Bugzilla->dbh; + + #$dbh->bz_start_transaction(); + + my $replace_count = 0; + my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); + if ($query) { + my $sth = $dbh->prepare( + "UPDATE namedqueries SET query = ? + WHERE id = ?" + ); + + foreach my $row (@$query) { + my ($id, $query) = @$row; + if ($query =~ /(?:^|&|;)$field=$old(?:&|$|;)/) { + $query =~ s/((?:^|&|;)$field=)$old(;|&|$)/$1$new$2/; + $sth->execute($query, $id); + $replace_count++; + } } + } - #$dbh->bz_commit_transaction(); - print "namedqueries: $replace_count replacements made.\n"; + #$dbh->bz_commit_transaction(); + print "namedqueries: $replace_count replacements made.\n"; } # series sub do_series($$$) { - my ($field, $old, $new) = @_; - $old = url_quote($old); - $new = url_quote($new); - - my $dbh = Bugzilla->dbh; - #$dbh->bz_start_transaction(); - - my $replace_count = 0; - my $query = $dbh->selectall_arrayref("SELECT series_id, query - FROM series"); - if ($query) { - my $sth = $dbh->prepare("UPDATE series SET query = ? - WHERE series_id = ?"); - foreach my $row (@$query) { - my ($series_id, $query) = @$row; - - if ($query =~ /(?:^|&|;)$field=$old(?:&|$|;)/) { - $query =~ s/((?:^|&|;)$field=)$old(;|&|$)/$1$new$2/; - $replace_count++; - } - - $sth->execute($query, $series_id); - } + my ($field, $old, $new) = @_; + $old = url_quote($old); + $new = url_quote($new); + + my $dbh = Bugzilla->dbh; + + #$dbh->bz_start_transaction(); + + my $replace_count = 0; + my $query = $dbh->selectall_arrayref( + "SELECT series_id, query + FROM series" + ); + if ($query) { + my $sth = $dbh->prepare( + "UPDATE series SET query = ? + WHERE series_id = ?" + ); + foreach my $row (@$query) { + my ($series_id, $query) = @$row; + + if ($query =~ /(?:^|&|;)$field=$old(?:&|$|;)/) { + $query =~ s/((?:^|&|;)$field=)$old(;|&|$)/$1$new$2/; + $replace_count++; + } + + $sth->execute($query, $series_id); } + } - #$dbh->bz_commit_transaction(); - print "series: $replace_count replacements made.\n"; + #$dbh->bz_commit_transaction(); + print "series: $replace_count replacements made.\n"; } # series_categories sub do_series_categories($$) { - my ($old, $new) = @_; - my $dbh = Bugzilla->dbh; + my ($old, $new) = @_; + my $dbh = Bugzilla->dbh; - $dbh->do("UPDATE series_categories SET name = ? WHERE name = ?", - undef, - ($new, $old)); + $dbh->do("UPDATE series_categories SET name = ? WHERE name = ?", + undef, ($new, $old)); } ############################################################################# @@ -117,8 +124,8 @@ sub do_series_categories($$) { Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 3) { - usage(); - exit(); + usage(); + exit(); } my ($field, $old, $new) = @ARGV; diff --git a/scripts/generate_bmo_data.pl b/scripts/generate_bmo_data.pl index 8a9f72d17..0f63c8abb 100755 --- a/scripts/generate_bmo_data.pl +++ b/scripts/generate_bmo_data.pl @@ -35,42 +35,42 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); ########################################################################## my %user_prefs = ( - post_bug_submit_action => 'nothing', - bugmail_new_prefix => 'on', - comment_box_position => 'after_comments', - comment_sort_order => 'oldest_to_newest', - csv_colsepchar => ',', - display_quips => 'off', - email_format => 'text_only', - headers_in_body => 'off', - inline_history => 'on', - lang => 'en', - orange_factor => 'off', - per_bug_queries => 'off', - possible_duplicates => 'on', - post_bug_submit_action => 'same_bug', - product_chooser => 'pretty_product_chooser', - quicksearch_fulltext => 'off', - quote_replies => 'quoted_reply', - requestee_cc => 'on', - request_nagging => 'on', - show_gravatars => 'On', - show_my_gravatar => 'On', - skin => 'Mozilla', - state_addselfcc => 'cc_unless_role', - timezone => 'local', - zoom_textareas => 'off', + post_bug_submit_action => 'nothing', + bugmail_new_prefix => 'on', + comment_box_position => 'after_comments', + comment_sort_order => 'oldest_to_newest', + csv_colsepchar => ',', + display_quips => 'off', + email_format => 'text_only', + headers_in_body => 'off', + inline_history => 'on', + lang => 'en', + orange_factor => 'off', + per_bug_queries => 'off', + possible_duplicates => 'on', + post_bug_submit_action => 'same_bug', + product_chooser => 'pretty_product_chooser', + quicksearch_fulltext => 'off', + quote_replies => 'quoted_reply', + requestee_cc => 'on', + request_nagging => 'on', + show_gravatars => 'On', + show_my_gravatar => 'On', + skin => 'Mozilla', + state_addselfcc => 'cc_unless_role', + timezone => 'local', + zoom_textareas => 'off', ); my %opt_param; GetOptions('user-pref=s%' => \%user_prefs, 'param=s' => \%opt_param); my $admin_email = shift || 'admin@mozilla.bugs'; -Bugzilla->set_user(Bugzilla::User->check({ name => $admin_email })); +Bugzilla->set_user(Bugzilla::User->check({name => $admin_email})); foreach my $pref (keys %user_prefs) { - my $value = $user_prefs{$pref}; - Bugzilla::User::Setting::set_default($pref, $value, 1); + my $value = $user_prefs{$pref}; + Bugzilla::User::Setting::set_default($pref, $value, 1); } ############################################################ @@ -78,435 +78,413 @@ foreach my $pref (keys %user_prefs) { ############################################################ my @priorities = qw( - -- - P1 - P2 - P3 - P4 - P5 + -- + P1 + P2 + P3 + P4 + P5 ); if (!$dbh->selectrow_array("SELECT 1 FROM priority WHERE value = 'P1'")) { - $dbh->do("DELETE FROM priority"); - my $count = 100; - foreach my $priority (@priorities) { - $dbh->do("INSERT INTO priority (value, sortkey) VALUES (?, ?)", - undef, ($priority, $count+100)); - } + $dbh->do("DELETE FROM priority"); + my $count = 100; + foreach my $priority (@priorities) { + $dbh->do("INSERT INTO priority (value, sortkey) VALUES (?, ?)", + undef, ($priority, $count + 100)); + } } my @platforms = qw( - All - ARM - x86 - x86_64 - Unspecified - Other + All + ARM + x86 + x86_64 + Unspecified + Other ); if (!$dbh->selectrow_array("SELECT 1 FROM rep_platform WHERE value = 'ARM'")) { - $dbh->do("DELETE FROM rep_platform"); - my $count = 100; - foreach my $platform (@platforms) { - $dbh->do("INSERT INTO rep_platform (value, sortkey) VALUES (?, ?)", - undef, ($platform, $count+100)); - } + $dbh->do("DELETE FROM rep_platform"); + my $count = 100; + foreach my $platform (@platforms) { + $dbh->do("INSERT INTO rep_platform (value, sortkey) VALUES (?, ?)", + undef, ($platform, $count + 100)); + } } -my @oses= ( - 'All', - 'Windows', - 'Windows XP', - 'Windows Server 2008', - 'Windows Vista', - 'Windows 7', - 'Windows 8', - 'Windows 8.1', - 'Windows 10', - 'Windows Phone', - 'Mac OS X', - 'Linux', - 'Gonk (Firefox OS)', - 'Android', - 'iOS', - 'iOS 7', - 'iOS 8', - 'BSDI', - 'FreeBSD', - 'NetBSD', - 'OpenBSD', - 'Unspecified', - 'Other' +my @oses = ( + 'All', + 'Windows', + 'Windows XP', + 'Windows Server 2008', + 'Windows Vista', + 'Windows 7', + 'Windows 8', + 'Windows 8.1', + 'Windows 10', + 'Windows Phone', + 'Mac OS X', + 'Linux', + 'Gonk (Firefox OS)', + 'Android', + 'iOS', + 'iOS 7', + 'iOS 8', + 'BSDI', + 'FreeBSD', + 'NetBSD', + 'OpenBSD', + 'Unspecified', + 'Other' ); if (!$dbh->selectrow_array("SELECT 1 FROM op_sys WHERE value = 'AIX'")) { - $dbh->do("DELETE FROM op_sys"); - my $count = 100; - foreach my $os (@oses) { - $dbh->do("INSERT INTO op_sys (value, sortkey) VALUES (?, ?)", - undef, ($os, $count+100)); - } + $dbh->do("DELETE FROM op_sys"); + my $count = 100; + foreach my $os (@oses) { + $dbh->do("INSERT INTO op_sys (value, sortkey) VALUES (?, ?)", + undef, ($os, $count + 100)); + } } ########################################################################## # Create Users ########################################################################## # First of all, remove the default .* regexp for the editbugs group. -my $group = new Bugzilla::Group({ name => 'editbugs' }); +my $group = new Bugzilla::Group({name => 'editbugs'}); $group->set_user_regexp(''); $group->update(); my @users = ( - { - login => Bugzilla->params->{'nobody_user'}, - realname => 'Nobody; OK to take it and work on it', - password => '*' - }, - { - login => 'automation@bmo.tld', - realname => 'BMO Automation', - password => '*' - }, + { + login => Bugzilla->params->{'nobody_user'}, + realname => 'Nobody; OK to take it and work on it', + password => '*' + }, + {login => 'automation@bmo.tld', realname => 'BMO Automation', password => '*'}, + map { {login => $_, realname => (split(/@/, $_, 2))[0], password => '*',} } map { - { - login => $_, - realname => (split(/@/, $_, 2))[0], - password => '*', - } - } map { - map { @$_ } values %$_ + map {@$_} + values %$_ } values %Bugzilla::Extension::BMO::Data::group_auto_cc, ); print "creating user accounts...\n"; foreach my $user (@users) { - if (is_available_username($user->{login})) { - Bugzilla::User->create( - { login_name => $user->{login}, - realname => $user->{realname}, - cryptpassword => $user->{password}, - } - ); - if ($user->{admin}) { - Bugzilla::Install::make_admin($user->{login}); - } + if (is_available_username($user->{login})) { + Bugzilla::User->create({ + login_name => $user->{login}, + realname => $user->{realname}, + cryptpassword => $user->{password}, + }); + if ($user->{admin}) { + Bugzilla::Install::make_admin($user->{login}); } + } } ########################################################################## # Create Classifications ########################################################################## my @classifications = ( - { - name => "Client Software", - description => "End User Products developed by mozilla.org contributors" - }, - { - name => "Components", - description => "Standalone components that can be used by other products. " . - "Core, Directory, NSPR, NSS and Toolkit are used by Gecko " . - "(which is in turn used by Firefox, Thunderbird, SeaMonkey, " . - "Fennec, and others)", - }, - { - name => "Server Software", - description => "Web Server software developed by mozilla.org contributors " . - "to aid the development of mozilla.org products" - }, - { - name => "Other", - description => "Everything else - websites, Labs, important things which aren't code" - }, - { - name => "Graveyard", - description => "Old, retired products" - }, + { + name => "Client Software", + description => "End User Products developed by mozilla.org contributors" + }, + { + name => "Components", + description => "Standalone components that can be used by other products. " + . "Core, Directory, NSPR, NSS and Toolkit are used by Gecko " + . "(which is in turn used by Firefox, Thunderbird, SeaMonkey, " + . "Fennec, and others)", + }, + { + name => "Server Software", + description => "Web Server software developed by mozilla.org contributors " + . "to aid the development of mozilla.org products" + }, + { + name => "Other", + description => + "Everything else - websites, Labs, important things which aren't code" + }, + {name => "Graveyard", description => "Old, retired products"}, ); print "creating classifications...\n"; for my $class (@classifications) { - my $new_class = Bugzilla::Classification->new({ name => $class->{name} }); - if (!$new_class) { - $dbh->do('INSERT INTO classifications (name, description) VALUES (?, ?)', - undef, ( $class->{name}, $class->{description} )); - } + my $new_class = Bugzilla::Classification->new({name => $class->{name}}); + if (!$new_class) { + $dbh->do('INSERT INTO classifications (name, description) VALUES (?, ?)', + undef, ($class->{name}, $class->{description})); + } } ########################################################################## # Create Some Products ########################################################################## my @products = ( - { - classification => 'Client Software', - product_name => 'Firefox', - description => 'For bugs in Firefox Desktop, the Mozilla Foundations ' . - 'web browser. For Firefox user interface issues in ' . - 'menus, developer tools, bookmarks, location bar, and ' . - 'preferences. Many Firefox bugs will either be filed ' . - 'here or in the <a href="https://bugzilla.mozilla.org/describecomponents.cgi?product=Core">Core</a> product.' . - '(<a href="https://wiki.mozilla.org/Modules/All#Firefox">more info</a>)', - versions => [ - '34 Branch', - '35 Branch', - '36 Branch', - '37 Branch', - 'Trunk', - 'unspecified' - ], - milestones => [ - 'Firefox 36', - '---', - 'Firefox 37', - 'Firefox 38', - 'Firefox 39', - 'Future' - ], - defaultmilestone => '---', - components => [ - { - name => 'General', - description => 'For bugs in Firefox which do not fit into ' . - 'other more specific Firefox components', - initialowner => Bugzilla->params->{'nobody_user'}, - initialqaowner => '', - initial_cc => [], - watch_user => 'general@firefox.bugs' - } - ], - }, - { - classification => 'Other', - product_name => 'bugzilla.mozilla.org', - description => 'For issues relating to the bugzilla.mozilla.org website, ' - . 'also known as <a href="https://wiki.mozilla.org/BMO">BMO</a>.', - versions => ['Development/Staging', 'Production'], - milestones => [ '---' ], - defaultmilestone => '---', - components => [ - { - name => 'General', - description => 'This is the component for issues specific to bugzilla.mozilla.org ' - . 'that do not belong in other components.', - initialowner => Bugzilla->params->{'nobody_user'}, - initialqaowner => '', - initial_cc => [], - watch_user => 'general@bugzilla.bugs' - } - ], - }, + { + classification => 'Client Software', + product_name => 'Firefox', + description => 'For bugs in Firefox Desktop, the Mozilla Foundations ' + . 'web browser. For Firefox user interface issues in ' + . 'menus, developer tools, bookmarks, location bar, and ' + . 'preferences. Many Firefox bugs will either be filed ' + . 'here or in the <a href="https://bugzilla.mozilla.org/describecomponents.cgi?product=Core">Core</a> product.' + . '(<a href="https://wiki.mozilla.org/Modules/All#Firefox">more info</a>)', + versions => + ['34 Branch', '35 Branch', '36 Branch', '37 Branch', 'Trunk', 'unspecified'], + milestones => + ['Firefox 36', '---', 'Firefox 37', 'Firefox 38', 'Firefox 39', 'Future'], + defaultmilestone => '---', + components => [{ + name => 'General', + description => 'For bugs in Firefox which do not fit into ' + . 'other more specific Firefox components', + initialowner => Bugzilla->params->{'nobody_user'}, + initialqaowner => '', + initial_cc => [], + watch_user => 'general@firefox.bugs' + }], + }, + { + classification => 'Other', + product_name => 'bugzilla.mozilla.org', + description => 'For issues relating to the bugzilla.mozilla.org website, ' + . 'also known as <a href="https://wiki.mozilla.org/BMO">BMO</a>.', + versions => ['Development/Staging', 'Production'], + milestones => ['---'], + defaultmilestone => '---', + components => [{ + name => 'General', + description => + 'This is the component for issues specific to bugzilla.mozilla.org ' + . 'that do not belong in other components.', + initialowner => Bugzilla->params->{'nobody_user'}, + initialqaowner => '', + initial_cc => [], + watch_user => 'general@bugzilla.bugs' + }], + }, ); my $default_op_sys_id - = $dbh->selectrow_array("SELECT id FROM op_sys WHERE value = 'Unspecified'"); -my $default_platform_id - = $dbh->selectrow_array("SELECT id FROM rep_platform WHERE value = 'Unspecified'"); + = $dbh->selectrow_array("SELECT id FROM op_sys WHERE value = 'Unspecified'"); +my $default_platform_id = $dbh->selectrow_array( + "SELECT id FROM rep_platform WHERE value = 'Unspecified'"); print "creating products...\n"; for my $product (@products) { - my $new_product = - Bugzilla::Product->new({ name => $product->{product_name} }); - if (!$new_product) { - my $class_id = 1; - if ($product->{classification}) { - $class_id = Bugzilla::Classification->new({ name => $product->{classification} })->id; - } - $dbh->do('INSERT INTO products (name, description, classification_id, + my $new_product = Bugzilla::Product->new({name => $product->{product_name}}); + if (!$new_product) { + my $class_id = 1; + if ($product->{classification}) { + $class_id + = Bugzilla::Classification->new({name => $product->{classification}})->id; + } + $dbh->do( + 'INSERT INTO products (name, description, classification_id, default_op_sys_id, default_platform_id) VALUES (?, ?, ?, ?, ?)', - undef, ( $product->{product_name}, $product->{description}, - $class_id, $default_op_sys_id, $default_platform_id )); - - $new_product - = new Bugzilla::Product( { name => $product->{product_name} } ); - - $dbh->do( 'INSERT INTO milestones (product_id, value) VALUES (?, ?)', - undef, ( $new_product->id, $product->{defaultmilestone} ) ); - - # Now clear the internal list of accessible products. - delete Bugzilla->user->{selectable_products}; - - foreach my $component (@{ $product->{components} }) { - if (!Bugzilla::User->new({ name => $component->{watch_user} })) { - Bugzilla::User->create({ - login_name => $component->{watch_user}, - cryptpassword => '*', - }); - } - Bugzilla->input_params({ watch_user => $component->{watch_user} }); - Bugzilla::Component->create({ - name => $component->{name}, - product => $new_product, - description => $component->{description}, - initialowner => $component->{initialowner}, - initialqacontact => $component->{initialqacontact} || '', - initial_cc => $component->{initial_cc} || [], - }); - } + undef, + ( + $product->{product_name}, $product->{description}, $class_id, + $default_op_sys_id, $default_platform_id + ) + ); + + $new_product = new Bugzilla::Product({name => $product->{product_name}}); + + $dbh->do('INSERT INTO milestones (product_id, value) VALUES (?, ?)', + undef, ($new_product->id, $product->{defaultmilestone})); + + # Now clear the internal list of accessible products. + delete Bugzilla->user->{selectable_products}; + + foreach my $component (@{$product->{components}}) { + if (!Bugzilla::User->new({name => $component->{watch_user}})) { + Bugzilla::User->create({ + login_name => $component->{watch_user}, cryptpassword => '*', + }); + } + Bugzilla->input_params({watch_user => $component->{watch_user}}); + Bugzilla::Component->create({ + name => $component->{name}, + product => $new_product, + description => $component->{description}, + initialowner => $component->{initialowner}, + initialqacontact => $component->{initialqacontact} || '', + initial_cc => $component->{initial_cc} || [], + }); } + } - foreach my $version (@{ $product->{versions} }) { - if (!new Bugzilla::Version({ name => $version, - product => $new_product })) - { - Bugzilla::Version->create({value => $version, product => $new_product}); - } + foreach my $version (@{$product->{versions}}) { + if (!new Bugzilla::Version({name => $version, product => $new_product})) { + Bugzilla::Version->create({value => $version, product => $new_product}); } + } - foreach my $milestone (@{ $product->{milestones} }) { - if (!new Bugzilla::Milestone({ name => $milestone, - product => $new_product })) - { - $dbh->do('INSERT INTO milestones (product_id, value) VALUES (?,?)', - undef, $new_product->id, $milestone); - } + foreach my $milestone (@{$product->{milestones}}) { + if (!new Bugzilla::Milestone({name => $milestone, product => $new_product})) { + $dbh->do('INSERT INTO milestones (product_id, value) VALUES (?,?)', + undef, $new_product->id, $milestone); } + } } ########################################################################## # Create Groups ########################################################################## my @groups = ( - { - name => 'core-security', - description => 'Security-Sensitive Core Bug', - no_admin => 1, - bug_group => 1, - all_products => 1, - }, - { - name => 'core-security-release', - description => 'Release-track Client Security Bug', - no_admin => 1, - bug_group => 1, - all_products => 1, - }, - { - name => 'core-security-release', - description => 'Release-track Client Security Bug', - no_admin => 1, - bug_group => 1, - all_products => 1, - }, - { - name => 'core-security-release', - description => 'Release-track Client Security Bug', - no_admin => 1, - bug_group => 1, - all_products => 1, - }, - { - name => 'can_edit_comments', - description => 'Members of this group will be able to edit comments', - no_admin => 0, - bug_group => 0, - all_products => 0, - }, - { - name => 'can_restrict_comments', - description => 'Members of this group will be able to restrict comments on bugs', - no_admin => 0, - all_products => 0, - bug_group => 0, - }, - { - name => 'timetrackers', - description => 'Time Trackers', - no_admin => 1, - all_products => 0, - bug_group => 0, - }, - { - name => 'partner-confidential', - description => 'Restrict the visibility of this bug to the assignee, QA contact, and CC list only.', - no_admin => 1, - all_products => 0, - bug_group => 1, - }, - { - name => 'partner-confidential-visible', - description => 'Members of this group will be able to use the partner-confidential group when filing bugs', - no_admin => 0, - all_products => 0, - bug_group => 0, - }, + { + name => 'core-security', + description => 'Security-Sensitive Core Bug', + no_admin => 1, + bug_group => 1, + all_products => 1, + }, + { + name => 'core-security-release', + description => 'Release-track Client Security Bug', + no_admin => 1, + bug_group => 1, + all_products => 1, + }, + { + name => 'core-security-release', + description => 'Release-track Client Security Bug', + no_admin => 1, + bug_group => 1, + all_products => 1, + }, + { + name => 'core-security-release', + description => 'Release-track Client Security Bug', + no_admin => 1, + bug_group => 1, + all_products => 1, + }, + { + name => 'can_edit_comments', + description => 'Members of this group will be able to edit comments', + no_admin => 0, + bug_group => 0, + all_products => 0, + }, + { + name => 'can_restrict_comments', + description => + 'Members of this group will be able to restrict comments on bugs', + no_admin => 0, + all_products => 0, + bug_group => 0, + }, + { + name => 'timetrackers', + description => 'Time Trackers', + no_admin => 1, + all_products => 0, + bug_group => 0, + }, + { + name => 'partner-confidential', + description => + 'Restrict the visibility of this bug to the assignee, QA contact, and CC list only.', + no_admin => 1, + all_products => 0, + bug_group => 1, + }, + { + name => 'partner-confidential-visible', + description => + 'Members of this group will be able to use the partner-confidential group when filing bugs', + no_admin => 0, + all_products => 0, + bug_group => 0, + }, ); print "creating groups...\n"; foreach my $group (@groups) { - my $name = $group->{name}; - my $desc = $group->{desc}; - my $bug_group = exists $group->{bug_group} ? $group->{bug_group} : 1; - my $no_admin = exists $group->{no_admin} ? $group->{no_admin} : 0; - - if (!Bugzilla::Group->new({ name => $name })) { - my $new_group; - if (exists $group->{no_admin} && $group->{no_admin}) { - $dbh->do('INSERT INTO groups (name, description, isbuggroup, isactive) - VALUES (?, ?, 1, 1)', - undef, ($group->{name}, $group->{description})); - $new_group = Bugzilla::Group->new({ name => $group->{name} }); - } - else { - $new_group - = Bugzilla::Group->create({ name => $group->{name}, - description => $group->{description}, - isbuggroup => $group->{bug_group} }); - } - - if (exists $group->{all_products} && $group->{all_products}) { - $dbh->do('INSERT INTO group_control_map + my $name = $group->{name}; + my $desc = $group->{desc}; + my $bug_group = exists $group->{bug_group} ? $group->{bug_group} : 1; + my $no_admin = exists $group->{no_admin} ? $group->{no_admin} : 0; + + if (!Bugzilla::Group->new({name => $name})) { + my $new_group; + if (exists $group->{no_admin} && $group->{no_admin}) { + $dbh->do( + 'INSERT INTO groups (name, description, isbuggroup, isactive) + VALUES (?, ?, 1, 1)', undef, + ($group->{name}, $group->{description}) + ); + $new_group = Bugzilla::Group->new({name => $group->{name}}); + } + else { + $new_group = Bugzilla::Group->create({ + name => $group->{name}, + description => $group->{description}, + isbuggroup => $group->{bug_group} + }); + } + + if (exists $group->{all_products} && $group->{all_products}) { + $dbh->do( + 'INSERT INTO group_control_map (group_id, product_id, entry, membercontrol, othercontrol, canedit) - SELECT ?, products.id, 0, ?, ?, 0 FROM products', - undef, ( $new_group->id, CONTROLMAPSHOWN, CONTROLMAPSHOWN ) ); - } + SELECT ?, products.id, 0, ?, ?, 0 FROM products', undef, + ($new_group->id, CONTROLMAPSHOWN, CONTROLMAPSHOWN) + ); } + } } -my @fields = ( - { - name => 'cf_due_date', - description => 'Due Date', - type => FIELD_TYPE_DATE, - sortkey => 949, - mailhead => 0, - enter_bug => 1, - obsolete => 0, - custom => 1, - buglist => 1, - reverse_desc => "", - is_mandatory => 0, - } -); +my @fields = ({ + name => 'cf_due_date', + description => 'Due Date', + type => FIELD_TYPE_DATE, + sortkey => 949, + mailhead => 0, + enter_bug => 1, + obsolete => 0, + custom => 1, + buglist => 1, + reverse_desc => "", + is_mandatory => 0, +}); say 'creating custom fields'; foreach my $field (@fields) { - next if Bugzilla::Field->new({name => $field->{name}}); - my $field_obj = Bugzilla::Field->create( - { - name => $field->{name}, - description => $field->{description}, - type => $field->{type}, - sortkey => $field->{sortkey}, - mailhead => $field->{new_bugmail}, - enter_bug => $field->{enter_bug}, - obsolete => $field->{obsolete}, - custom => 1, - buglist => 1, - visibility_field_id => $field->{visibility_field_id}, - visibility_values => $field->{visibility_values}, - value_field_id => $field->{value_field_id}, - reverse_desc => $field->{reverse_desc}, - is_mandatory => $field->{is_mandatory}, - } - ); + next if Bugzilla::Field->new({name => $field->{name}}); + my $field_obj = Bugzilla::Field->create({ + name => $field->{name}, + description => $field->{description}, + type => $field->{type}, + sortkey => $field->{sortkey}, + mailhead => $field->{new_bugmail}, + enter_bug => $field->{enter_bug}, + obsolete => $field->{obsolete}, + custom => 1, + buglist => 1, + visibility_field_id => $field->{visibility_field_id}, + visibility_values => $field->{visibility_values}, + value_field_id => $field->{value_field_id}, + reverse_desc => $field->{reverse_desc}, + is_mandatory => $field->{is_mandatory}, + }); } # Update default security group settings for new products -my $default_security_group = Bugzilla::Group->new({ name => 'core-security' }); +my $default_security_group = Bugzilla::Group->new({name => 'core-security'}); if ($default_security_group) { - $dbh->do('UPDATE products SET security_group_id = ? WHERE security_group_id IS NULL', - undef, $default_security_group->id); + $dbh->do( + 'UPDATE products SET security_group_id = ? WHERE security_group_id IS NULL', + undef, $default_security_group->id); } ########################################################################## @@ -514,62 +492,63 @@ if ($default_security_group) { ########################################################################## my %set_params = ( - allowbugdeletion => 1, - allowuserdeletion => 0, - allow_attachment_deletion => 1, - bonsai_url => 'http://bonsai.mozilla.org', - collapsed_comment_tags => 'obsolete,spam,typo,me-too,advocacy,off-topic,offtopic,abuse,abusive', - confirmuniqueusermatch => 0, - maxusermatches => '100', - debug_group => 'editbugs', - defaultpriority => '--', # FIXME: add priority - defaultquery => 'resolution=---&emailassigned_to1=1&emailassigned_to2=1' . - '&emailreporter2=1&emailqa_contact2=1&emailtype1=exact' . - '&emailtype2=exact&order=Importance&keywords_type=allwords' . - '&long_desc_type=substring', - defaultseverity => 'normal', - edit_comments_group => 'can_edit_comments', - insidergroup => 'core-security-release', - last_visit_keep_days => '28', - lxr_url => 'http://mxr.mozilla.org/mozilla', - lxr_root => 'mozilla/', - mail_delivery_method => 'Test', - mailfrom => '"Bugzilla@Mozilla" <bugzilla-daemon@mozilla.org>', - maintainer => 'bugzilla-admin@mozilla.org', - maxattachmentsize => '10240', - maxusermatches => '100', - mostfreqthreshold => '5', - mybugstemplate => 'buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW' . - '&bug_status=ASSIGNED&bug_status=REOPENED' . - '&emailassigned_to1=1&emailreporter1=1' . - '&emailtype1=exact&email1=%userid%' . - '&field0-0-0=bug_status&type0-0-0=notequals' . - '&value0-0-0=UNCONFIRMED&field0-0-1=reporter' . - '&type0-0-1=equals&value0-0-1=%userid%', - quip_list_entry_control => 'moderated', - restrict_comments_group => 'editbugs', - restrict_comments_enable_group => 'can_restrict_comments', - search_allow_no_criteria => 0, - strict_transport_security => 'include_subdomains', - timetrackinggroup => 'timetrackers', - upgrade_notification => 'disabled', - useclassification => 1, - usetargetmilestone => 1, - usestatuswhiteboard => 1, - usebugaliases => 1, - useqacontact => 1, - use_mailer_queue => 1, - user_info_class => 'GitHubAuth,CGI', - user_verify_class => 'GitHubAuth,DB', - %opt_param, + allowbugdeletion => 1, + allowuserdeletion => 0, + allow_attachment_deletion => 1, + bonsai_url => 'http://bonsai.mozilla.org', + collapsed_comment_tags => + 'obsolete,spam,typo,me-too,advocacy,off-topic,offtopic,abuse,abusive', + confirmuniqueusermatch => 0, + maxusermatches => '100', + debug_group => 'editbugs', + defaultpriority => '--', # FIXME: add priority + defaultquery => 'resolution=---&emailassigned_to1=1&emailassigned_to2=1' + . '&emailreporter2=1&emailqa_contact2=1&emailtype1=exact' + . '&emailtype2=exact&order=Importance&keywords_type=allwords' + . '&long_desc_type=substring', + defaultseverity => 'normal', + edit_comments_group => 'can_edit_comments', + insidergroup => 'core-security-release', + last_visit_keep_days => '28', + lxr_url => 'http://mxr.mozilla.org/mozilla', + lxr_root => 'mozilla/', + mail_delivery_method => 'Test', + mailfrom => '"Bugzilla@Mozilla" <bugzilla-daemon@mozilla.org>', + maintainer => 'bugzilla-admin@mozilla.org', + maxattachmentsize => '10240', + maxusermatches => '100', + mostfreqthreshold => '5', + mybugstemplate => 'buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW' + . '&bug_status=ASSIGNED&bug_status=REOPENED' + . '&emailassigned_to1=1&emailreporter1=1' + . '&emailtype1=exact&email1=%userid%' + . '&field0-0-0=bug_status&type0-0-0=notequals' + . '&value0-0-0=UNCONFIRMED&field0-0-1=reporter' + . '&type0-0-1=equals&value0-0-1=%userid%', + quip_list_entry_control => 'moderated', + restrict_comments_group => 'editbugs', + restrict_comments_enable_group => 'can_restrict_comments', + search_allow_no_criteria => 0, + strict_transport_security => 'include_subdomains', + timetrackinggroup => 'timetrackers', + upgrade_notification => 'disabled', + useclassification => 1, + usetargetmilestone => 1, + usestatuswhiteboard => 1, + usebugaliases => 1, + useqacontact => 1, + use_mailer_queue => 1, + user_info_class => 'GitHubAuth,CGI', + user_verify_class => 'GitHubAuth,DB', + %opt_param, ); my $params_modified; foreach my $param (keys %set_params) { - my $value = $set_params{$param}; - next unless defined $value && Bugzilla->params->{$param} ne $value; - SetParam($param, $value); - $params_modified = 1; + my $value = $set_params{$param}; + next unless defined $value && Bugzilla->params->{$param} ne $value; + SetParam($param, $value); + $params_modified = 1; } write_params() if $params_modified; @@ -578,64 +557,75 @@ write_params() if $params_modified; # Create flag types ########################################################################## my @flagtypes = ( - { - name => 'review', - desc => 'The patch has passed review by a module owner or peer.', - is_requestable => 1, - is_requesteeble => 1, - is_multiplicable => 1, - grant_group => '', - target_type => 'a', - cc_list => '', - inclusions => [''] - }, - { - name => 'feedback', - desc => 'A particular person\'s input is requested for a patch, ' . - 'but that input does not amount to an official review.', - is_requestable => 1, - is_requesteeble => 1, - is_multiplicable => 1, - grant_group => '', - target_type => 'a', - cc_list => '', - inclusions => [''] - } + { + name => 'review', + desc => 'The patch has passed review by a module owner or peer.', + is_requestable => 1, + is_requesteeble => 1, + is_multiplicable => 1, + grant_group => '', + target_type => 'a', + cc_list => '', + inclusions => [''] + }, + { + name => 'feedback', + desc => 'A particular person\'s input is requested for a patch, ' + . 'but that input does not amount to an official review.', + is_requestable => 1, + is_requesteeble => 1, + is_multiplicable => 1, + grant_group => '', + target_type => 'a', + cc_list => '', + inclusions => [''] + } ); print "creating flag types...\n"; foreach my $flag (@flagtypes) { - next if new Bugzilla::FlagType({ name => $flag->{name} }); - my $grant_group_id = $flag->{grant_group} - ? Bugzilla::Group->new({ name => $flag->{grant_group} })->id - : undef; - my $request_group_id = $flag->{request_group} - ? Bugzilla::Group->new({ name => $flag->{request_group} })->id - : undef; - - $dbh->do('INSERT INTO flagtypes (name, description, cc_list, target_type, is_requestable, + next if new Bugzilla::FlagType({name => $flag->{name}}); + my $grant_group_id + = $flag->{grant_group} + ? Bugzilla::Group->new({name => $flag->{grant_group}})->id + : undef; + my $request_group_id + = $flag->{request_group} + ? Bugzilla::Group->new({name => $flag->{request_group}})->id + : undef; + + $dbh->do( + 'INSERT INTO flagtypes (name, description, cc_list, target_type, is_requestable, is_requesteeble, is_multiplicable, grant_group_id, request_group_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', - undef, ($flag->{name}, $flag->{desc}, $flag->{cc_list}, $flag->{target_type}, - $flag->{is_requestable}, $flag->{is_requesteeble}, $flag->{is_multiplicable}, - $grant_group_id, $request_group_id)); - - my $type_id = $dbh->bz_last_key('flagtypes', 'id'); - - foreach my $inclusion (@{$flag->{inclusions}}) { - my ($product, $component) = split(':', $inclusion); - my ($prod_id, $comp_id); - if ($product) { - my $prod_obj = Bugzilla::Product->new({ name => $product }); - $prod_id = $prod_obj->id; - if ($component) { - $comp_id = Bugzilla::Component->new({ name => $component, product => $prod_obj})->id; - } - } - $dbh->do('INSERT INTO flaginclusions (type_id, product_id, component_id) - VALUES (?, ?, ?)', - undef, ($type_id, $prod_id, $comp_id)); + undef, + ( + $flag->{name}, $flag->{desc}, + $flag->{cc_list}, $flag->{target_type}, + $flag->{is_requestable}, $flag->{is_requesteeble}, + $flag->{is_multiplicable}, $grant_group_id, + $request_group_id + ) + ); + + my $type_id = $dbh->bz_last_key('flagtypes', 'id'); + + foreach my $inclusion (@{$flag->{inclusions}}) { + my ($product, $component) = split(':', $inclusion); + my ($prod_id, $comp_id); + if ($product) { + my $prod_obj = Bugzilla::Product->new({name => $product}); + $prod_id = $prod_obj->id; + if ($component) { + $comp_id + = Bugzilla::Component->new({name => $component, product => $prod_obj})->id; + } } + $dbh->do( + 'INSERT INTO flaginclusions (type_id, product_id, component_id) + VALUES (?, ?, ?)', undef, ($type_id, $prod_id, $comp_id) + ); + } } ########################################################### @@ -643,91 +633,100 @@ foreach my $flag (@flagtypes) { ########################################################### my @statuses = ( - { - value => undef, - transitions => [['UNCONFIRMED', 0], ['NEW', 0], ['ASSIGNED', 0]], - }, - { - value => 'UNCONFIRMED', - sortkey => 100, - isactive => 1, - isopen => 1, - transitions => [['NEW', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], - }, - { - value => 'NEW', - sortkey => 200, - isactive => 1, - isopen => 1, - transitions => [['UNCONFIRMED', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], - }, - { - value => 'ASSIGNED', - sortkey => 300, - isactive => 1, - isopen => 1, - transitions => [['UNCONFIRMED', 0], ['NEW', 0], ['RESOLVED', 0]], - }, - { - value => 'REOPENED', - sortkey => 400, - isactive => 1, - isopen => 1, - transitions => [['UNCONFIRMED', 0], ['NEW', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], - }, - { - value => 'RESOLVED', - sortkey => 500, - isactive => 1, - isopen => 0, - transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['VERIFIED', 0]], - }, - { - value => 'VERIFIED', - sortkey => 600, - isactive => 1, - isopen => 0, - transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['RESOLVED', 0]], - }, - { - value => 'CLOSED', - sortkey => 700, - isactive => 1, - isopen => 0, - transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['RESOLVED', 0]], - }, + { + value => undef, + transitions => [['UNCONFIRMED', 0], ['NEW', 0], ['ASSIGNED', 0]], + }, + { + value => 'UNCONFIRMED', + sortkey => 100, + isactive => 1, + isopen => 1, + transitions => [['NEW', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], + }, + { + value => 'NEW', + sortkey => 200, + isactive => 1, + isopen => 1, + transitions => [['UNCONFIRMED', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], + }, + { + value => 'ASSIGNED', + sortkey => 300, + isactive => 1, + isopen => 1, + transitions => [['UNCONFIRMED', 0], ['NEW', 0], ['RESOLVED', 0]], + }, + { + value => 'REOPENED', + sortkey => 400, + isactive => 1, + isopen => 1, + transitions => + [['UNCONFIRMED', 0], ['NEW', 0], ['ASSIGNED', 0], ['RESOLVED', 0]], + }, + { + value => 'RESOLVED', + sortkey => 500, + isactive => 1, + isopen => 0, + transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['VERIFIED', 0]], + }, + { + value => 'VERIFIED', + sortkey => 600, + isactive => 1, + isopen => 0, + transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['RESOLVED', 0]], + }, + { + value => 'CLOSED', + sortkey => 700, + isactive => 1, + isopen => 0, + transitions => [['UNCONFIRMED', 0], ['REOPENED', 0], ['RESOLVED', 0]], + }, ); -if (!$dbh->selectrow_array("SELECT 1 FROM bug_status WHERE value = 'ASSIGNED'")) { - $dbh->do('DELETE FROM bug_status'); - $dbh->do('DELETE FROM status_workflow'); +if (!$dbh->selectrow_array("SELECT 1 FROM bug_status WHERE value = 'ASSIGNED'")) +{ + $dbh->do('DELETE FROM bug_status'); + $dbh->do('DELETE FROM status_workflow'); - print "creating status workflow...\n"; + print "creating status workflow...\n"; - # One pass to add the status entries. - foreach my $status (@statuses) { - next if !$status->{value}; - $dbh->do('INSERT INTO bug_status (value, sortkey, isactive, is_open) VALUES (?, ?, ?, ?)', - undef, ( $status->{value}, $status->{sortkey}, $status->{isactive}, $status->{isopen} )); + # One pass to add the status entries. + foreach my $status (@statuses) { + next if !$status->{value}; + $dbh->do( + 'INSERT INTO bug_status (value, sortkey, isactive, is_open) VALUES (?, ?, ?, ?)', + undef, + ($status->{value}, $status->{sortkey}, $status->{isactive}, $status->{isopen}) + ); + } + + # Another pass to add the transitions. + foreach my $status (@statuses) { + my $old_id; + if ($status->{value}) { + my $from_status = new Bugzilla::Status({name => $status->{value}}); + $old_id = $from_status->{id}; + } + else { + $old_id = undef; } - # Another pass to add the transitions. - foreach my $status (@statuses) { - my $old_id; - if ($status->{value}) { - my $from_status = new Bugzilla::Status({ name => $status->{value} }); - $old_id = $from_status->{id}; - } else { - $old_id = undef; - } - - foreach my $transition (@{$status->{transitions}}) { - my $to_status = new Bugzilla::Status({ name => $transition->[0] }); - - $dbh->do('INSERT INTO status_workflow (old_status, new_status, require_comment) VALUES (?, ?, ?)', - undef, ( $old_id, $to_status->{id}, $transition->[1] )); - } + foreach my $transition (@{$status->{transitions}}) { + my $to_status = new Bugzilla::Status({name => $transition->[0]}); + + $dbh->do( + 'INSERT INTO status_workflow (old_status, new_status, require_comment) VALUES (?, ?, ?)', + undef, + ($old_id, $to_status->{id}, $transition->[1]) + ); } + } } ########################################################### @@ -735,66 +734,28 @@ if (!$dbh->selectrow_array("SELECT 1 FROM bug_status WHERE value = 'ASSIGNED'")) ########################################################### my @resolutions = ( - { - value => '', - sortkey => 100, - isactive => 1, - }, - { - value => 'FIXED', - sortkey => 200, - isactive => 1, - }, - { - value => 'INVALID', - sortkey => 300, - isactive => 1, - }, - { - value => 'WONTFIX', - sortkey => 400, - isactive => 1, - }, - { - value => 'DUPLICATE', - sortkey => 700, - isactive => 1, - }, - { - value => 'WORKSFORME', - sortkey => 800, - isactive => 1, - }, - { - value => 'EXPIRED', - sortkey => 900, - isactive => 1, - }, - { - value => 'MOVED', - sortkey => 1000, - isactive => 0, - }, - { - value => 'INCOMPLETE', - sortkey => 850, - isactive => 1, - }, - { - value => 'SUPPORT', - sortkey => 875, - isactive => 0, - }, + {value => '', sortkey => 100, isactive => 1,}, + {value => 'FIXED', sortkey => 200, isactive => 1,}, + {value => 'INVALID', sortkey => 300, isactive => 1,}, + {value => 'WONTFIX', sortkey => 400, isactive => 1,}, + {value => 'DUPLICATE', sortkey => 700, isactive => 1,}, + {value => 'WORKSFORME', sortkey => 800, isactive => 1,}, + {value => 'EXPIRED', sortkey => 900, isactive => 1,}, + {value => 'MOVED', sortkey => 1000, isactive => 0,}, + {value => 'INCOMPLETE', sortkey => 850, isactive => 1,}, + {value => 'SUPPORT', sortkey => 875, isactive => 0,}, ); -if (!$dbh->selectrow_array("SELECT 1 FROM resolution WHERE value = 'INCOMPLETE'")) { - $dbh->do('DELETE FROM resolution'); - print "creating resolutions...\n"; - foreach my $resolution (@resolutions) { - next if !$resolution->{value}; - $dbh->do('INSERT INTO resolution (value, sortkey, isactive) VALUES (?, ?, ?)', - undef, ($resolution->{value}, $resolution->{sortkey}, $resolution->{isactive})); - } +if (!$dbh->selectrow_array( + "SELECT 1 FROM resolution WHERE value = 'INCOMPLETE'")) +{ + $dbh->do('DELETE FROM resolution'); + print "creating resolutions...\n"; + foreach my $resolution (@resolutions) { + next if !$resolution->{value}; + $dbh->do('INSERT INTO resolution (value, sortkey, isactive) VALUES (?, ?, ?)', + undef, ($resolution->{value}, $resolution->{sortkey}, $resolution->{isactive})); + } } ########################################################### @@ -802,22 +763,22 @@ if (!$dbh->selectrow_array("SELECT 1 FROM resolution WHERE value = 'INCOMPLETE'" ########################################################### my @keywords = ( - { - name => 'regression', - description => 'The problem was fixed, but then it came back (regressed) ' . - 'and this new bug was filed to track the regression.' - }, - { - name => 'relnote', - description => 'This bug need to be put on release notes for next ' . - 'milestone announcement.' - }, + { + name => 'regression', + description => 'The problem was fixed, but then it came back (regressed) ' + . 'and this new bug was filed to track the regression.' + }, + { + name => 'relnote', + description => 'This bug need to be put on release notes for next ' + . 'milestone announcement.' + }, ); print "creating keywords...\n"; foreach my $kw (@keywords) { - next if new Bugzilla::Keyword({ name => $kw->{name} }); - Bugzilla::Keyword->create($kw); + next if new Bugzilla::Keyword({name => $kw->{name}}); + Bugzilla::Keyword->create($kw); } print "installation and configuration complete!\n"; diff --git a/scripts/generate_conduit_data.pl b/scripts/generate_conduit_data.pl index 627f3a199..89668a6a3 100755 --- a/scripts/generate_conduit_data.pl +++ b/scripts/generate_conduit_data.pl @@ -15,7 +15,7 @@ use Bugzilla::User; use Bugzilla::User::APIKey; BEGIN { - Bugzilla->extensions; + Bugzilla->extensions; } my $dbh = Bugzilla->dbh; @@ -24,7 +24,7 @@ my $dbh = Bugzilla->dbh; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $admin_email = shift || 'admin@mozilla.bugs'; -Bugzilla->set_user( Bugzilla::User->check( { name => $admin_email } ) ); +Bugzilla->set_user(Bugzilla::User->check({name => $admin_email})); ########################################################################## # Create Conduit Test Users @@ -35,49 +35,47 @@ my $conduit_password = $ENV{CONDUIT_USER_PASSWORD} || 'password123456789!'; my $conduit_api_key = $ENV{CONDUIT_USER_API_KEY} || ''; print "creating conduit developer user account...\n"; -if ( !Bugzilla::User->new( { name => $conduit_login } ) ) { - my $new_user = Bugzilla::User->create( - { - login_name => $conduit_login, - realname => 'Conduit Developer', - cryptpassword => $conduit_password - }, - ); - - if ($conduit_api_key) { - Bugzilla::User::APIKey->create_special( - { - user_id => $new_user->id, - description => 'API key for Conduit Developer', - api_key => $conduit_api_key - } - ); - } +if (!Bugzilla::User->new({name => $conduit_login})) { + my $new_user = Bugzilla::User->create( + { + login_name => $conduit_login, + realname => 'Conduit Developer', + cryptpassword => $conduit_password + }, + ); + + if ($conduit_api_key) { + Bugzilla::User::APIKey->create_special({ + user_id => $new_user->id, + description => 'API key for Conduit Developer', + api_key => $conduit_api_key + }); + } } -my $conduit_reviewer_login = $ENV{CONDUIT_REVIEWER_USER_LOGIN} || 'conduit-reviewer@mozilla.bugs'; -my $conduit_reviewer_password = $ENV{CONDUIT_REVIEWER_USER_PASSWORD} || 'password123456789!'; -my $conduit_reviewer_api_key = $ENV{CONDUIT_REVIEWER_USER_API_KEY} || ''; +my $conduit_reviewer_login + = $ENV{CONDUIT_REVIEWER_USER_LOGIN} || 'conduit-reviewer@mozilla.bugs'; +my $conduit_reviewer_password + = $ENV{CONDUIT_REVIEWER_USER_PASSWORD} || 'password123456789!'; +my $conduit_reviewer_api_key = $ENV{CONDUIT_REVIEWER_USER_API_KEY} || ''; print "creating conduit reviewer user account...\n"; -if ( !Bugzilla::User->new( { name => $conduit_reviewer_login } ) ) { - my $new_user = Bugzilla::User->create( - { - login_name => $conduit_reviewer_login, - realname => 'Conduit Reviewer', - cryptpassword => $conduit_reviewer_password - }, - ); - - if ($conduit_reviewer_api_key) { - Bugzilla::User::APIKey->create_special( - { - user_id => $new_user->id, - description => 'API key for Conduit Reviewer', - api_key => $conduit_reviewer_api_key - } - ); - } +if (!Bugzilla::User->new({name => $conduit_reviewer_login})) { + my $new_user = Bugzilla::User->create( + { + login_name => $conduit_reviewer_login, + realname => 'Conduit Reviewer', + cryptpassword => $conduit_reviewer_password + }, + ); + + if ($conduit_reviewer_api_key) { + Bugzilla::User::APIKey->create_special({ + user_id => $new_user->id, + description => 'API key for Conduit Reviewer', + api_key => $conduit_reviewer_api_key + }); + } } ########################################################################## @@ -89,115 +87,117 @@ my $phab_password = $ENV{PHABRICATOR_BOT_PASSWORD} || 'password123456789!'; my $phab_api_key = $ENV{PHABRICATOR_BOT_API_KEY} || ''; print "creating phabricator automation account...\n"; -if ( !Bugzilla::User->new( { name => $phab_login } ) ) { - my $new_user = Bugzilla::User->create( - { - login_name => $phab_login, - realname => 'Phabricator Automation', - cryptpassword => $phab_password - }, - ); - - if ($phab_api_key) { - Bugzilla::User::APIKey->create_special( - { - user_id => $new_user->id, - description => 'API key for Phabricator Automation', - api_key => $phab_api_key - } - ); - } +if (!Bugzilla::User->new({name => $phab_login})) { + my $new_user = Bugzilla::User->create( + { + login_name => $phab_login, + realname => 'Phabricator Automation', + cryptpassword => $phab_password + }, + ); + + if ($phab_api_key) { + Bugzilla::User::APIKey->create_special({ + user_id => $new_user->id, + description => 'API key for Phabricator Automation', + api_key => $phab_api_key + }); + } } ########################################################################## # Add Users to Groups ########################################################################## my @users_groups = ( - { user => 'conduit@mozilla.bugs', group => 'editbugs' }, - { user => 'conduit@mozilla.bugs', group => 'core-security' }, - { user => 'conduit-reviewer@mozilla.bugs', group => 'editbugs' }, - { user => 'phab-bot@bmo.tld', group => 'editbugs' }, - { user => 'phab-bot@bmo.tld', group => 'core-security' }, + {user => 'conduit@mozilla.bugs', group => 'editbugs'}, + {user => 'conduit@mozilla.bugs', group => 'core-security'}, + {user => 'conduit-reviewer@mozilla.bugs', group => 'editbugs'}, + {user => 'phab-bot@bmo.tld', group => 'editbugs'}, + {user => 'phab-bot@bmo.tld', group => 'core-security'}, ); print "adding users to groups...\n"; foreach my $user_group (@users_groups) { - my $group = Bugzilla::Group->new( { name => $user_group->{group} } ); - my $user = Bugzilla::User->new( { name => $user_group->{user} } ); - my $sth_add_mapping = $dbh->prepare( + my $group = Bugzilla::Group->new({name => $user_group->{group}}); + my $user = Bugzilla::User->new({name => $user_group->{user}}); + my $sth_add_mapping + = $dbh->prepare( 'INSERT INTO user_group_map (user_id, group_id, isbless, grant_type)' - . ' VALUES (?, ?, ?, ?)' - ); - - # Don't crash if the entry already exists. - my $ok = eval { - $sth_add_mapping->execute( $user->id, $group->id, 0, GRANT_DIRECT ); - 1; - }; - warn $@ unless $ok; + . ' VALUES (?, ?, ?, ?)'); + + # Don't crash if the entry already exists. + my $ok = eval { + $sth_add_mapping->execute($user->id, $group->id, 0, GRANT_DIRECT); + 1; + }; + warn $@ unless $ok; } ########################################################################## # Create Conduit Test Bug ########################################################################## print "creating conduit test bug...\n"; -Bugzilla->set_user( Bugzilla::User->check( { name => 'conduit@mozilla.bugs' } ) ); -Bugzilla::Bug->create( - { - product => 'Firefox', - component => 'General', - priority => '--', - bug_status => 'NEW', - version => 'unspecified', - comment => '-- Comment Created By Conduit User --', - rep_platform => 'Unspecified', - short_desc => 'Conduit Test Bug', - op_sys => 'Unspecified', - bug_severity => 'normal', - version => 'unspecified', - } -); +Bugzilla->set_user(Bugzilla::User->check({name => 'conduit@mozilla.bugs'})); +Bugzilla::Bug->create({ + product => 'Firefox', + component => 'General', + priority => '--', + bug_status => 'NEW', + version => 'unspecified', + comment => '-- Comment Created By Conduit User --', + rep_platform => 'Unspecified', + short_desc => 'Conduit Test Bug', + op_sys => 'Unspecified', + bug_severity => 'normal', + version => 'unspecified', +}); set_params( - password_check_on_login => 0, - phabricator_base_uri => 'http://phabricator.test/', - phabricator_enabled => 1, + password_check_on_login => 0, + phabricator_base_uri => 'http://phabricator.test/', + phabricator_enabled => 1, ); set_push_connector_options(); print "installation and configuration complete!\n"; sub set_push_connector_options { - print "setting push connector options...\n"; - my ($phab_is_configured) = $dbh->selectrow_array(q{SELECT COUNT(*) FROM push_options WHERE connector = 'Phabricator'}); - unless ($phab_is_configured) { - $dbh->do(q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('global','enabled','Enabled')}); - $dbh->do( - q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('Phabricator','enabled','Enabled')}); - $dbh->do( - q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('Phabricator','phabricator_url','http://phabricator.test')} - ); - } + print "setting push connector options...\n"; + my ($phab_is_configured) + = $dbh->selectrow_array( + q{SELECT COUNT(*) FROM push_options WHERE connector = 'Phabricator'}); + unless ($phab_is_configured) { + $dbh->do( + q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('global','enabled','Enabled')} + ); + $dbh->do( + q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('Phabricator','enabled','Enabled')} + ); + $dbh->do( + q{INSERT INTO push_options (connector, option_name, option_value) VALUES ('Phabricator','phabricator_url','http://phabricator.test')} + ); + } } sub set_params { - my (%set_params) = @_; - print "setting custom parameters...\n"; - if ($ENV{PHABRICATOR_API_KEY}) { - $set_params{phabricator_api_key} = $ENV{PHABRICATOR_API_KEY}; - } - - if ($ENV{PHABRICATOR_APP_ID} && $ENV{PHABRICATOR_AUTH_CALLBACK_URL}) { - $set_params{phabricator_app_id} = $ENV{PHABRICATOR_APP_ID}; - $set_params{phabricator_auth_callback_url} = $ENV{PHABRICATOR_AUTH_CALLBACK_URL}; - } - - my $params_modified; - foreach my $param ( keys %set_params ) { - my $value = $set_params{$param}; - next if !$value || Bugzilla->params->{$param} eq $value; - SetParam( $param, $value ); - $params_modified = 1; - } - - write_params() if $params_modified; + my (%set_params) = @_; + print "setting custom parameters...\n"; + if ($ENV{PHABRICATOR_API_KEY}) { + $set_params{phabricator_api_key} = $ENV{PHABRICATOR_API_KEY}; + } + + if ($ENV{PHABRICATOR_APP_ID} && $ENV{PHABRICATOR_AUTH_CALLBACK_URL}) { + $set_params{phabricator_app_id} = $ENV{PHABRICATOR_APP_ID}; + $set_params{phabricator_auth_callback_url} + = $ENV{PHABRICATOR_AUTH_CALLBACK_URL}; + } + + my $params_modified; + foreach my $param (keys %set_params) { + my $value = $set_params{$param}; + next if !$value || Bugzilla->params->{$param} eq $value; + SetParam($param, $value); + $params_modified = 1; + } + + write_params() if $params_modified; } diff --git a/scripts/group-set-members.pl b/scripts/group-set-members.pl index 0ec9aedda..c4d31b435 100755 --- a/scripts/group-set-members.pl +++ b/scripts/group-set-members.pl @@ -24,11 +24,13 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($users_file, $group, $admin); my ($do_adds, $do_removes) = (0, 0); -GetOptions('admin=s' => \$admin, - 'users-file=s' => \$users_file, - 'do-adds' => \$do_adds, - 'do-removes' => \$do_removes, - 'group=s' => \$group); +GetOptions( + 'admin=s' => \$admin, + 'users-file=s' => \$users_file, + 'do-adds' => \$do_adds, + 'do-removes' => \$do_removes, + 'group=s' => \$group +); usage() unless $admin && $users_file && $group; @@ -42,33 +44,35 @@ my @missing; open my $fh, '<', $users_file or die "Unable to open $users_file: $!"; while (my $user_name = <$fh>) { - chomp $user_name; - eval { - my $user = Bugzilla::User->check({name => $user_name}); - $new_member{ $user->name } = $user; - }; - if ($@) { - push @missing, $user_name; - } + chomp $user_name; + eval { + my $user = Bugzilla::User->check({name => $user_name}); + $new_member{$user->name} = $user; + }; + if ($@) { + push @missing, $user_name; + } } -my @removes = map { $old_member{$_} } grep { !$new_member{$_} } keys %old_member; -my @adds = map { $new_member{$_} } grep { !$old_member{$_} } keys %new_member; +my @removes + = map { $old_member{$_} } grep { !$new_member{$_} } keys %old_member; +my @adds = map { $new_member{$_} } grep { !$old_member{$_} } keys %new_member; if (@removes == 0 && @adds == 0) { - if (@missing != 0) { - printf STDERR "There are %d user(s) in %s that do not exist.\n", - scalar @missing, $users_file; - } - say STDERR "Nothing to do\n"; - exit; + if (@missing != 0) { + printf STDERR "There are %d user(s) in %s that do not exist.\n", + scalar @missing, $users_file; + } + say STDERR "Nothing to do\n"; + exit; } $| = 1; printf STDERR "Group '%s', Admin '%s'\n", $group, $admin; -printf STDERR "Will add %d user(s)\n", scalar @adds if $do_adds; +printf STDERR "Will add %d user(s)\n", scalar @adds if $do_adds; printf STDERR "Will remove %d user(s)\n", scalar @removes if $do_removes; -printf STDERR "There are %d user(s) in %s that do not exist.\n", scalar @missing, $users_file +printf STDERR "There are %d user(s) in %s that do not exist.\n", + scalar @missing, $users_file if @missing; say STDERR "Press <Ctrl-C> to stop or <Enter> to continue..."; getc(); @@ -79,19 +83,19 @@ my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction(); if ($do_removes) { - foreach my $remove (@removes) { - say "remove ", $remove->login, " from ", $group; - $remove->set_groups({ remove => [$group] }); - $remove->update; - } + foreach my $remove (@removes) { + say "remove ", $remove->login, " from ", $group; + $remove->set_groups({remove => [$group]}); + $remove->update; + } } if ($do_adds) { - foreach my $add (@adds) { - say "add ", $add->login, " to ", $group; - $add->set_groups({ add => [$group] }); - $add->update; - } + foreach my $add (@adds) { + say "add ", $add->login, " to ", $group; + $add->set_groups({add => [$group]}); + $add->update; + } } $dbh->bz_commit_transaction(); @@ -101,7 +105,7 @@ say STDERR "done.\n"; Bugzilla->memcached->clear_all(); sub usage { - die <<EOF; + die <<EOF; usage $0 --admin bob\@mozilla.org --users-file users.txt --group pants --users-file File containing one bugzilla email per line. @@ -113,4 +117,4 @@ usage $0 --admin bob\@mozilla.org --users-file users.txt --group pants Informational messages are sent to STDERR. STDOUT should be redirected to a file as it will contain a list of which users were added, removed, and any missing users. EOF -}
\ No newline at end of file +} diff --git a/scripts/issue-api-key.pl b/scripts/issue-api-key.pl index e4cc1cdd0..25c3ba1a2 100755 --- a/scripts/issue-api-key.pl +++ b/scripts/issue-api-key.pl @@ -19,23 +19,23 @@ use Bugzilla::User::APIKey; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $login = shift - or die "syntax: $0 bugzilla-login [description] [api key]\n"; -my $description = shift; +my $login = shift or die "syntax: $0 bugzilla-login [description] [api key]\n"; +my $description = shift; my $given_api_key = shift; my $api_key; -my $user = Bugzilla::User->check({ name => $login }); +my $user = Bugzilla::User->check({name => $login}); my $params = { - user_id => $user->id, - description => $description, - api_key => $given_api_key, + user_id => $user->id, + description => $description, + api_key => $given_api_key, }; if ($given_api_key) { - $api_key = Bugzilla::User::APIKey->create_special($params); -} else { - $api_key = Bugzilla::User::APIKey->create($params); + $api_key = Bugzilla::User::APIKey->create_special($params); +} +else { + $api_key = Bugzilla::User::APIKey->create($params); } say $api_key->api_key; diff --git a/scripts/merge-users.pl b/scripts/merge-users.pl index 2d9c795d7..6195d8419 100755 --- a/scripts/merge-users.pl +++ b/scripts/merge-users.pl @@ -33,7 +33,6 @@ merge-users.pl - Merge two user accounts. =cut - use Bugzilla; use Bugzilla::Constants; use Bugzilla::Util; @@ -46,7 +45,7 @@ use Pod::Usage; my $dbh = Bugzilla->dbh; # Display the help if called with --help or -?. -my $help = 0; +my $help = 0; my $result = GetOptions("help|?" => \$help); pod2usage(0) if $help; @@ -55,49 +54,54 @@ pod2usage(0) if $help; my $old = $ARGV[0] || die "You must specify an old user account.\n"; my $old_id; if ($old =~ /^id:(\d+)$/) { - # As the old user account may be a deleted one, we don't - # check whether this user ID is valid or not. - # If it never existed, no damage will be done. - $old_id = $1; + + # As the old user account may be a deleted one, we don't + # check whether this user ID is valid or not. + # If it never existed, no damage will be done. + $old_id = $1; } else { - trick_taint($old); - $old_id = $dbh->selectrow_array('SELECT userid FROM profiles - WHERE login_name = ?', - undef, $old); + trick_taint($old); + $old_id = $dbh->selectrow_array( + 'SELECT userid FROM profiles + WHERE login_name = ?', undef, $old + ); } if ($old_id) { - print "OK, old user account $old found; user ID: $old_id.\n"; + print "OK, old user account $old found; user ID: $old_id.\n"; } else { - die "The old user account $old does not exist.\n"; + die "The old user account $old does not exist.\n"; } my $new = $ARGV[1] || die "You must specify a new user account.\n"; my $new_id; if ($new =~ /^id:(\d+)$/) { - $new_id = $1; - # Make sure this user ID exists. - $new_id = $dbh->selectrow_array('SELECT userid FROM profiles - WHERE userid = ?', - undef, $new_id); + $new_id = $1; + + # Make sure this user ID exists. + $new_id = $dbh->selectrow_array( + 'SELECT userid FROM profiles + WHERE userid = ?', undef, $new_id + ); } else { - trick_taint($new); - $new_id = $dbh->selectrow_array('SELECT userid FROM profiles - WHERE login_name = ?', - undef, $new); + trick_taint($new); + $new_id = $dbh->selectrow_array( + 'SELECT userid FROM profiles + WHERE login_name = ?', undef, $new + ); } if ($new_id) { - print "OK, new user account $new found; user ID: $new_id.\n"; + print "OK, new user account $new found; user ID: $new_id.\n"; } else { - die "The new user account $new does not exist.\n"; + die "The new user account $new does not exist.\n"; } # Make sure the old and new accounts are different. if ($old_id == $new_id) { - die "\nBoth accounts are identical. There is nothing to migrate.\n"; + die "\nBoth accounts are identical. There is nothing to migrate.\n"; } @@ -114,43 +118,46 @@ if ($old_id == $new_id) { # We set the tables that require custom stuff (multiple columns to check) # here, but the simple stuff is all handled below by bz_get_related_fks. my %changes = ( - cc => ['who bug_id'], - # Tables affecting global behavior / other users. - component_cc => ['user_id component_id'], - watch => ['watcher watched', 'watched watcher'], - # Tables affecting the user directly. - namedqueries => ['userid name'], - namedqueries_link_in_footer => ['user_id namedquery_id'], - user_group_map => ['user_id group_id isbless grant_type'], - email_setting => ['user_id relationship event'], - profile_setting => ['user_id setting_name'], - - # Only do it if mailto_type = 0, i.e is pointing to a user account! - # This requires to be done separately due to this condition. - whine_schedules => [], # ['mailto'], + cc => ['who bug_id'], + + # Tables affecting global behavior / other users. + component_cc => ['user_id component_id'], + watch => ['watcher watched', 'watched watcher'], + + # Tables affecting the user directly. + namedqueries => ['userid name'], + namedqueries_link_in_footer => ['user_id namedquery_id'], + user_group_map => ['user_id group_id isbless grant_type'], + email_setting => ['user_id relationship event'], + profile_setting => ['user_id setting_name'], + + # Only do it if mailto_type = 0, i.e is pointing to a user account! + # This requires to be done separately due to this condition. + whine_schedules => [], # ['mailto'], ); my $userid_fks = $dbh->bz_get_related_fks('profiles', 'userid'); foreach my $item (@$userid_fks) { - my ($table, $column) = @$item; - $changes{$table} ||= []; - push(@{ $changes{$table} }, $column); + my ($table, $column) = @$item; + $changes{$table} ||= []; + push(@{$changes{$table}}, $column); } # Delete all old records for these tables; no migration. foreach my $table (qw(logincookies tokens profiles)) { - $changes{$table} = []; + $changes{$table} = []; } # Start the transaction $dbh->bz_start_transaction(); # BMO - pre-work hook -Bugzilla::Hook::process('merge_users_before', { old_id => $old_id, new_id => $new_id }); +Bugzilla::Hook::process('merge_users_before', + {old_id => $old_id, new_id => $new_id}); # Delete old records from logincookies and tokens tables. $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id); -$dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $old_id); +$dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $old_id); # Special care needs to be done with bug_user_last_visit table as the # source user and destination user may have visited the same bug id at one time. @@ -163,78 +170,87 @@ my $dupe_ids = $dbh->selectcol_arrayref(" AND earlier.last_visit_ts < later.last_visit_ts AND earlier.bug_id = later.bug_id) WHERE (earlier.user_id = ? OR earlier.user_id = ?) - AND (later.user_id = ? OR later.user_id = ?)", - undef, $old_id, $new_id, $old_id, $new_id); + AND (later.user_id = ? OR later.user_id = ?)", undef, $old_id, + $new_id, $old_id, $new_id); if (@$dupe_ids) { - $dbh->do("DELETE FROM bug_user_last_visit WHERE " . - $dbh->sql_in('id', $dupe_ids)); + $dbh->do( + "DELETE FROM bug_user_last_visit WHERE " . $dbh->sql_in('id', $dupe_ids)); } # Migrate records from old user to new user. foreach my $table (keys %changes) { - foreach my $column_list (@{ $changes{$table} }) { - # Get all columns to consider. There is always at least - # one column given: the one to update. - my @columns = split(/[\s]+/, $column_list); - my $cols_to_check = join(' AND ', map {"$_ = ?"} @columns); - # The first column of the list is the one to update. - my $col_to_update = shift @columns; - - # Will be used to migrate the old user account to the new one. - my $sth_update = $dbh->prepare("UPDATE $table + foreach my $column_list (@{$changes{$table}}) { + + # Get all columns to consider. There is always at least + # one column given: the one to update. + my @columns = split(/[\s]+/, $column_list); + my $cols_to_check = join(' AND ', map {"$_ = ?"} @columns); + + # The first column of the list is the one to update. + my $col_to_update = shift @columns; + + # Will be used to migrate the old user account to the new one. + my $sth_update = $dbh->prepare( + "UPDATE $table SET $col_to_update = ? - WHERE $cols_to_check"); + WHERE $cols_to_check" + ); - # Do we have additional columns to take care of? - if (scalar(@columns)) { - my $cols_to_query = join(', ', @columns); + # Do we have additional columns to take care of? + if (scalar(@columns)) { + my $cols_to_query = join(', ', @columns); - # Get existing entries for the old user account. - my $old_entries = - $dbh->selectall_arrayref("SELECT $cols_to_query + # Get existing entries for the old user account. + my $old_entries = $dbh->selectall_arrayref( + "SELECT $cols_to_query FROM $table - WHERE $col_to_update = ?", - undef, $old_id); + WHERE $col_to_update = ?", undef, $old_id + ); - # Will be used to check whether the same entry exists - # for the new user account. - my $sth_select = $dbh->prepare("SELECT COUNT(*) + # Will be used to check whether the same entry exists + # for the new user account. + my $sth_select = $dbh->prepare( + "SELECT COUNT(*) FROM $table - WHERE $cols_to_check"); - - # Will be used to delete duplicated entries. - my $sth_delete = $dbh->prepare("DELETE FROM $table - WHERE $cols_to_check"); - - foreach my $entry (@$old_entries) { - my $exists = $dbh->selectrow_array($sth_select, undef, - ($new_id, @$entry)); - - if ($exists) { - $sth_delete->execute($old_id, @$entry); - } - else { - $sth_update->execute($new_id, $old_id, @$entry); - } - } + WHERE $cols_to_check" + ); + + # Will be used to delete duplicated entries. + my $sth_delete = $dbh->prepare( + "DELETE FROM $table + WHERE $cols_to_check" + ); + + foreach my $entry (@$old_entries) { + my $exists = $dbh->selectrow_array($sth_select, undef, ($new_id, @$entry)); + + if ($exists) { + $sth_delete->execute($old_id, @$entry); } - # No check required. Update the column directly. else { - $sth_update->execute($new_id, $old_id); + $sth_update->execute($new_id, $old_id, @$entry); } - print "OK, records in the '$col_to_update' column of the '$table' table\n" . - "have been migrated to the new user account.\n"; + } } + + # No check required. Update the column directly. + else { + $sth_update->execute($new_id, $old_id); + } + print "OK, records in the '$col_to_update' column of the '$table' table\n" + . "have been migrated to the new user account.\n"; + } } # Only update 'whine_schedules' if mailto_type = 0. # (i.e. is pointing to a user ID). -$dbh->do('UPDATE whine_schedules SET mailto = ? - WHERE mailto = ? AND mailto_type = ?', - undef, ($new_id, $old_id, 0)); -print "OK, records in the 'mailto' column of the 'whine_schedules' table\n" . - "have been migrated to the new user account.\n"; +$dbh->do( + 'UPDATE whine_schedules SET mailto = ? + WHERE mailto = ? AND mailto_type = ?', undef, ($new_id, $old_id, 0) +); +print "OK, records in the 'mailto' column of the 'whine_schedules' table\n" + . "have been migrated to the new user account.\n"; # Delete the old record from the profiles table. $dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id); @@ -246,7 +262,8 @@ my $user = new Bugzilla::User($new_id); $user->derive_regexp_groups(); # BMO - post-work hook -Bugzilla::Hook::process('merge_users_after', { old_id => $old_id, new_id => $new_id }); +Bugzilla::Hook::process('merge_users_after', + {old_id => $old_id, new_id => $new_id}); # Commit the transaction $dbh->bz_commit_transaction(); diff --git a/scripts/migrate-attachments.pl b/scripts/migrate-attachments.pl index dee1e7a3b..2de7c602c 100755 --- a/scripts/migrate-attachments.pl +++ b/scripts/migrate-attachments.pl @@ -13,8 +13,6 @@ use lib qw(. lib local/lib/perl5); $| = 1; - - use Bugzilla; use Bugzilla::Attachment; use Bugzilla::Install::Util qw(indicate_progress); @@ -25,7 +23,7 @@ my @storage_names = Bugzilla::Attachment->get_storage_names(); my %options; GetOptions(\%options, 'mirror=s@{2}', 'copy=s@{2}', 'delete=s') or exit(1); unless ($options{mirror} || $options{copy} || $options{delete}) { - die <<EOF; + die <<EOF; Syntax: migrate-attachments.pl --mirror source destination migrate-attachments.pl --copy source destination @@ -62,94 +60,107 @@ EOF my $dbh = Bugzilla->dbh; if ($options{mirror}) { - if ($options{mirror}->[0] eq $options{mirror}->[1]) { - die "Source and destination must be different\n"; + if ($options{mirror}->[0] eq $options{mirror}->[1]) { + die "Source and destination must be different\n"; + } + my ($source, $dest) = map { storage($_) } @{$options{mirror}}; + + my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM attachments"); + confirm(sprintf( + 'Mirror %s attachments from %s to %s?', $total, @{$options{mirror}})); + + my $sth = $dbh->prepare( + "SELECT attach_id, attach_size FROM attachments ORDER BY attach_id DESC"); + $sth->execute(); + my ($count, $deleted, $stored) = (0, 0, 0); + while (my ($attach_id, $attach_size) = $sth->fetchrow_array()) { + indicate_progress({total => $total, current => ++$count}); + + # remove deleted attachments + if ($attach_size == 0 && $dest->exists($attach_id)) { + $dest->remove($attach_id); + $deleted++; } - my ($source, $dest) = map { storage($_) } @{ $options{mirror} }; - - my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM attachments"); - confirm(sprintf('Mirror %s attachments from %s to %s?', $total, @{ $options{mirror} })); - - my $sth = $dbh->prepare("SELECT attach_id, attach_size FROM attachments ORDER BY attach_id DESC"); - $sth->execute(); - my ($count, $deleted, $stored) = (0, 0, 0); - while (my ($attach_id, $attach_size) = $sth->fetchrow_array()) { - indicate_progress({ total => $total, current => ++$count }); - - # remove deleted attachments - if ($attach_size == 0 && $dest->exists($attach_id)) { - $dest->remove($attach_id); - $deleted++; - } - - # store attachments that don't already exist - elsif ($attach_size != 0 && !$dest->exists($attach_id)) { - if (my $data = $source->retrieve($attach_id)) { - $dest->store($attach_id, $data); - $stored++; - } - } + + # store attachments that don't already exist + elsif ($attach_size != 0 && !$dest->exists($attach_id)) { + if (my $data = $source->retrieve($attach_id)) { + $dest->store($attach_id, $data); + $stored++; + } } - print "\n"; - print "Attachments stored: $stored\n"; - print "Attachments deleted: $deleted\n" if $deleted; + } + print "\n"; + print "Attachments stored: $stored\n"; + print "Attachments deleted: $deleted\n" if $deleted; } elsif ($options{copy}) { - if ($options{copy}->[0] eq $options{copy}->[1]) { - die "Source and destination must be different\n"; - } - my ($source, $dest) = map { storage($_) } @{ $options{copy} }; - - my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM attachments WHERE attach_size != 0"); - confirm(sprintf('Copy %s attachments from %s to %s?', $total, @{ $options{copy} })); - - my $sth = $dbh->prepare("SELECT attach_id, attach_size FROM attachments WHERE attach_size != 0 ORDER BY attach_id DESC"); - $sth->execute(); - my ($count, $stored) = (0, 0); - while (my ($attach_id, $attach_size) = $sth->fetchrow_array()) { - indicate_progress({ total => $total, current => ++$count }); - - # store attachments that don't already exist - if (!$dest->exists($attach_id)) { - if (my $data = $source->retrieve($attach_id)) { - $dest->store($attach_id, $data); - $stored++; - } - } + if ($options{copy}->[0] eq $options{copy}->[1]) { + die "Source and destination must be different\n"; + } + my ($source, $dest) = map { storage($_) } @{$options{copy}}; + + my ($total) + = $dbh->selectrow_array( + "SELECT COUNT(*) FROM attachments WHERE attach_size != 0"); + confirm(sprintf( + 'Copy %s attachments from %s to %s?', $total, @{$options{copy}})); + + my $sth + = $dbh->prepare( + "SELECT attach_id, attach_size FROM attachments WHERE attach_size != 0 ORDER BY attach_id DESC" + ); + $sth->execute(); + my ($count, $stored) = (0, 0); + while (my ($attach_id, $attach_size) = $sth->fetchrow_array()) { + indicate_progress({total => $total, current => ++$count}); + + # store attachments that don't already exist + if (!$dest->exists($attach_id)) { + if (my $data = $source->retrieve($attach_id)) { + $dest->store($attach_id, $data); + $stored++; + } } - print "\n"; - print "Attachments stored: $stored\n"; + } + print "\n"; + print "Attachments stored: $stored\n"; } elsif ($options{delete}) { - my $storage = storage($options{delete}); - my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM attachments WHERE attach_size != 0"); - confirm(sprintf('DELETE %s attachments from %s?', $total, $options{delete})); - - my $sth = $dbh->prepare("SELECT attach_id FROM attachments WHERE attach_size != 0 ORDER BY attach_id DESC"); - $sth->execute(); - my ($count, $deleted) = (0, 0); - while (my ($attach_id) = $sth->fetchrow_array()) { - indicate_progress({ total => $total, current => ++$count }); - if ($storage->exists($attach_id)) { - $storage->remove($attach_id); - $deleted++; - } + my $storage = storage($options{delete}); + my ($total) + = $dbh->selectrow_array( + "SELECT COUNT(*) FROM attachments WHERE attach_size != 0"); + confirm(sprintf('DELETE %s attachments from %s?', $total, $options{delete})); + + my $sth + = $dbh->prepare( + "SELECT attach_id FROM attachments WHERE attach_size != 0 ORDER BY attach_id DESC" + ); + $sth->execute(); + my ($count, $deleted) = (0, 0); + while (my ($attach_id) = $sth->fetchrow_array()) { + indicate_progress({total => $total, current => ++$count}); + if ($storage->exists($attach_id)) { + $storage->remove($attach_id); + $deleted++; } - print "\n"; - print "Attachments deleted: $deleted\n"; + } + print "\n"; + print "Attachments deleted: $deleted\n"; } sub storage { - my ($name) = @_; - my $storage = Bugzilla::Attachment::get_storage_by_name($name) - or die "Invalid attachment location: $name\n"; - return $storage; + my ($name) = @_; + my $storage = Bugzilla::Attachment::get_storage_by_name($name) + or die "Invalid attachment location: $name\n"; + return $storage; } sub confirm { - my ($prompt) = @_; - print $prompt, "\n\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; - getc(); + my ($prompt) = @_; + print $prompt, "\n\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; + getc(); } diff --git a/scripts/migrate-cab-review.pl b/scripts/migrate-cab-review.pl index b4665f255..5cfb0ca2d 100755 --- a/scripts/migrate-cab-review.pl +++ b/scripts/migrate-cab-review.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Bug; use Bugzilla::Constants; @@ -27,24 +25,20 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $dbh = Bugzilla->dbh; # Make all changes as the automation user -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); -$auto_user->{groups} = [ Bugzilla::Group->get_all ]; -$auto_user->{bless_groups} = [ Bugzilla::Group->get_all ]; +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); +$auto_user->{groups} = [Bugzilla::Group->get_all]; +$auto_user->{bless_groups} = [Bugzilla::Group->get_all]; Bugzilla->set_user($auto_user); # cab-review flag values to custom field values mapping -my %map = ( - '?' => '?', - '+' => 'approved', - '-' => 'denied' -); +my %map = ('?' => '?', '+' => 'approved', '-' => 'denied'); # Verify that all of the custom field values in the mapping data are present -my $cab_field = Bugzilla::Field->check({ name => 'cf_cab_review' }); +my $cab_field = Bugzilla::Field->check({name => 'cf_cab_review'}); foreach my $value (values %map) { - unless (grep($_ eq $value, map { $_->name } @{ $cab_field->legal_values })) { - die "Value '$value' does not exist. Please add to 'cf_cab_review.\n"; - } + unless (grep($_ eq $value, map { $_->name } @{$cab_field->legal_values})) { + die "Value '$value' does not exist. Please add to 'cf_cab_review.\n"; + } } # Grab list of bugs with cab-review flag set @@ -61,43 +55,44 @@ my $bugs = $dbh->selectcol_arrayref($sql); my ($current, $total, $updated) = (1, scalar(@$bugs), 0); die "No matching bugs found\n" unless $total; -print "About to update $total bugs with cab-review flags set and migrate to the cf_cab_review custom field.\n"; +print + "About to update $total bugs with cab-review flags set and migrate to the cf_cab_review custom field.\n"; print "Press <enter> to start, or ^C to cancel...\n"; <>; foreach my $bug_id (@$bugs) { - indicate_progress({ current => $current++, total => $total, every => 5 }); + indicate_progress({current => $current++, total => $total, every => 5}); - # Load bug object - my $bug = Bugzilla::Bug->new($bug_id); + # Load bug object + my $bug = Bugzilla::Bug->new($bug_id); - # Find the current cab-review status - my $cab_flag; - foreach my $flag (@{ $bug->flags }) { - next if $flag->type->name ne 'cab-review'; - $cab_flag = $flag; - last; - } + # Find the current cab-review status + my $cab_flag; + foreach my $flag (@{$bug->flags}) { + next if $flag->type->name ne 'cab-review'; + $cab_flag = $flag; + last; + } - my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - $dbh->bz_start_transaction; + $dbh->bz_start_transaction; - # Set the cab-review custom field to the right status based on the mapped values - $bug->set_custom_field($cab_field, $map{$cab_flag->status}); + # Set the cab-review custom field to the right status based on the mapped values + $bug->set_custom_field($cab_field, $map{$cab_flag->status}); - # Clear the old cab-review flag - $bug->set_flags([{ id => $cab_flag->id, status => 'X' }], []); + # Clear the old cab-review flag + $bug->set_flags([{id => $cab_flag->id, status => 'X'}], []); - # Update the bug - $bug->update($timestamp); + # Update the bug + $bug->update($timestamp); - # Do not send email about this change - $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $timestamp, $bug_id); + # Do not send email about this change + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); - $dbh->bz_commit_transaction; - $updated++; + $dbh->bz_commit_transaction; + $updated++; } print "Bugs updated: $updated\n"; diff --git a/scripts/migrate_whiteboard_keyword.pl b/scripts/migrate_whiteboard_keyword.pl index a1bbf6152..ce97455ce 100755 --- a/scripts/migrate_whiteboard_keyword.pl +++ b/scripts/migrate_whiteboard_keyword.pl @@ -47,13 +47,16 @@ use Term::ANSIColor qw(colored); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($remove_whiteboard, $help, $doit); -GetOptions("r|remove" => \$remove_whiteboard, - "h|help" => \$help, 'doit' => \$doit); +GetOptions( + "r|remove" => \$remove_whiteboard, + "h|help" => \$help, + 'doit' => \$doit +); sub usage { - my $error = shift || ""; - print colored(['red'], $error) if $error; - print <<USAGE; + my $error = shift || ""; + print colored(['red'], $error) if $error; + print <<USAGE; Usage: migrate_whiteboard_keyword.pl [--remove|-r] [--help|-h] [--doit] E.g.: migrate_whiteboard_keyword.pl --remove --doit "good first bug" "good-first-bug" @@ -63,7 +66,7 @@ given, then string will be removed from the whiteboard as well. Pass --doit to make the database changes permanent. USAGE - exit(1); + exit(1); } # exit if help was requested @@ -71,30 +74,33 @@ usage() if $help; # grab whiteboard and keyword my $whiteboard = shift; -my $keyword = shift; -($whiteboard && $keyword) || usage("Whiteboard or keyword strings were not provided\n"); +my $keyword = shift; +($whiteboard && $keyword) + || usage("Whiteboard or keyword strings were not provided\n"); trick_taint($whiteboard); trick_taint($keyword); # User to make changes as automation@bmo.tld -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); $auto_user || usage("Can't find user 'automation\@bmo.tld'\n"); # field ids for logging activity -my $keyword_field = Bugzilla::Field->new({ name => 'keywords'}); +my $keyword_field = Bugzilla::Field->new({name => 'keywords'}); $keyword_field || usage("Can't find field 'keywords'\n"); -my $whiteboard_field = Bugzilla::Field->new({ name => 'status_whiteboard' }); +my $whiteboard_field = Bugzilla::Field->new({name => 'status_whiteboard'}); $whiteboard_field || usage("Can't find field 'status_whiteboard'\n"); # keyword object (assumes already created) -my $keyword_obj = Bugzilla::Keyword->new({ name => $keyword }); +my $keyword_obj = Bugzilla::Keyword->new({name => $keyword}); $keyword_obj || usage("Can't find keyword '$keyword'\n"); my $dbh = Bugzilla->dbh; -my $bugs = $dbh->selectall_arrayref("SELECT DISTINCT bugs.bug_id, bugs.status_whiteboard +my $bugs = $dbh->selectall_arrayref( + "SELECT DISTINCT bugs.bug_id, bugs.status_whiteboard FROM bugs WHERE bugs.status_whiteboard LIKE ?", - { Slice => {} }, '%' . $whiteboard . '%'); + {Slice => {}}, '%' . $whiteboard . '%' +); my $bug_count = scalar @$bugs; $bug_count || usage("No bugs were found in matching search criteria.\n"); @@ -104,59 +110,70 @@ print colored(['green'], "Processing $bug_count bug(s)\n"); $dbh->bz_start_transaction() if $doit; foreach my $bug (@$bugs) { - my $bug_id = $bug->{'bug_id'}; - my $status_whiteboard = $bug->{'status_whiteboard'}; + my $bug_id = $bug->{'bug_id'}; + my $status_whiteboard = $bug->{'status_whiteboard'}; - print "working on bug $bug_id\n"; + print "working on bug $bug_id\n"; - my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - my $keyword_present = $dbh->selectrow_array(" - SELECT bug_id FROM keywords WHERE bug_id = ? AND keywordid = ?", - undef, $bug_id, $keyword_obj->id); + my $keyword_present = $dbh->selectrow_array(" + SELECT bug_id FROM keywords WHERE bug_id = ? AND keywordid = ?", undef, + $bug_id, $keyword_obj->id); - if (!$keyword_present) { - print " adding keyword\n"; - if ($doit) { - $dbh->do("INSERT INTO keywords (bug_id, keywordid) VALUES (?, ?)", - undef, $bug_id, $keyword_obj->id); - $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . - "VALUES (?, ?, ?, ?, '', ?)", - undef, $bug_id, $auto_user->id, $timestamp, $keyword_field->id, $keyword); - $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $timestamp, $bug_id); - } + if (!$keyword_present) { + print " adding keyword\n"; + if ($doit) { + $dbh->do("INSERT INTO keywords (bug_id, keywordid) VALUES (?, ?)", + undef, $bug_id, $keyword_obj->id); + $dbh->do( + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " + . "VALUES (?, ?, ?, ?, '', ?)", + undef, $bug_id, $auto_user->id, $timestamp, $keyword_field->id, $keyword + ); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); } - - if ($remove_whiteboard) { - print " removing whiteboard\n"; - if ($doit) { - my $old_whiteboard = $status_whiteboard; - $status_whiteboard =~ s/\Q$whiteboard\E//ig; - $status_whiteboard = trim($status_whiteboard); - - $dbh->do("UPDATE bugs SET status_whiteboard = ? WHERE bug_id = ?", - undef, $status_whiteboard, $bug_id); - $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . - "VALUES (?, ?, ?, ?, ?, ?)", - undef, $bug_id, $auto_user->id, $timestamp, $whiteboard_field->id, $old_whiteboard, $status_whiteboard); - $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $timestamp, $bug_id); - } + } + + if ($remove_whiteboard) { + print " removing whiteboard\n"; + if ($doit) { + my $old_whiteboard = $status_whiteboard; + $status_whiteboard =~ s/\Q$whiteboard\E//ig; + $status_whiteboard = trim($status_whiteboard); + + $dbh->do("UPDATE bugs SET status_whiteboard = ? WHERE bug_id = ?", + undef, $status_whiteboard, $bug_id); + $dbh->do( + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " + . "VALUES (?, ?, ?, ?, ?, ?)", + undef, + $bug_id, + $auto_user->id, + $timestamp, + $whiteboard_field->id, + $old_whiteboard, + $status_whiteboard + ); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); } + } } $dbh->bz_commit_transaction() if $doit; if ($doit) { - # 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(); - print colored(['green'], "DATABASE WAS UPDATED\n"); + # 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(); + + print colored(['green'], "DATABASE WAS UPDATED\n"); } else { - print colored(['red'], "DATABASE WAS NOT UPDATED\n"); + print colored(['red'], "DATABASE WAS NOT UPDATED\n"); } exit(0); diff --git a/scripts/move_flag_types.pl b/scripts/move_flag_types.pl index d4aa6cb09..659788a06 100755 --- a/scripts/move_flag_types.pl +++ b/scripts/move_flag_types.pl @@ -88,40 +88,43 @@ use Getopt::Long; use Pod::Usage; my %params; -GetOptions(\%params, 'help|h|?', 'oldid|o=s', 'newid|n=s', - 'product|p=s', 'component|c:s', 'doit|d') or pod2usage(1); - -if ($params{'help'} || !$params{'oldid'} - || !$params{'newid'} || !$params{'product'}) { - pod2usage({ -message => "Missing required argument", - -exitval => 1 }); +GetOptions(\%params, 'help|h|?', 'oldid|o=s', 'newid|n=s', 'product|p=s', + 'component|c:s', 'doit|d') + or pod2usage(1); + +if ( $params{'help'} + || !$params{'oldid'} + || !$params{'newid'} + || !$params{'product'}) +{ + pod2usage({-message => "Missing required argument", -exitval => 1}); } # Set defaults -$params{'doit'} ||= 0; +$params{'doit'} ||= 0; $params{'component'} ||= ''; my $dbh = Bugzilla->dbh; # Get the flag names -my $old_flag_name = $dbh->selectrow_array( - "SELECT name FROM flagtypes WHERE id = ?", - undef, $params{'oldid'}); -my $new_flag_name = $dbh->selectrow_array( - "SELECT name FROM flagtypes WHERE id = ?", - undef, $params{'newid'}); +my $old_flag_name + = $dbh->selectrow_array("SELECT name FROM flagtypes WHERE id = ?", + undef, $params{'oldid'}); +my $new_flag_name + = $dbh->selectrow_array("SELECT name FROM flagtypes WHERE id = ?", + undef, $params{'newid'}); # Find the product id -my $product_id = $dbh->selectrow_array( - "SELECT id FROM products WHERE name = ?", - undef, $params{'product'}); +my $product_id = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $params{'product'}); # Find the component id if not __ANY__ my $component_id; if ($params{'component'}) { - $component_id = $dbh->selectrow_array( - "SELECT id FROM components WHERE name = ? AND product_id = ?", - undef, $params{'component'}, $product_id); + $component_id + = $dbh->selectrow_array( + "SELECT id FROM components WHERE name = ? AND product_id = ?", + undef, $params{'component'}, $product_id); } my @query_args = ($params{'oldid'}); @@ -131,41 +134,49 @@ my $flag_query = "SELECT flags.id AS flag_id, flags.bug_id AS bug_id WHERE flags.type_id = ? "; if ($component_id) { - # No need to compare against product_id as component_id is already - # tied to a specific product - $flag_query .= "AND bugs.component_id = ?"; - push(@query_args, $component_id); + + # No need to compare against product_id as component_id is already + # tied to a specific product + $flag_query .= "AND bugs.component_id = ?"; + push(@query_args, $component_id); } else { - # All bugs for a product regardless of component - $flag_query .= "AND bugs.product_id = ?"; - push(@query_args, $product_id); + # All bugs for a product regardless of component + $flag_query .= "AND bugs.product_id = ?"; + push(@query_args, $product_id); } my $flags = $dbh->selectall_arrayref($flag_query, undef, @query_args); if (@$flags) { - print "Moving '" . scalar @$flags . "' flags " . - "from $old_flag_name (" . $params{'oldid'} . ") " . - "to $new_flag_name (" . $params{'newid'} . ")...\n"; - - if (!$params{'doit'}) { - print "Pass the argument --doit or -d to permanently make changes to the database.\n"; - } - else { - my $flag_update_sth = $dbh->prepare("UPDATE flags SET type_id = ? WHERE id = ?"); - - foreach my $flag (@$flags) { - my ($flag_id, $bug_id) = @$flag; - print "Bug: $bug_id Flag: $flag_id\n"; - $flag_update_sth->execute($params{'newid'}, $flag_id); - } + print "Moving '" + . scalar @$flags + . "' flags " + . "from $old_flag_name (" + . $params{'oldid'} . ") " + . "to $new_flag_name (" + . $params{'newid'} + . ")...\n"; + + if (!$params{'doit'}) { + print + "Pass the argument --doit or -d to permanently make changes to the database.\n"; + } + else { + my $flag_update_sth + = $dbh->prepare("UPDATE flags SET type_id = ? WHERE id = ?"); + + foreach my $flag (@$flags) { + my ($flag_id, $bug_id) = @$flag; + print "Bug: $bug_id Flag: $flag_id\n"; + $flag_update_sth->execute($params{'newid'}, $flag_id); } + } - # 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(); + # 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(); } else { - print "No flags to move\n"; + print "No flags to move\n"; } diff --git a/scripts/move_os.pl b/scripts/move_os.pl index 963188261..bfa3d34ce 100755 --- a/scripts/move_os.pl +++ b/scripts/move_os.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Field; use Bugzilla::Constants; @@ -29,23 +27,28 @@ GetOptions('from=s' => \$from_os, 'to=s' => \$to_os); pod2usage(1) unless defined $from_os && defined $to_os; -my $check_from_os = Bugzilla::Field::Choice->type('op_sys')->match({ value => $from_os }); -my $check_to_os = Bugzilla::Field::Choice->type('op_sys')->match({ value => $to_os }); +my $check_from_os + = Bugzilla::Field::Choice->type('op_sys')->match({value => $from_os}); +my $check_to_os + = Bugzilla::Field::Choice->type('op_sys')->match({value => $to_os}); die "Cannot move $from_os because it does not exist\n" - unless @$check_from_os == 1; + unless @$check_from_os == 1; die "Cannot move $from_os because $to_os doesn't exist.\n" - unless @$check_to_os == 1; + unless @$check_to_os == 1; my $dbh = Bugzilla->dbh; my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); -my $bug_ids = $dbh->selectcol_arrayref(q{SELECT bug_id FROM bugs WHERE bugs.op_sys = ?}, undef, $from_os); -my $field = Bugzilla::Field->check({ name => 'op_sys', cache => 1 }); -my $nobody = Bugzilla::User->check({ name => Bugzilla->params->{'nobody_user'}, cache => 1 }); +my $bug_ids + = $dbh->selectcol_arrayref(q{SELECT bug_id FROM bugs WHERE bugs.op_sys = ?}, + undef, $from_os); +my $field = Bugzilla::Field->check({name => 'op_sys', cache => 1}); +my $nobody = Bugzilla::User->check( + {name => Bugzilla->params->{'nobody_user'}, cache => 1}); my $bug_count = @$bug_ids; if ($bug_count == 0) { - warn "There are no bugs to move.\n"; - exit 1; + warn "There are no bugs to move.\n"; + exit 1; } print STDERR <<EOF; @@ -57,13 +60,16 @@ getc(); $dbh->bz_start_transaction; foreach my $bug_id (@$bug_ids) { - warn "Moving $bug_id...\n"; - - $dbh->do(q{INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, ?)}, - undef, $bug_id, $nobody->id, $timestamp, $field->id, $from_os, $to_os); - $dbh->do(q{UPDATE bugs SET op_sys = ?, delta_ts = ?, lastdiffed = ? WHERE bug_id = ?}, - undef, $to_os, $timestamp, $timestamp, $bug_id); + warn "Moving $bug_id...\n"; + + $dbh->do( + q{INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, ?)}, undef, $bug_id, $nobody->id, $timestamp, + $field->id, $from_os, $to_os + ); + $dbh->do( + q{UPDATE bugs SET op_sys = ?, delta_ts = ?, lastdiffed = ? WHERE bug_id = ?}, + undef, $to_os, $timestamp, $timestamp, $bug_id); } $dbh->bz_commit_transaction; diff --git a/scripts/movebugs.pl b/scripts/movebugs.pl index 55a43d943..8fc46a30c 100755 --- a/scripts/movebugs.pl +++ b/scripts/movebugs.pl @@ -24,7 +24,7 @@ use Bugzilla::Util; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 4) { - die <<USAGE; + die <<USAGE; Usage: movebugs.pl <old-product> <old-component> <new-product> <new-component> Eg. movebugs.pl mozilla.org bmo bugzilla.mozilla.org admin @@ -40,109 +40,107 @@ my ($old_product, $old_component, $new_product, $new_component) = @ARGV; my $dbh = Bugzilla->dbh; -my $old_product_id = $dbh->selectrow_array( - "SELECT id FROM products WHERE name=?", - undef, $old_product); -$old_product_id - or die "Can't find product ID for '$old_product'.\n"; - -my $old_component_id = $dbh->selectrow_array( - "SELECT id FROM components WHERE name=? AND product_id=?", - undef, $old_component, $old_product_id); -$old_component_id - or die "Can't find component ID for '$old_component'.\n"; - -my $new_product_id = $dbh->selectrow_array( - "SELECT id FROM products WHERE name=?", - undef, $new_product); -$new_product_id - or die "Can't find product ID for '$new_product'.\n"; - -my $new_component_id = $dbh->selectrow_array( - "SELECT id FROM components WHERE name=? AND product_id=?", - undef, $new_component, $new_product_id); -$new_component_id - or die "Can't find component ID for '$new_component'.\n"; - -my $product_field_id = $dbh->selectrow_array( - "SELECT id FROM fielddefs WHERE name = 'product'"); -$product_field_id - or die "Can't find field ID for 'product' field\n"; -my $component_field_id = $dbh->selectrow_array( - "SELECT id FROM fielddefs WHERE name = 'component'"); -$component_field_id - or die "Can't find field ID for 'component' field\n"; +my $old_product_id + = $dbh->selectrow_array("SELECT id FROM products WHERE name=?", + undef, $old_product); +$old_product_id or die "Can't find product ID for '$old_product'.\n"; + +my $old_component_id + = $dbh->selectrow_array( + "SELECT id FROM components WHERE name=? AND product_id=?", + undef, $old_component, $old_product_id); +$old_component_id or die "Can't find component ID for '$old_component'.\n"; + +my $new_product_id + = $dbh->selectrow_array("SELECT id FROM products WHERE name=?", + undef, $new_product); +$new_product_id or die "Can't find product ID for '$new_product'.\n"; + +my $new_component_id + = $dbh->selectrow_array( + "SELECT id FROM components WHERE name=? AND product_id=?", + undef, $new_component, $new_product_id); +$new_component_id or die "Can't find component ID for '$new_component'.\n"; + +my $product_field_id + = $dbh->selectrow_array("SELECT id FROM fielddefs WHERE name = 'product'"); +$product_field_id or die "Can't find field ID for 'product' field\n"; +my $component_field_id + = $dbh->selectrow_array("SELECT id FROM fielddefs WHERE name = 'component'"); +$component_field_id or die "Can't find field ID for 'component' field\n"; my $nobody = Bugzilla->params->{'nobody_user'}; -my $user_id = $dbh->selectrow_array( - "SELECT userid FROM profiles WHERE login_name=?", - undef, $nobody); -$user_id - or die "Can't find user ID for '$nobody'\n"; +my $user_id + = $dbh->selectrow_array("SELECT userid FROM profiles WHERE login_name=?", + undef, $nobody); +$user_id or die "Can't find user ID for '$nobody'\n"; $dbh->bz_start_transaction(); # build list of bugs -my $ra_ids = $dbh->selectcol_arrayref( - "SELECT bug_id FROM bugs WHERE product_id=? AND component_id=?", - undef, $old_product_id, $old_component_id); +my $ra_ids + = $dbh->selectcol_arrayref( + "SELECT bug_id FROM bugs WHERE product_id=? AND component_id=?", + undef, $old_product_id, $old_component_id); my $bug_count = scalar @$ra_ids; -$bug_count - or die "No bugs were found in '$old_component'\n"; +$bug_count or die "No bugs were found in '$old_component'\n"; my $where_sql = 'bug_id IN (' . join(',', @$ra_ids) . ')'; # check versions my @missing_versions; my $ra_versions = $dbh->selectcol_arrayref( - "SELECT DISTINCT version FROM bugs WHERE $where_sql"); + "SELECT DISTINCT version FROM bugs WHERE $where_sql"); foreach my $version (@$ra_versions) { - my $has_version = $dbh->selectrow_array( - "SELECT 1 FROM versions WHERE product_id=? AND value=?", - undef, $new_product_id, $version); - push @missing_versions, $version unless $has_version; + my $has_version + = $dbh->selectrow_array( + "SELECT 1 FROM versions WHERE product_id=? AND value=?", + undef, $new_product_id, $version); + push @missing_versions, $version unless $has_version; } # check milestones my @missing_milestones; my $ra_milestones = $dbh->selectcol_arrayref( - "SELECT DISTINCT target_milestone FROM bugs WHERE $where_sql"); + "SELECT DISTINCT target_milestone FROM bugs WHERE $where_sql"); foreach my $milestone (@$ra_milestones) { - my $has_milestone = $dbh->selectrow_array( - "SELECT 1 FROM milestones WHERE product_id=? AND value=?", - undef, $new_product_id, $milestone); - push @missing_milestones, $milestone unless $has_milestone; + my $has_milestone + = $dbh->selectrow_array( + "SELECT 1 FROM milestones WHERE product_id=? AND value=?", + undef, $new_product_id, $milestone); + push @missing_milestones, $milestone unless $has_milestone; } # check flags my @missing_flags; my $ra_old_types = $dbh->selectcol_arrayref( - "SELECT DISTINCT type_id + "SELECT DISTINCT type_id FROM flags INNER JOIN flagtypes ON flagtypes.id = flags.type_id - WHERE $where_sql"); -my $ra_new_types = - Bugzilla::FlagType::match({ product_id => $new_product_id, - component_id => $new_component_id }); + WHERE $where_sql" +); +my $ra_new_types = Bugzilla::FlagType::match( + {product_id => $new_product_id, component_id => $new_component_id}); foreach my $old_type (@$ra_old_types) { - unless (grep { $_->id == $old_type } @$ra_new_types) { - my $flagtype = Bugzilla::FlagType->new($old_type); - push @missing_flags, $flagtype->name . ' (' . $flagtype->target_type . ')'; - } + unless (grep { $_->id == $old_type } @$ra_new_types) { + my $flagtype = Bugzilla::FlagType->new($old_type); + push @missing_flags, $flagtype->name . ' (' . $flagtype->target_type . ')'; + } } # show missing my $missing_error = ''; if (@missing_versions) { - $missing_error .= "'$new_product' is missing the following version(s):\n " . - join("\n ", @missing_versions) . "\n"; + $missing_error .= "'$new_product' is missing the following version(s):\n " + . join("\n ", @missing_versions) . "\n"; } if (@missing_milestones) { - $missing_error .= "'$new_product' is missing the following milestone(s):\n " . - join("\n ", @missing_milestones) . "\n"; + $missing_error .= "'$new_product' is missing the following milestone(s):\n " + . join("\n ", @missing_milestones) . "\n"; } if (@missing_flags) { - $missing_error .= "'$new_product'::'$new_component' is missing the following flag(s):\n " . - join("\n ", @missing_flags) . "\n"; + $missing_error + .= "'$new_product'::'$new_component' is missing the following flag(s):\n " + . join("\n ", @missing_flags) . "\n"; } die $missing_error if $missing_error; @@ -156,12 +154,12 @@ Press <Ctrl-C> to stop or <Enter> to continue... EOF getc(); -print "Moving $bug_count bugs from $old_product:$old_component to $new_product:$new_component\n"; +print + "Moving $bug_count bugs from $old_product:$old_component to $new_product:$new_component\n"; # update bugs -$dbh->do( - "UPDATE bugs SET product_id=?, component_id=? WHERE $where_sql", - undef, $new_product_id, $new_component_id); +$dbh->do("UPDATE bugs SET product_id=?, component_id=? WHERE $where_sql", + undef, $new_product_id, $new_component_id); # touch bugs $dbh->do("UPDATE bugs SET delta_ts=NOW() WHERE $where_sql"); @@ -169,22 +167,22 @@ $dbh->do("UPDATE bugs SET lastdiffed=NOW() WHERE $where_sql"); # update bugs_activity $dbh->do( - "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) SELECT bug_id, ?, delta_ts, ?, ?, ? FROM bugs WHERE $where_sql", - undef, - $user_id, $product_field_id, $old_product, $new_product); + undef, $user_id, $product_field_id, $old_product, $new_product +); $dbh->do( - "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) SELECT bug_id, ?, delta_ts, ?, ?, ? FROM bugs WHERE $where_sql", - undef, - $user_id, $component_field_id, $old_component, $new_component); + undef, $user_id, $component_field_id, $old_component, $new_component +); -Bugzilla::Hook::process('reorg_move_bugs', { bug_ids => $ra_ids } ); +Bugzilla::Hook::process('reorg_move_bugs', {bug_ids => $ra_ids}); $dbh->bz_commit_transaction(); foreach my $bug_id (@$ra_ids) { - Bugzilla->memcached->clear({ table => 'bugs', id => $bug_id }); + Bugzilla->memcached->clear({table => 'bugs', id => $bug_id}); } # It's complex to determine which items now need to be flushed from memcached. diff --git a/scripts/movecomponent.pl b/scripts/movecomponent.pl index 4c3b26cfb..c22d937c1 100755 --- a/scripts/movecomponent.pl +++ b/scripts/movecomponent.pl @@ -22,7 +22,7 @@ use Bugzilla::Util; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 3) { - die <<USAGE; + die <<USAGE; Usage: movecomponent.pl <oldproduct> <newproduct> <component> E.g.: movecomponent.pl ReplicationEngine FoodReplicator SeaMonkey @@ -36,45 +36,51 @@ USAGE } my ($old_product_name, $new_product_name, $component_name) = @ARGV; -my $old_product = Bugzilla::Product->check({ name => $old_product_name }); -my $new_product = Bugzilla::Product->check({ name => $new_product_name }); -my $component = Bugzilla::Component->check({ product => $old_product, name => $component_name }); -my $field_id = get_field_id('product'); +my $old_product = Bugzilla::Product->check({name => $old_product_name}); +my $new_product = Bugzilla::Product->check({name => $new_product_name}); +my $component = Bugzilla::Component->check( + {product => $old_product, name => $component_name}); +my $field_id = get_field_id('product'); my $dbh = Bugzilla->dbh; # check versions my @missing_versions; -my $ra_versions = $dbh->selectcol_arrayref( - "SELECT DISTINCT version FROM bugs WHERE component_id = ?", - undef, $component->id); +my $ra_versions + = $dbh->selectcol_arrayref( + "SELECT DISTINCT version FROM bugs WHERE component_id = ?", + undef, $component->id); foreach my $version (@$ra_versions) { - my $has_version = $dbh->selectrow_array( - "SELECT 1 FROM versions WHERE product_id = ? AND value = ?", - undef, $new_product->id, $version); - push @missing_versions, $version unless $has_version; + my $has_version + = $dbh->selectrow_array( + "SELECT 1 FROM versions WHERE product_id = ? AND value = ?", + undef, $new_product->id, $version); + push @missing_versions, $version unless $has_version; } # check milestones my @missing_milestones; -my $ra_milestones = $dbh->selectcol_arrayref( - "SELECT DISTINCT target_milestone FROM bugs WHERE component_id = ?", - undef, $component->id); +my $ra_milestones + = $dbh->selectcol_arrayref( + "SELECT DISTINCT target_milestone FROM bugs WHERE component_id = ?", + undef, $component->id); foreach my $milestone (@$ra_milestones) { - my $has_milestone = $dbh->selectrow_array( - "SELECT 1 FROM milestones WHERE product_id=? AND value=?", - undef, $new_product->id, $milestone); - push @missing_milestones, $milestone unless $has_milestone; + my $has_milestone + = $dbh->selectrow_array( + "SELECT 1 FROM milestones WHERE product_id=? AND value=?", + undef, $new_product->id, $milestone); + push @missing_milestones, $milestone unless $has_milestone; } my $missing_error = ''; if (@missing_versions) { - $missing_error .= "'$new_product_name' is missing the following version(s):\n " . - join("\n ", @missing_versions) . "\n"; + $missing_error .= "'$new_product_name' is missing the following version(s):\n " + . join("\n ", @missing_versions) . "\n"; } if (@missing_milestones) { - $missing_error .= "'$new_product_name' is missing the following milestone(s):\n " . - join("\n ", @missing_milestones) . "\n"; + $missing_error + .= "'$new_product_name' is missing the following milestone(s):\n " + . join("\n ", @missing_milestones) . "\n"; } die $missing_error if $missing_error; @@ -88,17 +94,18 @@ Press <Ctrl-C> to stop or <Enter> to continue... EOF getc(); -print "Moving '$component_name' from '$old_product_name' to '$new_product_name'...\n\n"; +print + "Moving '$component_name' from '$old_product_name' to '$new_product_name'...\n\n"; $dbh->bz_start_transaction(); -my $ra_ids = $dbh->selectcol_arrayref( - "SELECT bug_id FROM bugs WHERE product_id=? AND component_id=?", - undef, $old_product->id, $component->id); +my $ra_ids + = $dbh->selectcol_arrayref( + "SELECT bug_id FROM bugs WHERE product_id=? AND component_id=?", + undef, $old_product->id, $component->id); # Bugs table $dbh->do("UPDATE bugs SET product_id = ? WHERE component_id = ?", - undef, - ($new_product->id, $component->id)); + undef, ($new_product->id, $component->id)); # Flags tables fix_flags('flaginclusions', $new_product, $component); @@ -106,34 +113,41 @@ fix_flags('flagexclusions', $new_product, $component); # Components $dbh->do("UPDATE components SET product_id = ? WHERE id = ?", - undef, - ($new_product->id, $component->id)); + undef, ($new_product->id, $component->id)); -Bugzilla::Hook::process('reorg_move_component', { +Bugzilla::Hook::process( + 'reorg_move_component', + { old_product => $old_product, new_product => $new_product, component => $component, -} ); + } +); # Mark bugs as touched -$dbh->do("UPDATE bugs SET delta_ts = NOW() - WHERE component_id = ?", undef, $component->id); -$dbh->do("UPDATE bugs SET lastdiffed = NOW() - WHERE component_id = ?", undef, $component->id); +$dbh->do( + "UPDATE bugs SET delta_ts = NOW() + WHERE component_id = ?", undef, $component->id +); +$dbh->do( + "UPDATE bugs SET lastdiffed = NOW() + WHERE component_id = ?", undef, $component->id +); # Update bugs_activity -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); my $userid = $auto_user->id; Bugzilla->set_user($auto_user); -$dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, +$dbh->do( + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) SELECT bug_id, ?, delta_ts, ?, ?, ? - FROM bugs WHERE component_id = ?", - undef, - ($userid, $field_id, $old_product_name, $new_product_name, $component->id)); + FROM bugs WHERE component_id = ?", undef, + ($userid, $field_id, $old_product_name, $new_product_name, $component->id) +); -Bugzilla::Hook::process('reorg_move_bugs', { bug_ids => $ra_ids } ); +Bugzilla::Hook::process('reorg_move_bugs', {bug_ids => $ra_ids}); $dbh->bz_commit_transaction(); @@ -142,15 +156,17 @@ $dbh->bz_commit_transaction(); Bugzilla->memcached->clear_all(); sub fix_flags { - my ($table, $new_product, $component) = @_; - my $dbh = Bugzilla->dbh; - - my $type_ids = $dbh->selectcol_arrayref("SELECT DISTINCT type_id FROM $table WHERE component_id = ?", - undef, - $component->id); - $dbh->do("DELETE FROM $table WHERE component_id = ?", undef, $component->id); - foreach my $type_id (@$type_ids) { - $dbh->do("INSERT INTO $table (type_id, product_id, component_id) VALUES (?, ?, ?)", - undef, ($type_id, $new_product->id, $component->id)); - } + my ($table, $new_product, $component) = @_; + my $dbh = Bugzilla->dbh; + + my $type_ids + = $dbh->selectcol_arrayref( + "SELECT DISTINCT type_id FROM $table WHERE component_id = ?", + undef, $component->id); + $dbh->do("DELETE FROM $table WHERE component_id = ?", undef, $component->id); + foreach my $type_id (@$type_ids) { + $dbh->do( + "INSERT INTO $table (type_id, product_id, component_id) VALUES (?, ?, ?)", + undef, ($type_id, $new_product->id, $component->id)); + } } diff --git a/scripts/nagios_blocker_checker.pl b/scripts/nagios_blocker_checker.pl index 01a7b7348..bbae5625d 100755 --- a/scripts/nagios_blocker_checker.pl +++ b/scripts/nagios_blocker_checker.pl @@ -21,31 +21,35 @@ use English qw(-no_match_vars); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); Bugzilla->error_mode(ERROR_MODE_DIE); -use Try::Tiny; # bmo ships with this nowadays +use Try::Tiny; # bmo ships with this nowadays my $config = { - # filter by assignee, product or component - assignee => '', - product => '', - component => '', - unassigned => Bugzilla->params->{'nobody_user'}, - # severities - severity => 'major,critical,blocker', - # time in hours to wait before paging/warning - major_alarm => 24, - major_warn => 20, - critical_alarm => 8, - critical_warn => 5, - blocker_alarm => 0, - blocker_warn => 0, - any_alarm => 24, - any_warn => 20, - # time in seconds before terminating this script - # 300 chosen as it is longer than the default NRPE timeout - # (meaning you should never need to tweak it upward) and - # shorter than what you are likely to do checking bugs - # (meaning you won't pile up too many instances before they die) - max_runtime => 300, + + # filter by assignee, product or component + assignee => '', + product => '', + component => '', + unassigned => Bugzilla->params->{'nobody_user'}, + + # severities + severity => 'major,critical,blocker', + + # time in hours to wait before paging/warning + major_alarm => 24, + major_warn => 20, + critical_alarm => 8, + critical_warn => 5, + blocker_alarm => 0, + blocker_warn => 0, + any_alarm => 24, + any_warn => 20, + + # time in seconds before terminating this script + # 300 chosen as it is longer than the default NRPE timeout + # (meaning you should never need to tweak it upward) and + # shorter than what you are likely to do checking bugs + # (meaning you won't pile up too many instances before they die) + max_runtime => 300, }; my $usage = <<"EOF"; @@ -103,142 +107,145 @@ EXAMPLES EOF GetOptions( - 'assignee=s' => \$config->{assignee}, - 'product=s' => \$config->{product}, - 'component=s' => \$config->{component}, - 'severity=s' => \$config->{severity}, - 'major_alarm=i' => \$config->{major_alarm}, - 'major_warn=i' => \$config->{major_warn}, - 'critical_alarm=i' => \$config->{critical_alarm}, - 'critical_warn=i' => \$config->{critical_warn}, - 'blocker_alarm=i' => \$config->{blocker_alarm}, - 'blocker_warn=i' => \$config->{blocker_warn}, - 'any_alarm=i' => \$config->{any_alarm}, - 'any_warn=i' => \$config->{any_warn}, - 'max_runtime=i' => \$config->{max_runtime}, - 'help|?' => \$config->{help}, + 'assignee=s' => \$config->{assignee}, + 'product=s' => \$config->{product}, + 'component=s' => \$config->{component}, + 'severity=s' => \$config->{severity}, + 'major_alarm=i' => \$config->{major_alarm}, + 'major_warn=i' => \$config->{major_warn}, + 'critical_alarm=i' => \$config->{critical_alarm}, + 'critical_warn=i' => \$config->{critical_warn}, + 'blocker_alarm=i' => \$config->{blocker_alarm}, + 'blocker_warn=i' => \$config->{blocker_warn}, + 'any_alarm=i' => \$config->{any_alarm}, + 'any_warn=i' => \$config->{any_warn}, + 'max_runtime=i' => \$config->{max_runtime}, + 'help|?' => \$config->{help}, ) or die $usage; $config->{assignee} = $ARGV[0] if !$config->{assignee} && @ARGV; -die $usage if - $config->{help} - || !($config->{assignee} || $config->{product}) - || ($config->{assignee} && $config->{product}) - || ($config->{component} && !$config->{product}) - || !$config->{severity}; +die $usage + if $config->{help} + || !($config->{assignee} || $config->{product}) + || ($config->{assignee} && $config->{product}) + || ($config->{component} && !$config->{product}) + || !$config->{severity}; # -use constant NAGIOS_OK => 0; -use constant NAGIOS_WARNING => 1; -use constant NAGIOS_CRITICAL => 2; -use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; +use constant NAGIOS_OK => 0; +use constant NAGIOS_WARNING => 1; +use constant NAGIOS_CRITICAL => 2; +use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; my $current_state = NAGIOS_OK; try { - # Per bug 1330293, the checker script can get confused/hung up - # if the DB rotates out from under it. Since a long-running - # 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."; - FATAL($message); - die "$message\n"; - }; - alarm($config->{max_runtime}); - - my $dbh = Bugzilla->switch_to_shadow_db; - my $any_severity = $config->{severity} eq 'any'; - my ($where, @values); - - if ($config->{assignee}) { - $where = 'bugs.assigned_to = ?'; - push @values, Bugzilla::User->check({ name => $config->{assignee} })->id; - - } elsif ($config->{component}) { - $where = 'bugs.product_id = ? AND bugs.component_id = ? AND bugs.assigned_to = ?'; - my $product = Bugzilla::Product->check({ name => $config->{product} }); - push @values, $product->id; - push @values, Bugzilla::Component->check({ product => $product, name => $config->{component} })->id; - push @values, Bugzilla::User->check({ name => $config->{unassigned} })->id; - - } else { - $where = 'bugs.product_id = ? AND bugs.assigned_to = ?'; - push @values, Bugzilla::Product->check({ name => $config->{product} })->id; - push @values, Bugzilla::User->check({ name => $config->{unassigned} })->id; - } - - if (!$any_severity) { - my $severities = join ',', map { $dbh->quote($_) } split(/,/, $config->{severity}); - $where .= " AND bug_severity IN ($severities)"; - } - - my $sql = <<"EOF"; + # Per bug 1330293, the checker script can get confused/hung up + # if the DB rotates out from under it. Since a long-running + # 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."; + FATAL($message); + die "$message\n"; + }; + alarm($config->{max_runtime}); + + my $dbh = Bugzilla->switch_to_shadow_db; + my $any_severity = $config->{severity} eq 'any'; + my ($where, @values); + + if ($config->{assignee}) { + $where = 'bugs.assigned_to = ?'; + push @values, Bugzilla::User->check({name => $config->{assignee}})->id; + + } + elsif ($config->{component}) { + $where + = 'bugs.product_id = ? AND bugs.component_id = ? AND bugs.assigned_to = ?'; + my $product = Bugzilla::Product->check({name => $config->{product}}); + push @values, $product->id; + push @values, + Bugzilla::Component->check( + {product => $product, name => $config->{component}})->id; + push @values, Bugzilla::User->check({name => $config->{unassigned}})->id; + + } + else { + $where = 'bugs.product_id = ? AND bugs.assigned_to = ?'; + push @values, Bugzilla::Product->check({name => $config->{product}})->id; + push @values, Bugzilla::User->check({name => $config->{unassigned}})->id; + } + + if (!$any_severity) { + my $severities = join ',', + map { $dbh->quote($_) } split(/,/, $config->{severity}); + $where .= " AND bug_severity IN ($severities)"; + } + + my $sql = <<"EOF"; SELECT bug_id, bug_severity, UNIX_TIMESTAMP(bugs.creation_ts) AS ts FROM bugs WHERE $where AND COALESCE(resolution, '') = '' EOF - my $bugs = { - 'major' => [], - 'critical' => [], - 'blocker' => [], - 'any' => [], - }; - my $current_time = time; - - foreach my $bug (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, @values) }) { - my $severity = $any_severity ? 'any' : $bug->{bug_severity}; - my $age = ($current_time - $bug->{ts}) / 3600; - - if ($age > $config->{"${severity}_alarm"}) { - $current_state = NAGIOS_CRITICAL; - push @{$bugs->{$severity}}, $bug->{bug_id}; - - } elsif ($age > $config->{"${severity}_warn"}) { - if ($current_state < NAGIOS_WARNING) { - $current_state = NAGIOS_WARNING; - } - push @{$bugs->{$severity}}, $bug->{bug_id}; - - } + my $bugs = {'major' => [], 'critical' => [], 'blocker' => [], 'any' => [],}; + my $current_time = time; + + foreach my $bug (@{$dbh->selectall_arrayref($sql, {Slice => {}}, @values)}) { + my $severity = $any_severity ? 'any' : $bug->{bug_severity}; + my $age = ($current_time - $bug->{ts}) / 3600; + + if ($age > $config->{"${severity}_alarm"}) { + $current_state = NAGIOS_CRITICAL; + push @{$bugs->{$severity}}, $bug->{bug_id}; + } + elsif ($age > $config->{"${severity}_warn"}) { + if ($current_state < NAGIOS_WARNING) { + $current_state = NAGIOS_WARNING; + } + push @{$bugs->{$severity}}, $bug->{bug_id}; - print 'bugs ' . NAGIOS_NAMES->[$current_state] . ': '; - if ($current_state == NAGIOS_OK) { - if ($config->{severity} eq 'any') { - print 'No unassigned bugs found.'; - } else { - print "No $config->{severity} bugs found." - } } - foreach my $severity (qw( blocker critical major any )) { - my $list = $bugs->{$severity}; - if (@$list) { - printf - '%s %s %s found https://bugzil.la/' . join(',', @$list) . ' ', - scalar(@$list), - ($any_severity ? 'unassigned' : $severity), - (scalar(@$list) == 1 ? 'bug' : 'bugs'); - } + } + + print 'bugs ' . NAGIOS_NAMES->[$current_state] . ': '; + if ($current_state == NAGIOS_OK) { + if ($config->{severity} eq 'any') { + print 'No unassigned bugs found.'; + } + else { + print "No $config->{severity} bugs found."; + } + } + foreach my $severity (qw( blocker critical major any )) { + my $list = $bugs->{$severity}; + if (@$list) { + printf '%s %s %s found https://bugzil.la/' . join(',', @$list) . ' ', + scalar(@$list), ($any_severity ? 'unassigned' : $severity), + (scalar(@$list) == 1 ? 'bug' : 'bugs'); } - print "\n"; - alarm 0; -} catch { - # Anything that trips an error, we're calling nagios-critical - $current_state = NAGIOS_CRITICAL; - # - # Templates often have linebreaks ; nagios really prefers a status - # to be on one line. Here we strip out breaks, and try to make sure - # there's spacing in place when we crunch those lines together. - s/\s?\r?\n/ /g; - # - # Now, just print the status we got out. - # Keep in mind, depending on when 'try' blew out, we may have - # already printed SOMETHING. Can't help that without a much more - # thorough fix. Our majority case here is a blowout from BZ - # where a Product/Component went away, ala bug 1326233. - print "$_\n"; + } + print "\n"; + alarm 0; +} +catch { + # Anything that trips an error, we're calling nagios-critical + $current_state = NAGIOS_CRITICAL; + # + # Templates often have linebreaks ; nagios really prefers a status + # to be on one line. Here we strip out breaks, and try to make sure + # there's spacing in place when we crunch those lines together. + s/\s?\r?\n/ /g; + # + # Now, just print the status we got out. + # Keep in mind, depending on when 'try' blew out, we may have + # already printed SOMETHING. Can't help that without a much more + # thorough fix. Our majority case here is a blowout from BZ + # where a Product/Component went away, ala bug 1326233. + print "$_\n"; }; exit $current_state; diff --git a/scripts/nagios_push_checker.pl b/scripts/nagios_push_checker.pl index ef350c3e1..4ff43f0da 100755 --- a/scripts/nagios_push_checker.pl +++ b/scripts/nagios_push_checker.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Constants; use Bugzilla::Product; @@ -22,11 +20,7 @@ use Getopt::Long; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $config = { - connector => '', - warn => 5, - alarm => 10, -}; +my $config = {connector => '', warn => 5, alarm => 10,}; my $usage = <<EOF; DESCRIPTION @@ -46,39 +40,39 @@ EXAMPLES nagios_push_checker.pl --connector TCL --warn 25 --alarm 50 EOF -die($usage) unless GetOptions( - 'connector=s' => \$config->{connector}, - 'warn=i' => \$config->{warn}, - 'alarm=i' => \$config->{alarm}, - 'help|?' => \$config->{help}, -); +die($usage) + unless GetOptions( + 'connector=s' => \$config->{connector}, + 'warn=i' => \$config->{warn}, + 'alarm=i' => \$config->{alarm}, + 'help|?' => \$config->{help}, + ); die $usage if $config->{help} || !$config->{connector}; # -use constant NAGIOS_OK => 0; -use constant NAGIOS_WARNING => 1; -use constant NAGIOS_CRITICAL => 2; -use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; +use constant NAGIOS_OK => 0; +use constant NAGIOS_WARNING => 1; +use constant NAGIOS_CRITICAL => 2; +use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; my $dbh = Bugzilla->switch_to_shadow_db; -my ($count) = $dbh->selectrow_array( - "SELECT COUNT(*) FROM push_backlog WHERE connector=?", - undef, - $config->{connector}, -); +my ($count) + = $dbh->selectrow_array("SELECT COUNT(*) FROM push_backlog WHERE connector=?", + undef, $config->{connector},); my $state; if ($count >= $config->{alarm}) { - $state = NAGIOS_CRITICAL; -} elsif ($count >= $config->{warn}) { - $state = NAGIOS_WARNING; -} else { - $state = NAGIOS_OK; + $state = NAGIOS_CRITICAL; +} +elsif ($count >= $config->{warn}) { + $state = NAGIOS_WARNING; +} +else { + $state = NAGIOS_OK; } -print "push ", NAGIOS_NAMES->[$state], ": ", $count, " ", - "push.", $config->{connector}, " message", - ($count == 1 ? '' : 's'), " in backlog\n"; +print "push ", NAGIOS_NAMES->[$state], ": ", $count, " ", "push.", + $config->{connector}, " message", ($count == 1 ? '' : 's'), " in backlog\n"; exit $state; diff --git a/scripts/nuke-bugs.pl b/scripts/nuke-bugs.pl index 6faf7d694..d48fe952b 100755 --- a/scripts/nuke-bugs.pl +++ b/scripts/nuke-bugs.pl @@ -64,8 +64,8 @@ $dbh->do("DELETE FROM bugs_fulltext"); print "All done!\n"; sub delete_from_table { - my $table = shift; - print "Deleting from $table..."; - $dbh->do("DELETE FROM $table"); - print "done.\n"; + my $table = shift; + print "Deleting from $table..."; + $dbh->do("DELETE FROM $table"); + print "done.\n"; } diff --git a/scripts/reassign_open_bugs.pl b/scripts/reassign_open_bugs.pl index d0f107c16..bb2160381 100755 --- a/scripts/reassign_open_bugs.pl +++ b/scripts/reassign_open_bugs.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::User; use Bugzilla::Constants; @@ -27,30 +25,30 @@ BEGIN { Bugzilla->extensions(); } Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($from, $to); -GetOptions( - "from|f=s" => \$from, - "to|t=s" => \$to, -); +GetOptions("from|f=s" => \$from, "to|t=s" => \$to,); pod2usage(1) unless defined $from && defined $to; my $dbh = Bugzilla->dbh; my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); -my $field = Bugzilla::Field->check({ name => 'assigned_to', cache => 1 }); -my $from_user = Bugzilla::User->check({ name => $from, cache => 1 }); -my $to_user = Bugzilla::User->check({ name => $to, cache => 1 }); +my $field = Bugzilla::Field->check({name => 'assigned_to', cache => 1}); +my $from_user = Bugzilla::User->check({name => $from, cache => 1}); +my $to_user = Bugzilla::User->check({name => $to, cache => 1}); -my $bugs = $dbh->selectcol_arrayref(q{SELECT bug_id +my $bugs = $dbh->selectcol_arrayref( + q{SELECT bug_id FROM bugs LEFT JOIN bug_status ON bug_status.value = bugs.bug_status WHERE bug_status.is_open = 1 - AND bugs.assigned_to = ?}, undef, $from_user->id); + AND bugs.assigned_to = ?}, undef, + $from_user->id +); my $bug_count = @$bugs; if ($bug_count == 0) { - warn "There are no bugs to move.\n"; - exit 1; + warn "There are no bugs to move.\n"; + exit 1; } print STDERR <<EOF; @@ -62,12 +60,16 @@ getc(); $dbh->bz_start_transaction; foreach my $bug_id (@$bugs) { - warn "Updating bug $bug_id\n"; - $dbh->do(q{INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, ?)}, - undef, $bug_id, $to_user->id, $timestamp, $field->id, $from_user->login, $to_user->login); - $dbh->do(q{UPDATE bugs SET assigned_to = ?, delta_ts = ?, lastdiffed = ? WHERE bug_id = ?}, - undef, $to_user->id, $timestamp, $timestamp, $bug_id); + warn "Updating bug $bug_id\n"; + $dbh->do( + q{INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, ?)}, undef, $bug_id, $to_user->id, + $timestamp, $field->id, $from_user->login, $to_user->login + ); + $dbh->do( + q{UPDATE bugs SET assigned_to = ?, delta_ts = ?, lastdiffed = ? WHERE bug_id = ?}, + undef, $to_user->id, $timestamp, $timestamp, $bug_id + ); } $from_user->clear_last_statistics_ts(); $to_user->clear_last_statistics_ts(); diff --git a/scripts/remove-non-public-data.pl b/scripts/remove-non-public-data.pl index 47c123464..265734d65 100755 --- a/scripts/remove-non-public-data.pl +++ b/scripts/remove-non-public-data.pl @@ -13,10 +13,11 @@ 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))); + require lib; + my $dir = rel2abs(catdir(dirname(__FILE__), '..')); + lib->import($dir, catdir($dir, 'lib'), catdir($dir, qw(local lib perl5))); } use autodie; @@ -29,94 +30,146 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); # database. my %whitelist = ( - attachments => [qw( - attach_id bug_id creation_ts modification_time description - mimetype ispatch filename submitter_id isobsolete attach_size - )], - bug_mentors => [qw( - bug_id user_id - )], - bug_see_also => [qw( - id bug_id value - )], - bugs => [qw( - bug_id assigned_to bug_file_loc bug_severity bug_status - creation_ts delta_ts short_desc op_sys priority product_id - rep_platform reporter version component_id resolution - target_milestone qa_contact status_whiteboard everconfirmed - estimated_time remaining_time deadline alias cf_rank - cf_crash_signature cf_last_resolved cf_user_story votes - )], - bugs_activity => [qw( - id bug_id attach_id who bug_when fieldid added removed - comment_id - )], - cc => [qw( - bug_id who - )], - classifications => [qw( - id name description sortkey - )], - components => [qw( - id name product_id description isactive - )], - dependencies => [qw( - blocked dependson - )], - duplicates => [qw( - dupe_of dupe - )], - fielddefs => [qw( - id name type custom description obsolete - )], - flag_state_activity => [qw( - id flag_when type_id flag_id setter_id requestee_id bug_id - attachment_id status - )], - flags => [qw( - id type_id status bug_id attach_id creation_date - modification_date setter_id requestee_id - )], - flagtypes => [qw( - id name description target_type is_active - )], - keyworddefs => [qw( - id name description is_active - )], - keywords => [qw( - bug_id keywordid - )], - longdescs => [qw( - comment_id bug_id who bug_when work_time thetext type - extra_data - )], - longdescs_tags => [qw( - id comment_id tag - )], - longdescs_tags_activity => [qw( - id bug_id comment_id who bug_when added removed - )], - milestones => [qw( - id product_id value sortkey isactive - )], - products => [qw( - id name classification_id description isactive defaultmilestone - )], - profiles => [qw( - userid login_name realname is_enabled creation_ts - )], - tracking_flags => [qw( - id field_id name description type sortkey is_active - )], - tracking_flags_bugs => [qw( - id tracking_flag_id bug_id value - )], - tracking_flags_values => [qw( - id tracking_flag_id setter_group_id value sortkey is_active - )], - versions => [qw( - id value product_id isactive - )], + attachments => [ + qw( + attach_id bug_id creation_ts modification_time description + mimetype ispatch filename submitter_id isobsolete attach_size + ) + ], + bug_mentors => [ + qw( + bug_id user_id + ) + ], + bug_see_also => [ + qw( + id bug_id value + ) + ], + bugs => [ + qw( + bug_id assigned_to bug_file_loc bug_severity bug_status + creation_ts delta_ts short_desc op_sys priority product_id + rep_platform reporter version component_id resolution + target_milestone qa_contact status_whiteboard everconfirmed + estimated_time remaining_time deadline alias cf_rank + cf_crash_signature cf_last_resolved cf_user_story votes + ) + ], + bugs_activity => [ + qw( + id bug_id attach_id who bug_when fieldid added removed + comment_id + ) + ], + cc => [ + qw( + bug_id who + ) + ], + classifications => [ + qw( + id name description sortkey + ) + ], + components => [ + qw( + id name product_id description isactive + ) + ], + dependencies => [ + qw( + blocked dependson + ) + ], + duplicates => [ + qw( + dupe_of dupe + ) + ], + fielddefs => [ + qw( + id name type custom description obsolete + ) + ], + flag_state_activity => [ + qw( + id flag_when type_id flag_id setter_id requestee_id bug_id + attachment_id status + ) + ], + flags => [ + qw( + id type_id status bug_id attach_id creation_date + modification_date setter_id requestee_id + ) + ], + flagtypes => [ + qw( + id name description target_type is_active + ) + ], + keyworddefs => [ + qw( + id name description is_active + ) + ], + keywords => [ + qw( + bug_id keywordid + ) + ], + longdescs => [ + qw( + comment_id bug_id who bug_when work_time thetext type + extra_data + ) + ], + longdescs_tags => [ + qw( + id comment_id tag + ) + ], + longdescs_tags_activity => [ + qw( + id bug_id comment_id who bug_when added removed + ) + ], + milestones => [ + qw( + id product_id value sortkey isactive + ) + ], + products => [ + qw( + id name classification_id description isactive defaultmilestone + ) + ], + profiles => [ + qw( + userid login_name realname is_enabled creation_ts + ) + ], + tracking_flags => [ + qw( + id field_id name description type sortkey is_active + ) + ], + tracking_flags_bugs => [ + qw( + id tracking_flag_id bug_id value + ) + ], + tracking_flags_values => [ + qw( + id tracking_flag_id setter_group_id value sortkey is_active + ) + ], + versions => [ + qw( + id value product_id isactive + ) + ], ); # @@ -143,39 +196,47 @@ 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"; + die "sanitization failed\n"; } # drop all views -foreach my $view (sort @{ $dbh->selectcol_arrayref("SHOW FULL TABLES IN $db_name WHERE TABLE_TYPE LIKE 'VIEW'") }) { - print "dropping view $view\n"; - $dbh->do("DROP VIEW $view"); +foreach my $view ( + sort @{ + $dbh->selectcol_arrayref( + "SHOW FULL TABLES IN $db_name WHERE TABLE_TYPE LIKE 'VIEW'") + } + ) +{ + print "dropping view $view\n"; + $dbh->do("DROP VIEW $view"); } # drop tables/columns -my @tables = sort @{ $dbh->selectcol_arrayref("SHOW TABLES") }; +my @tables = sort @{$dbh->selectcol_arrayref("SHOW TABLES")}; foreach my $table (@tables) { - if (exists $whitelist{$table}) { - my @drop_columns; - foreach my $column (map { $_->{Field} } @{ $dbh->selectall_arrayref("DESCRIBE $table", { Slice => {} }) }) { - unless (any { $_ eq $column } @{ $whitelist{$table} }) { - print "dropping references to $table.$column\n"; - drop_referencing($table, $column); - push @drop_columns, "DROP COLUMN $column"; - } - } - if (@drop_columns) { - print "dropping columns from $table\n"; - $dbh->do("ALTER TABLE $table " . join(", ", @drop_columns)); - } + if (exists $whitelist{$table}) { + my @drop_columns; + foreach my $column (map { $_->{Field} } + @{$dbh->selectall_arrayref("DESCRIBE $table", {Slice => {}})}) + { + unless (any { $_ eq $column } @{$whitelist{$table}}) { + print "dropping references to $table.$column\n"; + drop_referencing($table, $column); + push @drop_columns, "DROP COLUMN $column"; + } } - else { - print "dropping $table\n"; - drop_referencing($table); - $dbh->do("DROP TABLE IF EXISTS $table"); + if (@drop_columns) { + print "dropping columns from $table\n"; + $dbh->do("ALTER TABLE $table " . join(", ", @drop_columns)); } + } + else { + print "dropping $table\n"; + drop_referencing($table); + $dbh->do("DROP TABLE IF EXISTS $table"); + } } # remove users with no activity @@ -198,56 +259,55 @@ $dbh->do(" "); sub drop_referencing { - my ($table, $column) = @_; - my ($sql, @values); + my ($table, $column) = @_; + my ($sql, @values); - # drop foreign keys that reference this table/column - $sql = " + # drop foreign keys that reference this table/column + $sql = " SELECT DISTINCT TABLE_NAME 'table', CONSTRAINT_NAME name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ? AND REFERENCED_TABLE_NAME = ? "; - @values = ($db_name, $table); - if ($column) { - $sql .= " AND REFERENCED_COLUMN_NAME = ?"; - push @values, $column; - } - foreach my $fk (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, @values) }) { - print " dropping fk $fk->{table}.$fk->{name}\n"; - $dbh->do("ALTER TABLE $fk->{table} DROP FOREIGN KEY $fk->{name}"); - } + @values = ($db_name, $table); + if ($column) { + $sql .= " AND REFERENCED_COLUMN_NAME = ?"; + push @values, $column; + } + foreach my $fk (@{$dbh->selectall_arrayref($sql, {Slice => {}}, @values)}) { + print " dropping fk $fk->{table}.$fk->{name}\n"; + $dbh->do("ALTER TABLE $fk->{table} DROP FOREIGN KEY $fk->{name}"); + } - # drop indexes - if ($column) { - # drop associated fk/index - $sql = " + # drop indexes + if ($column) { + + # drop associated fk/index + $sql = " SELECT DISTINCT TABLE_NAME 'table', CONSTRAINT_NAME name, REFERENCED_TABLE_NAME ref FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ? "; - @values = ($db_name, $table, $column); - foreach my $fk (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, @values) }) { - if ($fk->{ref}) { - print " dropping fk $fk->{table}.$fk->{name}\n"; - $dbh->do("ALTER TABLE $fk->{table} DROP FOREIGN KEY $fk->{name}"); - } - else { - print " dropping index $fk->{table}.$fk->{name}\n"; - $dbh->do("ALTER TABLE $fk->{table} DROP INDEX $fk->{name}"); - } - } - - # drop the index - my $rows = $dbh->selectall_arrayref( - "SHOW INDEX FROM $table WHERE Column_name = ?", - { Slice => {} }, - $column - ); - foreach my $fk (@$rows) { - print " dropping index $fk->{Table}.$fk->{Key_name}\n"; - $dbh->do("ALTER TABLE $fk->{Table} DROP INDEX $fk->{Key_name}"); - } + @values = ($db_name, $table, $column); + foreach my $fk (@{$dbh->selectall_arrayref($sql, {Slice => {}}, @values)}) { + if ($fk->{ref}) { + print " dropping fk $fk->{table}.$fk->{name}\n"; + $dbh->do("ALTER TABLE $fk->{table} DROP FOREIGN KEY $fk->{name}"); + } + else { + print " dropping index $fk->{table}.$fk->{name}\n"; + $dbh->do("ALTER TABLE $fk->{table} DROP INDEX $fk->{name}"); + } + } + + # drop the index + my $rows + = $dbh->selectall_arrayref("SHOW INDEX FROM $table WHERE Column_name = ?", + {Slice => {}}, $column); + foreach my $fk (@$rows) { + print " dropping index $fk->{Table}.$fk->{Key_name}\n"; + $dbh->do("ALTER TABLE $fk->{Table} DROP INDEX $fk->{Key_name}"); } + } } diff --git a/scripts/remove_idle_group_members.pl b/scripts/remove_idle_group_members.pl index e4ef88bc1..02274d10f 100755 --- a/scripts/remove_idle_group_members.pl +++ b/scripts/remove_idle_group_members.pl @@ -29,12 +29,12 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $dbh = Bugzilla->dbh; # Record any changes as made by the automation user -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); # This ignores things that end with "bugs" or ".tld", just like # Bugzilla/BugMail.pm sub Send() my $expired = $dbh->selectall_arrayref( - q{SELECT DISTINCT profiles.userid AS user_id, + q{SELECT DISTINCT profiles.userid AS user_id, groups.id AS group_id FROM profiles JOIN user_group_map ON profiles.userid = user_group_map.user_id JOIN groups ON user_group_map.group_id = groups.id @@ -44,92 +44,93 @@ my $expired = $dbh->selectall_arrayref( AND groups.idle_member_removal > 0 AND (profiles.last_seen_date IS NULL OR TO_DAYS(LOCALTIMESTAMP(0)) - TO_DAYS(profiles.last_seen_date) > groups.idle_member_removal) - ORDER BY profiles.login_name}, - { Slice => {} }, GRANT_DIRECT + ORDER BY profiles.login_name}, {Slice => {}}, GRANT_DIRECT ); exit(0) if !@$expired; my %remove_data = (); foreach my $data (@$expired) { - $remove_data{$data->{group_id}} ||= []; - push(@{ $remove_data{$data->{group_id}} }, $data->{user_id}); + $remove_data{$data->{group_id}} ||= []; + push(@{$remove_data{$data->{group_id}}}, $data->{user_id}); } # 1. Remove users from the group # 2. $user->update will add audit log and profile_activity entries # 3. Send email to group owner showing users removed foreach my $group_id (keys %remove_data) { - my $group = Bugzilla::Group->new({ id => $group_id, cache => 1 }); + my $group = Bugzilla::Group->new({id => $group_id, cache => 1}); - $dbh->bz_start_transaction(); + $dbh->bz_start_transaction(); - my @users_removed = (); - foreach my $user_id (@{ $remove_data{$group->id} }) { - my $user = Bugzilla::User->new({ id => $user_id, cache => 1 }); - Bugzilla->set_user(Bugzilla::User->super_user); - $user->set_groups({ remove => [ $group->name ] }); - $user->set_bless_groups({ remove => [ $group->name ] }); - Bugzilla->set_user($auto_user); - $user->update(); - push(@users_removed, $user); - } + my @users_removed = (); + foreach my $user_id (@{$remove_data{$group->id}}) { + my $user = Bugzilla::User->new({id => $user_id, cache => 1}); + Bugzilla->set_user(Bugzilla::User->super_user); + $user->set_groups({remove => [$group->name]}); + $user->set_bless_groups({remove => [$group->name]}); + Bugzilla->set_user($auto_user); + $user->update(); + push(@users_removed, $user); + } - $dbh->bz_commit_transaction(); + $dbh->bz_commit_transaction(); - # nobody@mozilla.org cannot recieve email - next if $group->owner->login eq Bugzilla->params->{'nobody_user'}; + # nobody@mozilla.org cannot recieve email + next if $group->owner->login eq Bugzilla->params->{'nobody_user'}; - _send_email($group, \@users_removed); + _send_email($group, \@users_removed); } sub _send_email { - my ($group, $users) = @_; - - my $template = Bugzilla->template_inner($group->owner->setting('lang')); - my $vars = { group => $group, users => $users }; - - my ($header, $text); - $template->process("admin/groups/email/idle-member-removal-header.txt.tmpl", $vars, \$header) - || ThrowTemplateError($template->error()); - $header .= "\n"; - $template->process("admin/groups/email/idle-member-removal.txt.tmpl", $vars, \$text) - || ThrowTemplateError($template->error()); - - my @parts = ( - Email::MIME->create( - attributes => { - content_type => 'text/plain', - charset => 'UTF-8', - encoding => 'quoted-printable', - }, - body_str => $text, - ) - ); - - if ($group->owner->setting('email_format') eq 'html') { - my $html; - $template->process("admin/groups/email/idle-member-removal.html.tmpl", $vars, \$html) - || ThrowTemplateError($template->error()); - push @parts, Email::MIME->create( - attributes => { - content_type => 'text/html', - charset => 'UTF-8', - encoding => 'quoted-printable', - }, - body_str => $html, - ); - } - - my $email = Email::MIME->new($header); - $email->header_set('X-Generated-By' => hostname()); - if (scalar(@parts) == 1) { - $email->content_type_set($parts[0]->content_type); - } - else { - $email->content_type_set('multipart/alternative'); - } - $email->parts_set(\@parts); - - MessageToMTA($email); + my ($group, $users) = @_; + + my $template = Bugzilla->template_inner($group->owner->setting('lang')); + my $vars = {group => $group, users => $users}; + + my ($header, $text); + $template->process("admin/groups/email/idle-member-removal-header.txt.tmpl", + $vars, \$header) + || ThrowTemplateError($template->error()); + $header .= "\n"; + $template->process("admin/groups/email/idle-member-removal.txt.tmpl", + $vars, \$text) + || ThrowTemplateError($template->error()); + + my @parts = (Email::MIME->create( + attributes => { + content_type => 'text/plain', + charset => 'UTF-8', + encoding => 'quoted-printable', + }, + body_str => $text, + )); + + if ($group->owner->setting('email_format') eq 'html') { + my $html; + $template->process("admin/groups/email/idle-member-removal.html.tmpl", + $vars, \$html) + || ThrowTemplateError($template->error()); + push @parts, + Email::MIME->create( + attributes => { + content_type => 'text/html', + charset => 'UTF-8', + encoding => 'quoted-printable', + }, + body_str => $html, + ); + } + + my $email = Email::MIME->new($header); + $email->header_set('X-Generated-By' => hostname()); + if (scalar(@parts) == 1) { + $email->content_type_set($parts[0]->content_type); + } + else { + $email->content_type_set('multipart/alternative'); + } + $email->parts_set(\@parts); + + MessageToMTA($email); } diff --git a/scripts/reset_default_user.pl b/scripts/reset_default_user.pl index 942afda17..a0bec8a24 100755 --- a/scripts/reset_default_user.pl +++ b/scripts/reset_default_user.pl @@ -29,13 +29,15 @@ my $component = ""; my $help = ""; my %user_cache = (); -my $result = GetOptions('field=s' => \$field_name, - 'product=s' => \$product, - 'component=s' => \$component, - 'help|h' => \$help); +my $result = GetOptions( + 'field=s' => \$field_name, + 'product=s' => \$product, + 'component=s' => \$component, + 'help|h' => \$help +); sub usage { - print <<USAGE; + print <<USAGE; Usage: reset_default_user.pl --field <fieldname> --product <product> [--component <component>] [--help] This script will load all bugs matching the product, and optionally component, @@ -44,52 +46,50 @@ Valid field names are assigned_to and qa_contact. USAGE } -if (!$product || $help - || ($field_name ne 'assigned_to' && $field_name ne 'qa_contact')) +if (!$product + || $help + || ($field_name ne 'assigned_to' && $field_name ne 'qa_contact')) { - usage(); - exit(1); + usage(); + exit(1); } # We will need these for entering into bugs_activity -my $who = Bugzilla::User->new({ name => Bugzilla->params->{'nobody_user'} }); -my $field = Bugzilla::Field->new({ name => $field_name }); +my $who = Bugzilla::User->new({name => Bugzilla->params->{'nobody_user'}}); +my $field = Bugzilla::Field->new({name => $field_name}); trick_taint($product); -my $product_id = $dbh->selectrow_array( - "SELECT id FROM products WHERE name = ?", - undef, $product); +my $product_id = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $product); $product_id or die "Can't find product ID for '$product'.\n"; my $component_id; my $default_user_id; if ($component) { - trick_taint($component); - my $colname = $field->name eq 'qa_contact' - ? 'initialqacontact' - : 'initialowner'; - ($component_id, $default_user_id) = $dbh->selectrow_array( - "SELECT id, $colname FROM components " . - "WHERE name = ? AND product_id = ?", - undef, $component, $product_id); - $component_id or die "Can't find component ID for '$component'.\n"; - $user_cache{$default_user_id} ||= Bugzilla::User->new($default_user_id); + trick_taint($component); + my $colname + = $field->name eq 'qa_contact' ? 'initialqacontact' : 'initialowner'; + ($component_id, $default_user_id) + = $dbh->selectrow_array( + "SELECT id, $colname FROM components " . "WHERE name = ? AND product_id = ?", + undef, $component, $product_id); + $component_id or die "Can't find component ID for '$component'.\n"; + $user_cache{$default_user_id} ||= Bugzilla::User->new($default_user_id); } # build list of bugs -my $bugs_query = "SELECT bug_id, qa_contact, component_id " . - "FROM bugs WHERE product_id = ?"; +my $bugs_query = "SELECT bug_id, qa_contact, component_id " + . "FROM bugs WHERE product_id = ?"; my @args = ($product_id); if ($component_id) { - $bugs_query .= " AND component_id = ? AND qa_contact != ?"; - push(@args, $component_id, $default_user_id); + $bugs_query .= " AND component_id = ? AND qa_contact != ?"; + push(@args, $component_id, $default_user_id); } my $bugs = $dbh->selectall_arrayref($bugs_query, {Slice => {}}, @args); my $bug_count = scalar @$bugs; -$bug_count - or die "No bugs were found.\n"; +$bug_count or die "No bugs were found.\n"; # confirmation print <<EOF; @@ -102,45 +102,52 @@ getc(); $dbh->bz_start_transaction(); foreach my $bug (@$bugs) { - my $bug_id = $bug->{bug_id}; - my $old_user_id = $bug->{$field->name}; - my $old_comp_id = $bug->{component_id}; - - # If only changing one component, we already have the default user id - my $new_user_id; - if ($default_user_id) { - $new_user_id = $default_user_id; - } - else { - my $colname = $field->name eq 'qa_contact' - ? 'initialqacontact' - : 'initialowner'; - $new_user_id = $dbh->selectrow_array( - "SELECT $colname FROM components WHERE id = ?", - undef, $old_comp_id); - } - - if ($old_user_id != $new_user_id) { - print "Resetting " . $field->name . " for bug $bug_id ..."; - - # Use the cached version if already exists - my $old_user = $user_cache{$old_user_id} ||= Bugzilla::User->new($old_user_id); - my $new_user = $user_cache{$new_user_id} ||= Bugzilla::User->new($new_user_id); - - my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - - $dbh->do("UPDATE bugs SET " . $field->name . " = ? WHERE bug_id = ?", - undef, $new_user_id, $bug_id); - $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . - "VALUES (?, ?, ?, ?, ?, ?)", - undef, $bug_id, $who->id, $timestamp, $field->id, $old_user->login, $new_user->login); - $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $timestamp, $bug_id); - - Bugzilla->memcached->clear({ table => 'bugs', id => $bug_id }); - - print "done.\n"; - } + my $bug_id = $bug->{bug_id}; + my $old_user_id = $bug->{$field->name}; + my $old_comp_id = $bug->{component_id}; + + # If only changing one component, we already have the default user id + my $new_user_id; + if ($default_user_id) { + $new_user_id = $default_user_id; + } + else { + my $colname + = $field->name eq 'qa_contact' ? 'initialqacontact' : 'initialowner'; + $new_user_id + = $dbh->selectrow_array("SELECT $colname FROM components WHERE id = ?", + undef, $old_comp_id); + } + + if ($old_user_id != $new_user_id) { + print "Resetting " . $field->name . " for bug $bug_id ..."; + + # Use the cached version if already exists + my $old_user = $user_cache{$old_user_id} ||= Bugzilla::User->new($old_user_id); + my $new_user = $user_cache{$new_user_id} ||= Bugzilla::User->new($new_user_id); + + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + + $dbh->do("UPDATE bugs SET " . $field->name . " = ? WHERE bug_id = ?", + undef, $new_user_id, $bug_id); + $dbh->do( + "INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " + . "VALUES (?, ?, ?, ?, ?, ?)", + undef, + $bug_id, + $who->id, + $timestamp, + $field->id, + $old_user->login, + $new_user->login + ); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); + + Bugzilla->memcached->clear({table => 'bugs', id => $bug_id}); + + print "done.\n"; + } } $dbh->bz_commit_transaction(); diff --git a/scripts/resolve_bugs.pl b/scripts/resolve_bugs.pl index 70ed30c23..324dd06ac 100755 --- a/scripts/resolve_bugs.pl +++ b/scripts/resolve_bugs.pl @@ -25,10 +25,10 @@ my $resolution = 'WONTFIX'; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); GetOptions( - 'product|p=s' => \$product, - 'resolution|r=s' => \$resolution, - 'component|c=s' => \$component, - 'comment|m=s' => \$comment, + 'product|p=s' => \$product, + 'resolution|r=s' => \$resolution, + 'component|c=s' => \$component, + 'comment|m=s' => \$comment, ); die "--product (-p) is required!\n" unless $product; @@ -37,55 +37,54 @@ die "--comment (-m) is required!\n" unless $comment; my $dbh = Bugzilla->dbh; # Make all changes as the automation user -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); -$auto_user->{groups} = [ Bugzilla::Group->get_all ]; -$auto_user->{bless_groups} = [ Bugzilla::Group->get_all ]; +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); +$auto_user->{groups} = [Bugzilla::Group->get_all]; +$auto_user->{bless_groups} = [Bugzilla::Group->get_all]; Bugzilla->set_user($auto_user); -my $query = { resolution => '---', product => $product }; +my $query = {resolution => '---', product => $product}; $query->{component} = $component if defined $component; -my $search = Bugzilla::Search->new( - fields => ['bug_id'], - params => $query, -); +my $search = Bugzilla::Search->new(fields => ['bug_id'], params => $query,); my ($data) = $search->data; my $bug_count = @$data; if ($bug_count == 0) { - warn "There are no bugs to close.\n"; - exit 1; + warn "There are no bugs to close.\n"; + exit 1; } # if running from commmand line if (-t STDIN) { - print STDERR <<EOF; + print STDERR <<EOF; About to resolve $bug_count bugs as $resolution Press <Ctrl-C> to stop or <Enter> to continue... EOF - getc(); + getc(); } foreach my $row (@$data) { - my $bug_id = shift @$row; - warn "Updating bug $bug_id\n"; - - my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - - $dbh->bz_start_transaction; - my $bug = Bugzilla::Bug->new($bug_id); - $bug->set_bug_status('RESOLVED', { resolution => $resolution }); - $bug->add_comment($comment); - $bug->update($timestamp); - $dbh->do("UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?", - undef, $timestamp, $bug_id); - # make sure memory is cleaned up. - Bugzilla::Hook::process('request_cleanup'); - Bugzilla::Bug->CLEANUP; - Bugzilla->clear_request_cache(except => [qw(user dbh dbh_main dbh_shadow memcached)]); - - $dbh->bz_commit_transaction; + my $bug_id = shift @$row; + warn "Updating bug $bug_id\n"; + + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + + $dbh->bz_start_transaction; + my $bug = Bugzilla::Bug->new($bug_id); + $bug->set_bug_status('RESOLVED', {resolution => $resolution}); + $bug->add_comment($comment); + $bug->update($timestamp); + $dbh->do("UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $bug_id); + + # make sure memory is cleaned up. + Bugzilla::Hook::process('request_cleanup'); + Bugzilla::Bug->CLEANUP; + Bugzilla->clear_request_cache( + except => [qw(user dbh dbh_main dbh_shadow memcached)]); + + $dbh->bz_commit_transaction; } Bugzilla->memcached->clear_all(); diff --git a/scripts/rewrite2mojo.pl b/scripts/rewrite2mojo.pl index bae6d514b..f2b812564 100755 --- a/scripts/rewrite2mojo.pl +++ b/scripts/rewrite2mojo.pl @@ -13,58 +13,59 @@ use Mojo::Parameters; use Data::Dumper; while (<>) { - my ($cmd, @args) = split /\s+/, $_; - next unless $cmd; - if (lc($cmd) eq "\LRewriteRule") { - my ($regex, $target, $flags) = @args; - $flags //= ''; - next if $flags =~ /E=HTTP/; - next if $target eq '-'; - my $action = 'rewrite_query'; - if ($flags =~ /R/) { - next; - } - my ($script, $query) = $target =~ /^([^?]+)(?:\?(.+))?$/; - my $name = _file_to_method($script); - $regex =~ s/^\^//; - $regex =~ s/\$$//; - my $regex_name = _regex_to_name($regex); - my $param_hash = Mojo::Parameters->new($query)->to_hash; - my $param_str = Data::Dumper->new([$param_hash])->Terse(1)->Indent(0)->Dump; - say "\$r->any('/:$regex_name' => [$regex_name => qr{$regex}])->to("; - say " 'CGI#$name' => $param_str"; - say ");"; - + my ($cmd, @args) = split /\s+/, $_; + next unless $cmd; + if (lc($cmd) eq "\LRewriteRule") { + my ($regex, $target, $flags) = @args; + $flags //= ''; + next if $flags =~ /E=HTTP/; + next if $target eq '-'; + my $action = 'rewrite_query'; + if ($flags =~ /R/) { + next; } - # elsif (lc($cmd) eq "\LRedirect") { - # my ($type, $path, $url) = @args; - # if ($type eq 'permanent') { - # say "if (\$path =~ m{^\Q$path\E}s) {"; - # say " redirect(\$c, q{$url});"; - # say " return;"; - # say "}"; - # } - # else { - # warn "I don't understand Redirect $type\n"; - # } - # } + my ($script, $query) = $target =~ /^([^?]+)(?:\?(.+))?$/; + my $name = _file_to_method($script); + $regex =~ s/^\^//; + $regex =~ s/\$$//; + my $regex_name = _regex_to_name($regex); + my $param_hash = Mojo::Parameters->new($query)->to_hash; + my $param_str = Data::Dumper->new([$param_hash])->Terse(1)->Indent(0)->Dump; + say "\$r->any('/:$regex_name' => [$regex_name => qr{$regex}])->to("; + say " 'CGI#$name' => $param_str"; + say ");"; + + } + + # elsif (lc($cmd) eq "\LRedirect") { + # my ($type, $path, $url) = @args; + # if ($type eq 'permanent') { + # say "if (\$path =~ m{^\Q$path\E}s) {"; + # say " redirect(\$c, q{$url});"; + # say " return;"; + # say "}"; + # } + # else { + # warn "I don't understand Redirect $type\n"; + # } + # } } sub _file_to_method { - my ($name) = @_; - $name =~ s/\./_/s; - $name =~ s/\W+/_/gs; - return $name; + my ($name) = @_; + $name =~ s/\./_/s; + $name =~ s/\W+/_/gs; + return $name; } sub _regex_to_name { - my ($name) = @_; - $name =~ s/\./_/s; - $name =~ s/\W+/_/gs; - $name =~ s/_+/_/g; - $name =~ s/^_//s; - $name =~ s/_$//s; - return $name; + my ($name) = @_; + $name =~ s/\./_/s; + $name =~ s/\W+/_/gs; + $name =~ s/_+/_/g; + $name =~ s/^_//s; + $name =~ s/_$//s; + return $name; } diff --git a/scripts/sanitizeme.pl b/scripts/sanitizeme.pl index 31418d047..c8c569ce7 100755 --- a/scripts/sanitizeme.pl +++ b/scripts/sanitizeme.pl @@ -41,8 +41,11 @@ my $dbh = Bugzilla->dbh; # doesn't contain any information that can't be viewed from a web browser by # a user who is not logged in. -my ($dry_run, $from_cron, $keep_attachments, $keep_group_bugs, $keep_groups, $execute, - $keep_passwords, $keep_insider, $trace, $enable_email) = (0, 0, 0, '', 0, 0, 0, 0, 0, 0); +my ( + $dry_run, $from_cron, $keep_attachments, $keep_group_bugs, + $keep_groups, $execute, $keep_passwords, $keep_insider, + $trace, $enable_email +) = (0, 0, 0, '', 0, 0, 0, 0, 0, 0); my $keep_group_bugs_sql = ''; my $syntax = <<EOF; @@ -59,181 +62,215 @@ options: --trace output sql statements EOF GetOptions( - "execute" => \$execute, - "dry-run" => \$dry_run, - "from-cron" => \$from_cron, - "keep-attachments" => \$keep_attachments, - "keep-passwords" => \$keep_passwords, - "keep-insider" => \$keep_insider, - "keep-group-bugs:s" => \$keep_group_bugs, - "keep-groups" => \$keep_groups, - "trace" => \$trace, - "enable-email" => \$enable_email, + "execute" => \$execute, + "dry-run" => \$dry_run, + "from-cron" => \$from_cron, + "keep-attachments" => \$keep_attachments, + "keep-passwords" => \$keep_passwords, + "keep-insider" => \$keep_insider, + "keep-group-bugs:s" => \$keep_group_bugs, + "keep-groups" => \$keep_groups, + "trace" => \$trace, + "enable-email" => \$enable_email, ) or die $syntax; die "--execute switch required to perform database sanitization.\n\n$syntax" - unless $execute or $dry_run; + unless $execute or $dry_run; if ($keep_group_bugs ne '') { - my @groups; - foreach my $group_id (split(/\s*,\s*/, $keep_group_bugs)) { - my $group; - if ($group_id =~ /\D/) { - $group = Bugzilla::Group->new({ name => $group_id }); - } else { - $group = Bugzilla::Group->new($group_id); - } - die "Invalid group '$group_id'\n" unless $group; - push @groups, $group->id; + my @groups; + foreach my $group_id (split(/\s*,\s*/, $keep_group_bugs)) { + my $group; + if ($group_id =~ /\D/) { + $group = Bugzilla::Group->new({name => $group_id}); } - $keep_group_bugs_sql = "NOT IN (" . join(",", @groups) . ")"; + else { + $group = Bugzilla::Group->new($group_id); + } + die "Invalid group '$group_id'\n" unless $group; + push @groups, $group->id; + } + $keep_group_bugs_sql = "NOT IN (" . join(",", @groups) . ")"; } $dbh->{TraceLevel} = 1 if $trace; if ($dry_run) { - print "** dry run : no changes to the database will be made **\n"; - $dbh->bz_start_transaction(); + print "** dry run : no changes to the database will be made **\n"; + $dbh->bz_start_transaction(); } eval { - delete_non_public_products(); - delete_secure_bugs(); - delete_deleted_comments(); - delete_insider_comments() unless $keep_insider; - delete_security_groups() unless $keep_groups; - delete_sensitive_user_data(); - delete_attachment_data() unless $keep_attachments; - delete_bug_user_last_visit(); - delete_user_request_log(); - Bugzilla::Hook::process('db_sanitize'); - disable_email_delivery() unless $enable_email; - print "All done!\n"; - $dbh->bz_rollback_transaction() if $dry_run; + delete_non_public_products(); + delete_secure_bugs(); + delete_deleted_comments(); + delete_insider_comments() unless $keep_insider; + delete_security_groups() unless $keep_groups; + delete_sensitive_user_data(); + delete_attachment_data() unless $keep_attachments; + delete_bug_user_last_visit(); + delete_user_request_log(); + Bugzilla::Hook::process('db_sanitize'); + disable_email_delivery() unless $enable_email; + print "All done!\n"; + $dbh->bz_rollback_transaction() if $dry_run; }; if ($@) { - $dbh->bz_rollback_transaction() if $dry_run; - die "$@" if $@; + $dbh->bz_rollback_transaction() if $dry_run; + die "$@" if $@; } sub delete_non_public_products { - # Delete all non-public products, and all data associated with them - my @products = Bugzilla::Product->get_all(); - my $mandatory = CONTROLMAPMANDATORY; - foreach my $product (@products) { - # if there are any mandatory groups on the product, nuke it and - # everything associated with it (including the bugs) - Bugzilla->params->{'allowbugdeletion'} = 1; # override this in memory for now - my $mandatorygroups = $dbh->selectcol_arrayref("SELECT group_id FROM group_control_map WHERE product_id = ? AND (membercontrol = $mandatory)", undef, $product->id); - if (0 < scalar(@$mandatorygroups)) { - print "Deleting product '" . $product->name . "'...\n"; - $product->remove_from_db(); - } + + # Delete all non-public products, and all data associated with them + my @products = Bugzilla::Product->get_all(); + my $mandatory = CONTROLMAPMANDATORY; + foreach my $product (@products) { + + # if there are any mandatory groups on the product, nuke it and + # everything associated with it (including the bugs) + Bugzilla->params->{'allowbugdeletion'} = 1; # override this in memory for now + my $mandatorygroups = $dbh->selectcol_arrayref( + "SELECT group_id FROM group_control_map WHERE product_id = ? AND (membercontrol = $mandatory)", + undef, $product->id + ); + if (0 < scalar(@$mandatorygroups)) { + print "Deleting product '" . $product->name . "'...\n"; + $product->remove_from_db(); } + } } sub delete_secure_bugs { - # Delete all data for bugs in security groups. - my $buglist = $dbh->selectall_arrayref( - $keep_group_bugs - ? "SELECT DISTINCT bug_id FROM bug_group_map WHERE group_id $keep_group_bugs_sql" - : "SELECT DISTINCT bug_id FROM bug_group_map" - ); - my $numbugs = scalar(@$buglist); - my $bugnum = 0; - print "Deleting $numbugs bugs in " . ($keep_group_bugs ? 'non-' : '') . "security groups...\n"; - foreach my $row (@$buglist) { - my $bug_id = $row->[0]; - $bugnum++; - print "\r$bugnum/$numbugs" unless $from_cron; - my $bug = new Bugzilla::Bug($bug_id); - $bug->remove_from_db(); - } - print "\rDone \n" unless $from_cron; + + # Delete all data for bugs in security groups. + my $buglist + = $dbh->selectall_arrayref($keep_group_bugs + ? "SELECT DISTINCT bug_id FROM bug_group_map WHERE group_id $keep_group_bugs_sql" + : "SELECT DISTINCT bug_id FROM bug_group_map"); + my $numbugs = scalar(@$buglist); + my $bugnum = 0; + print "Deleting $numbugs bugs in " + . ($keep_group_bugs ? 'non-' : '') + . "security groups...\n"; + foreach my $row (@$buglist) { + my $bug_id = $row->[0]; + $bugnum++; + print "\r$bugnum/$numbugs" unless $from_cron; + my $bug = new Bugzilla::Bug($bug_id); + $bug->remove_from_db(); + } + print "\rDone \n" unless $from_cron; } sub delete_deleted_comments { - # Delete all comments tagged as 'deleted' - my $comment_ids = $dbh->selectcol_arrayref("SELECT comment_id FROM longdescs_tags WHERE tag='deleted'"); - return unless @$comment_ids; - print "Deleting 'deleted' comments...\n"; - my @bug_ids = uniq @{ - $dbh->selectcol_arrayref("SELECT bug_id FROM longdescs WHERE comment_id IN (" . join(',', @$comment_ids) . ")") - }; - $dbh->do("DELETE FROM longdescs WHERE comment_id IN (" . join(',', @$comment_ids) . ")"); - foreach my $bug_id (@bug_ids) { - Bugzilla::Bug->new($bug_id)->_sync_fulltext(update_comments => 1); - } + + # Delete all comments tagged as 'deleted' + my $comment_ids = $dbh->selectcol_arrayref( + "SELECT comment_id FROM longdescs_tags WHERE tag='deleted'"); + return unless @$comment_ids; + print "Deleting 'deleted' comments...\n"; + my @bug_ids = uniq @{ + $dbh->selectcol_arrayref( + "SELECT bug_id FROM longdescs WHERE comment_id IN (" + . join(',', @$comment_ids) . ")" + ) + }; + $dbh->do( + "DELETE FROM longdescs WHERE comment_id IN (" . join(',', @$comment_ids) . ")"); + foreach my $bug_id (@bug_ids) { + Bugzilla::Bug->new($bug_id)->_sync_fulltext(update_comments => 1); + } } sub delete_insider_comments { - # Delete all 'insidergroup' comments and attachments - print "Deleting 'insidergroup' comments and attachments...\n"; - $dbh->do("DELETE FROM longdescs WHERE isprivate = 1"); - $dbh->do("DELETE attach_data FROM attachments JOIN attach_data ON attachments.attach_id = attach_data.id WHERE attachments.isprivate = 1"); - $dbh->do("DELETE FROM attachments WHERE isprivate = 1"); - $dbh->do("UPDATE bugs_fulltext SET comments = comments_noprivate"); + + # Delete all 'insidergroup' comments and attachments + print "Deleting 'insidergroup' comments and attachments...\n"; + $dbh->do("DELETE FROM longdescs WHERE isprivate = 1"); + $dbh->do( + "DELETE attach_data FROM attachments JOIN attach_data ON attachments.attach_id = attach_data.id WHERE attachments.isprivate = 1" + ); + $dbh->do("DELETE FROM attachments WHERE isprivate = 1"); + $dbh->do("UPDATE bugs_fulltext SET comments = comments_noprivate"); } sub delete_security_groups { - # Delete all security groups. - print "Deleting " . ($keep_group_bugs ? 'non-' : '') . "security groups...\n"; - $dbh->do("DELETE user_group_map FROM groups JOIN user_group_map ON groups.id = user_group_map.group_id WHERE groups.isbuggroup = 1"); - $dbh->do("DELETE group_group_map FROM groups JOIN group_group_map ON (groups.id = group_group_map.member_id OR groups.id = group_group_map.grantor_id) WHERE groups.isbuggroup = 1"); - $dbh->do("DELETE group_control_map FROM groups JOIN group_control_map ON groups.id = group_control_map.group_id WHERE groups.isbuggroup = 1"); - $dbh->do("UPDATE flagtypes LEFT JOIN groups ON flagtypes.grant_group_id = groups.id SET grant_group_id = NULL WHERE groups.isbuggroup = 1"); - $dbh->do("UPDATE flagtypes LEFT JOIN groups ON flagtypes.request_group_id = groups.id SET request_group_id = NULL WHERE groups.isbuggroup = 1"); - if ($keep_group_bugs) { - $dbh->do("DELETE FROM groups WHERE isbuggroup = 1 AND id $keep_group_bugs_sql"); - } else { - $dbh->do("DELETE FROM groups WHERE isbuggroup = 1"); - } + + # Delete all security groups. + print "Deleting " . ($keep_group_bugs ? 'non-' : '') . "security groups...\n"; + $dbh->do( + "DELETE user_group_map FROM groups JOIN user_group_map ON groups.id = user_group_map.group_id WHERE groups.isbuggroup = 1" + ); + $dbh->do( + "DELETE group_group_map FROM groups JOIN group_group_map ON (groups.id = group_group_map.member_id OR groups.id = group_group_map.grantor_id) WHERE groups.isbuggroup = 1" + ); + $dbh->do( + "DELETE group_control_map FROM groups JOIN group_control_map ON groups.id = group_control_map.group_id WHERE groups.isbuggroup = 1" + ); + $dbh->do( + "UPDATE flagtypes LEFT JOIN groups ON flagtypes.grant_group_id = groups.id SET grant_group_id = NULL WHERE groups.isbuggroup = 1" + ); + $dbh->do( + "UPDATE flagtypes LEFT JOIN groups ON flagtypes.request_group_id = groups.id SET request_group_id = NULL WHERE groups.isbuggroup = 1" + ); + if ($keep_group_bugs) { + $dbh->do("DELETE FROM groups WHERE isbuggroup = 1 AND id $keep_group_bugs_sql"); + } + else { + $dbh->do("DELETE FROM groups WHERE isbuggroup = 1"); + } } sub delete_sensitive_user_data { - # Remove sensitive user account data. - print "Deleting sensitive user account data...\n"; - $dbh->do("UPDATE profiles SET cryptpassword = 'deleted'") unless $keep_passwords; - $dbh->do("DELETE FROM user_api_keys"); - $dbh->do("DELETE FROM profiles_activity"); - $dbh->do("DELETE FROM profile_search"); - $dbh->do("DELETE FROM profile_mfa"); - $dbh->do("DELETE FROM namedqueries"); - $dbh->do("DELETE FROM tokens"); - $dbh->do("DELETE FROM logincookies"); - $dbh->do("DELETE FROM login_failure"); - $dbh->do("DELETE FROM audit_log"); - # queued bugmail - $dbh->do("DELETE FROM ts_error"); - $dbh->do("DELETE FROM ts_exitstatus"); - $dbh->do("DELETE FROM ts_funcmap"); - $dbh->do("DELETE FROM ts_job"); - $dbh->do("DELETE FROM ts_note"); + + # Remove sensitive user account data. + print "Deleting sensitive user account data...\n"; + $dbh->do("UPDATE profiles SET cryptpassword = 'deleted'") + unless $keep_passwords; + $dbh->do("DELETE FROM user_api_keys"); + $dbh->do("DELETE FROM profiles_activity"); + $dbh->do("DELETE FROM profile_search"); + $dbh->do("DELETE FROM profile_mfa"); + $dbh->do("DELETE FROM namedqueries"); + $dbh->do("DELETE FROM tokens"); + $dbh->do("DELETE FROM logincookies"); + $dbh->do("DELETE FROM login_failure"); + $dbh->do("DELETE FROM audit_log"); + + # queued bugmail + $dbh->do("DELETE FROM ts_error"); + $dbh->do("DELETE FROM ts_exitstatus"); + $dbh->do("DELETE FROM ts_funcmap"); + $dbh->do("DELETE FROM ts_job"); + $dbh->do("DELETE FROM ts_note"); } sub delete_attachment_data { - # Delete unnecessary attachment data. - print "Removing attachment data...\n"; - $dbh->do("UPDATE attach_data SET thedata = ''"); - $dbh->do("UPDATE attachments SET attach_size = 0"); + + # Delete unnecessary attachment data. + print "Removing attachment data...\n"; + $dbh->do("UPDATE attach_data SET thedata = ''"); + $dbh->do("UPDATE attachments SET attach_size = 0"); } sub delete_bug_user_last_visit { - print "Removing all entries from bug_user_last_visit...\n"; - $dbh->do('TRUNCATE TABLE bug_user_last_visit'); + print "Removing all entries from bug_user_last_visit...\n"; + $dbh->do('TRUNCATE TABLE bug_user_last_visit'); } sub delete_user_request_log { - print "Removing all entries from user_request_log...\n"; - $dbh->do('TRUNCATE TABLE user_request_log'); + print "Removing all entries from user_request_log...\n"; + $dbh->do('TRUNCATE TABLE user_request_log'); } sub disable_email_delivery { - # turn off email delivery for all users. - print "Turning off email delivery...\n"; - $dbh->do("UPDATE profiles SET disable_mail = 1"); - # Also clear out the default flag cc as well since they do not - # have to be in the profiles table - $dbh->do("UPDATE flagtypes SET cc_list = NULL"); + # turn off email delivery for all users. + print "Turning off email delivery...\n"; + $dbh->do("UPDATE profiles SET disable_mail = 1"); + + # Also clear out the default flag cc as well since they do not + # have to be in the profiles table + $dbh->do("UPDATE flagtypes SET cc_list = NULL"); } =head1 NAME diff --git a/scripts/search.pl b/scripts/search.pl index 6e0f7245d..3d2483f08 100755 --- a/scripts/search.pl +++ b/scripts/search.pl @@ -5,9 +5,9 @@ use Bugzilla; use JSON '-convert_blessed_universally'; print JSON->new->pretty->encode( - Bugzilla::Elastic::Search->new( - quicksearch => "@ARGV", - fields => ['bug_id', 'short_desc'], - order => ['bug_id'], - )->es_query + Bugzilla::Elastic::Search->new( + quicksearch => "@ARGV", + fields => ['bug_id', 'short_desc'], + order => ['bug_id'], + )->es_query ); diff --git a/scripts/secbugsreport.pl b/scripts/secbugsreport.pl index 81041b222..ccc92fd99 100644 --- a/scripts/secbugsreport.pl +++ b/scripts/secbugsreport.pl @@ -33,52 +33,53 @@ exit 0 unless Bugzilla->params->{report_secbugs_active}; exit 0 unless defined $ARGV[0] && defined $ARGV[1] && defined $ARGV[2]; my $html; -my $template = Bugzilla->template(); -my $end_date = DateTime->new( year => $ARGV[0], month => $ARGV[1], day => $ARGV[2] ); -my $start_date = $end_date->clone()->subtract( months => 6 ); +my $template = Bugzilla->template(); +my $end_date + = DateTime->new(year => $ARGV[0], month => $ARGV[1], day => $ARGV[2]); +my $start_date = $end_date->clone()->subtract(months => 6); my $report_week = $end_date->ymd('-'); -my $products = decode_json( Bugzilla->params->{report_secbugs_products} ); -my $sec_keywords = [ 'sec-critical', 'sec-high' ]; +my $products = decode_json(Bugzilla->params->{report_secbugs_products}); +my $sec_keywords = ['sec-critical', 'sec-high']; my $report = Bugzilla::Report::SecurityRisk->new( - start_date => $start_date, - end_date => $end_date, - products => $products, - sec_keywords => $sec_keywords + start_date => $start_date, + end_date => $end_date, + products => $products, + sec_keywords => $sec_keywords ); my $vars = { - urlbase => Bugzilla->localconfig->{urlbase}, - report_week => $report_week, - products => $products, - sec_keywords => $sec_keywords, - results => $report->results, - build_bugs_link => \&build_bugs_link, + urlbase => Bugzilla->localconfig->{urlbase}, + report_week => $report_week, + products => $products, + sec_keywords => $sec_keywords, + results => $report->results, + build_bugs_link => \&build_bugs_link, }; -$template->process( 'reports/email/security-risk.html.tmpl', $vars, \$html ) - or ThrowTemplateError( $template->error() ); +$template->process('reports/email/security-risk.html.tmpl', $vars, \$html) + or ThrowTemplateError($template->error()); # For now, only send HTML email. my $email = Email::MIME->create( - header_str => [ - From => Bugzilla->params->{'mailfrom'}, - To => Bugzilla->params->{report_secbugs_emails}, - Subject => "Security Bugs Report for $report_week", - 'X-Bugzilla-Type' => 'admin' - ], - attributes => { - content_type => 'text/html', - charset => 'UTF-8', - encoding => 'quoted-printable', - }, - body_str => $html, + header_str => [ + From => Bugzilla->params->{'mailfrom'}, + To => Bugzilla->params->{report_secbugs_emails}, + Subject => "Security Bugs Report for $report_week", + 'X-Bugzilla-Type' => 'admin' + ], + attributes => { + content_type => 'text/html', + charset => 'UTF-8', + encoding => 'quoted-printable', + }, + body_str => $html, ); MessageToMTA($email); sub build_bugs_link { - my ( $arr, $product ) = @_; - my $uri = URI->new( Bugzilla->localconfig->{urlbase} . 'buglist.cgi' ); - $uri->query_param( bug_id => ( join ',', @$arr ) ); - $uri->query_param( product => $product ) if $product; - return $uri->as_string; + my ($arr, $product) = @_; + my $uri = URI->new(Bugzilla->localconfig->{urlbase} . 'buglist.cgi'); + $uri->query_param(bug_id => (join ',', @$arr)); + $uri->query_param(product => $product) if $product; + return $uri->as_string; } diff --git a/scripts/security_remove.pl b/scripts/security_remove.pl index dc0847e3c..1187e1032 100755 --- a/scripts/security_remove.pl +++ b/scripts/security_remove.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Constants; use Bugzilla::Field; @@ -27,7 +25,7 @@ BEGIN { Bugzilla->extensions(); } Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 1) { - die <<USAGE; + die <<USAGE; Usage: security_remove.pl <user> E.g.: security_remove.pl foo\@bar.com @@ -49,57 +47,53 @@ USAGE my ($login_name) = @ARGV; # Load nobody user and set as current -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); Bugzilla->set_user($auto_user); # Check target user -my $target_user = Bugzilla::User->check({ name => $login_name }); +my $target_user = Bugzilla::User->check({name => $login_name}); -my $dbh = Bugzilla->dbh; +my $dbh = Bugzilla->dbh; my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); # Gather bug ids my $reporter_bugs = $dbh->selectcol_arrayref( - q{SELECT DISTINCT bugs.bug_id + q{SELECT DISTINCT bugs.bug_id FROM bugs, bug_group_map WHERE bugs.bug_id = bug_group_map.bug_id AND bugs.reporter_accessible = 1 - AND bugs.reporter = ?}, - undef, $target_user->id) || []; + AND bugs.reporter = ?}, undef, $target_user->id +) || []; my $assignee_bugs = $dbh->selectcol_arrayref( - q{SELECT DISTINCT bugs.bug_id + q{SELECT DISTINCT bugs.bug_id FROM bugs, bug_group_map WHERE bugs.bug_id = bug_group_map.bug_id - AND bugs.assigned_to = ?}, - undef, $target_user->id) || []; + AND bugs.assigned_to = ?}, undef, $target_user->id +) || []; my $qa_bugs = $dbh->selectcol_arrayref( - q{SELECT DISTINCT bugs.bug_id + q{SELECT DISTINCT bugs.bug_id FROM bugs, bug_group_map WHERE bugs.bug_id = bug_group_map.bug_id - AND bugs.qa_contact = ?}, - undef, $target_user->id) || []; + AND bugs.qa_contact = ?}, undef, $target_user->id +) || []; my $cc_bugs = $dbh->selectcol_arrayref( - q{SELECT DISTINCT cc.bug_id + q{SELECT DISTINCT cc.bug_id FROM cc, bug_group_map WHERE cc.bug_id = bug_group_map.bug_id - AND cc.who = ?}, - undef, $target_user->id) || []; + AND cc.who = ?}, undef, $target_user->id +) || []; my $reporter_count = scalar @$reporter_bugs; my $assignee_count = scalar @$assignee_bugs; my $qa_count = scalar @$qa_bugs; my $cc_count = scalar @$cc_bugs; -if (!$reporter_count - && !$assignee_count - && !$qa_count - && !$cc_count) -{ - warn "There are no bugs to update.\n"; - exit 1; +if (!$reporter_count && !$assignee_count && !$qa_count && !$cc_count) { + warn "There are no bugs to update.\n"; + exit 1; } warn <<EOF; @@ -119,56 +113,59 @@ $dbh->bz_start_transaction; # Reporter - set reporter_accessible to false my $field_id = get_field_id('reporter_accessible'); foreach my $bug_id (@$reporter_bugs) { - warn "Updating bug $bug_id\n"; - $dbh->do( - q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, ?)}, - undef, $bug_id, $auto_user->id, $timestamp, $field_id, 1, 0); - $dbh->do( - q{UPDATE bugs SET reporter_accessible = 0, delta_ts = ?, lastdiffed = ? - WHERE bug_id = ?}, - undef, $timestamp, $timestamp, $bug_id); + warn "Updating bug $bug_id\n"; + $dbh->do( + q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, ?)}, undef, $bug_id, $auto_user->id, $timestamp, + $field_id, 1, 0 + ); + $dbh->do( + q{UPDATE bugs SET reporter_accessible = 0, delta_ts = ?, lastdiffed = ? + WHERE bug_id = ?}, undef, $timestamp, $timestamp, $bug_id + ); } # Assignee $field_id = get_field_id('assigned_to'); foreach my $bug_id (@$assignee_bugs) { - warn "Updating bug $bug_id\n"; - $dbh->do( - q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, ?)}, - undef, $bug_id, $auto_user->id, $timestamp, $field_id, - $target_user->login, $auto_user->login); - $dbh->do( - q{UPDATE bugs SET assigned_to = ?, delta_ts = ?, lastdiffed = ? - WHERE bug_id = ?}, - undef, $auto_user->id, $timestamp, $timestamp, $bug_id); + warn "Updating bug $bug_id\n"; + $dbh->do( + q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, ?)}, undef, $bug_id, $auto_user->id, $timestamp, + $field_id, $target_user->login, $auto_user->login + ); + $dbh->do( + q{UPDATE bugs SET assigned_to = ?, delta_ts = ?, lastdiffed = ? + WHERE bug_id = ?}, undef, $auto_user->id, $timestamp, $timestamp, $bug_id + ); } # QA Contact $field_id = get_field_id('qa_contact'); foreach my $bug_id (@$qa_bugs) { - warn "Updating bug $bug_id\n"; - $dbh->do( - q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, '')}, - undef, $bug_id, $auto_user->id, $timestamp, $field_id, $target_user->login); - $dbh->do( - q{UPDATE bugs SET qa_contact = NULL, delta_ts = ?, lastdiffed = ? - WHERE bug_id = ?}, - undef, $timestamp, $timestamp, $bug_id); + warn "Updating bug $bug_id\n"; + $dbh->do( + q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, '')}, undef, $bug_id, $auto_user->id, $timestamp, + $field_id, $target_user->login + ); + $dbh->do( + q{UPDATE bugs SET qa_contact = NULL, delta_ts = ?, lastdiffed = ? + WHERE bug_id = ?}, undef, $timestamp, $timestamp, $bug_id + ); } # CC list $field_id = get_field_id('cc'); foreach my $bug_id (@$cc_bugs) { - warn "Updating bug $bug_id\n"; - $dbh->do( - q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) - VALUES (?, ?, ?, ?, ?, '')}, - undef, $bug_id, $auto_user->id, $timestamp, $field_id, $target_user->login); - $dbh->do(q{DELETE FROM cc WHERE bug_id = ? AND who = ?}, - undef, $bug_id, $target_user->id); + warn "Updating bug $bug_id\n"; + $dbh->do( + q{INSERT INTO bugs_activity (bug_id, who, bug_when, fieldid, removed, added) + VALUES (?, ?, ?, ?, ?, '')}, undef, $bug_id, $auto_user->id, $timestamp, + $field_id, $target_user->login + ); + $dbh->do(q{DELETE FROM cc WHERE bug_id = ? AND who = ?}, + undef, $bug_id, $target_user->id); } $target_user->clear_last_statistics_ts(); diff --git a/scripts/sendmail.pl b/scripts/sendmail.pl index aa9ab57a1..adf22a907 100755 --- a/scripts/sendmail.pl +++ b/scripts/sendmail.pl @@ -18,12 +18,17 @@ use warnings; use File::Basename; use File::Spec; + BEGIN { - require lib; - my $dir = File::Spec->rel2abs(dirname(__FILE__)); - my $base = File::Spec->catdir($dir, ".."); - lib->import($base, File::Spec->catdir($base, "lib"), File::Spec->catdir($base, qw(local lib perl5))); - chdir $base; + require lib; + my $dir = File::Spec->rel2abs(dirname(__FILE__)); + my $base = File::Spec->catdir($dir, ".."); + lib->import( + $base, + File::Spec->catdir($base, "lib"), + File::Spec->catdir($base, qw(local lib perl5)) + ); + chdir $base; } use Bugzilla; @@ -31,9 +36,9 @@ BEGIN { Bugzilla->extensions } use Bugzilla::Mailer; my $msg = do { - local $/ = undef; - binmode STDIN, ':bytes'; - <STDIN>; + local $/ = undef; + binmode STDIN, ':bytes'; + <STDIN>; }; -MessageToMTA($msg);
\ No newline at end of file +MessageToMTA($msg); diff --git a/scripts/sendunsentbugmail.pl b/scripts/sendunsentbugmail.pl index a8e1ed4dc..0f110d996 100755 --- a/scripts/sendunsentbugmail.pl +++ b/scripts/sendunsentbugmail.pl @@ -12,7 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - use Bugzilla; use Bugzilla::Constants; use Bugzilla::BugMail; @@ -20,29 +19,29 @@ use Bugzilla::BugMail; my $dbh = Bugzilla->dbh; my $list = $dbh->selectcol_arrayref( - 'SELECT bug_id FROM bugs + 'SELECT bug_id FROM bugs WHERE lastdiffed IS NULL OR lastdiffed < delta_ts AND delta_ts < ' - . $dbh->sql_date_math('NOW()', '-', 30, 'MINUTE') . - ' ORDER BY bug_id'); + . $dbh->sql_date_math('NOW()', '-', 30, 'MINUTE') . ' ORDER BY bug_id' +); if (scalar(@$list) > 0) { - say "OK, now attempting to send unsent mail"; - say scalar(@$list) . " bugs found with possibly unsent mail.\n"; - foreach my $bugid (@$list) { - my $start_time = time; - say "Sending mail for bug $bugid..."; - my $outputref = Bugzilla::BugMail::Send($bugid); - if ($ARGV[0] && $ARGV[0] eq "--report") { - say "Mail sent to:"; - say $_ foreach (sort @{$outputref->{sent}}); - } - else { - my $sent = scalar @{$outputref->{sent}}; - say "$sent mails sent."; - say "Took " . (time - $start_time) . " seconds.\n"; - } + say "OK, now attempting to send unsent mail"; + say scalar(@$list) . " bugs found with possibly unsent mail.\n"; + foreach my $bugid (@$list) { + my $start_time = time; + say "Sending mail for bug $bugid..."; + my $outputref = Bugzilla::BugMail::Send($bugid); + if ($ARGV[0] && $ARGV[0] eq "--report") { + say "Mail sent to:"; + say $_ foreach (sort @{$outputref->{sent}}); + } + else { + my $sent = scalar @{$outputref->{sent}}; + say "$sent mails sent."; + say "Took " . (time - $start_time) . " seconds.\n"; } - say "Unsent mail has been sent."; + } + say "Unsent mail has been sent."; } diff --git a/scripts/suggest-user.pl b/scripts/suggest-user.pl index dcf24da87..18cec7da2 100755 --- a/scripts/suggest-user.pl +++ b/scripts/suggest-user.pl @@ -7,14 +7,12 @@ use Bugzilla; use Search::Elasticsearch; use Bugzilla::Elastic; -my $elastic = Bugzilla::Elastic->new( - es_client => Search::Elasticsearch->new() -); +my $elastic = Bugzilla::Elastic->new(es_client => Search::Elasticsearch->new()); my $user = Bugzilla::User->check({name => 'dylan@mozilla.com'}); Bugzilla->set_user($user); my $users; -for (1..4) { - $users = $elastic->suggest_users($ARGV[0]); +for (1 .. 4) { + $users = $elastic->suggest_users($ARGV[0]); } print "$_->{name}\n" for @$users; diff --git a/scripts/syncflags.pl b/scripts/syncflags.pl index c99fd5160..2d3d65b58 100755 --- a/scripts/syncflags.pl +++ b/scripts/syncflags.pl @@ -32,7 +32,7 @@ use Bugzilla; use Bugzilla::Constants; sub usage() { - print <<USAGE; + print <<USAGE; Usage: syncflags.pl <srcproduct> <tgtproduct> E.g.: syncflags.pl FoodReplicator SeaMonkey @@ -41,7 +41,7 @@ so matching inclusions exist for the product "SeaMonkey". This script is normally used prior to moving components from srcproduct to tgtproduct. USAGE - exit(1); + exit(1); } ############################################################################# @@ -52,8 +52,8 @@ USAGE Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 2) { - usage(); - exit(); + usage(); + exit(); } my ($srcproduct, $tgtproduct) = @ARGV; @@ -62,40 +62,42 @@ my $dbh = Bugzilla->dbh; # Find product IDs my $srcprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", - undef, $srcproduct); + undef, $srcproduct); if (!$srcprodid) { - print "Can't find product ID for '$srcproduct'.\n"; - exit(1); + print "Can't find product ID for '$srcproduct'.\n"; + exit(1); } my $tgtprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", - undef, $tgtproduct); + undef, $tgtproduct); if (!$tgtprodid) { - print "Can't find product ID for '$tgtproduct'.\n"; - exit(1); + print "Can't find product ID for '$tgtproduct'.\n"; + exit(1); } # Normal flags such as bug flags and attachment flags -$dbh->do("INSERT INTO flaginclusions(component_id, type_id, product_id) +$dbh->do( + "INSERT INTO flaginclusions(component_id, type_id, product_id) SELECT fi1.component_id, fi1.type_id, ? FROM flaginclusions fi1 LEFT JOIN flaginclusions fi2 ON fi1.type_id = fi2.type_id AND fi2.product_id = ? WHERE fi1.product_id = ? - AND fi2.type_id IS NULL", - undef, - $tgtprodid, $tgtprodid, $srcprodid); + AND fi2.type_id IS NULL", undef, $tgtprodid, $tgtprodid, + $srcprodid +); # Tracking type flags -$dbh->do("INSERT INTO tracking_flags_visibility (tracking_flag_id, product_id, component_id) +$dbh->do( + "INSERT INTO tracking_flags_visibility (tracking_flag_id, product_id, component_id) SELECT tf1.tracking_flag_id, ?, tf1.component_id FROM tracking_flags_visibility tf1 LEFT JOIN tracking_flags_visibility tf2 ON tf1.tracking_flag_id = tf2.tracking_flag_id AND tf2.product_id = ? WHERE tf1.product_id = ? - AND tf2.tracking_flag_id IS NULL", - undef, - $tgtprodid, $tgtprodid, $srcprodid); + AND tf2.tracking_flag_id IS NULL", undef, $tgtprodid, + $tgtprodid, $srcprodid +); # 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. diff --git a/scripts/syncmsandversions.pl b/scripts/syncmsandversions.pl index 509a78cc8..25434f5d4 100755 --- a/scripts/syncmsandversions.pl +++ b/scripts/syncmsandversions.pl @@ -31,7 +31,7 @@ use Bugzilla; use Bugzilla::Constants; sub usage() { - print <<USAGE; + print <<USAGE; Usage: syncmsandversions.pl <srcproduct> <tgtproduct> E.g.: syncmsandversions.pl FoodReplicator SeaMonkey @@ -40,7 +40,7 @@ which do not exist in product "SeaMonkey" into it. This script is normally used prior to moving components from srcproduct to tgtproduct. USAGE - exit(1); + exit(1); } ############################################################################# @@ -51,8 +51,8 @@ USAGE Bugzilla->usage_mode(USAGE_MODE_CMDLINE); if (scalar @ARGV < 2) { - usage(); - exit(); + usage(); + exit(); } my ($srcproduct, $tgtproduct) = @ARGV; @@ -61,17 +61,17 @@ my $dbh = Bugzilla->dbh; # Find product IDs my $srcprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", - undef, $srcproduct); + undef, $srcproduct); if (!$srcprodid) { - print "Can't find product ID for '$srcproduct'.\n"; - exit(1); + print "Can't find product ID for '$srcproduct'.\n"; + exit(1); } my $tgtprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", - undef, $tgtproduct); + undef, $tgtproduct); if (!$tgtprodid) { - print "Can't find product ID for '$tgtproduct'.\n"; - exit(1); + print "Can't find product ID for '$tgtproduct'.\n"; + exit(1); } $dbh->bz_start_transaction(); @@ -84,9 +84,7 @@ $dbh->do(" AND m2.product_id = ? WHERE m1.product_id = ? AND m2.value IS NULL - ", - undef, - $tgtprodid, $tgtprodid, $srcprodid); + ", undef, $tgtprodid, $tgtprodid, $srcprodid); $dbh->do(" INSERT INTO versions(value, isactive, product_id) @@ -96,9 +94,7 @@ $dbh->do(" AND v2.product_id = ? WHERE v1.product_id = ? AND v2.value IS NULL - ", - undef, - $tgtprodid, $tgtprodid, $srcprodid); + ", undef, $tgtprodid, $tgtprodid, $srcprodid); $dbh->do(" INSERT INTO group_control_map (group_id, product_id, entry, membercontrol, @@ -112,9 +108,7 @@ $dbh->do(" AND g1.group_id = g2.group_id WHERE g1.product_id = ? AND g2.group_id IS NULL - ", - undef, - $tgtprodid, $srcprodid, $tgtprodid, $srcprodid); + ", undef, $tgtprodid, $srcprodid, $tgtprodid, $srcprodid); $dbh->bz_commit_transaction(); diff --git a/scripts/triage_owners_csv.pl b/scripts/triage_owners_csv.pl index e3feeee0f..460b3cc11 100755 --- a/scripts/triage_owners_csv.pl +++ b/scripts/triage_owners_csv.pl @@ -12,8 +12,6 @@ use warnings; use lib qw(. lib local/lib/perl5); - - use Bugzilla; use Bugzilla::Component; use Bugzilla::Constants; @@ -24,7 +22,7 @@ use Text::CSV_XS; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $auto_user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); +my $auto_user = Bugzilla::User->check({name => 'automation@bmo.tld'}); Bugzilla->set_user($auto_user); my $dbh = Bugzilla->dbh; @@ -37,36 +35,38 @@ open(CSV, $filename) || die "Could not open CSV file: $!\n"; # Original Email,LDAP,Bugmail,Product,Component my $csv = Text::CSV_XS->new(); while (my $line = <CSV>) { - $csv->parse($line); - my @values = $csv->fields(); - next if !@values; - my ($email, $product_name, $component_name) = @values[2..4]; - print "Updating triage owner for '$product_name :: $component_name' "; - my $product = Bugzilla::Product->new({ name => $product_name, cache => 1 }); - if (!$product) { - print "product '$product_name' does not exist ... skipping.\n"; - next; - } - my $component = Bugzilla::Component->new({ name => $component_name, product => $product, cache => 1 }); - if (!$component) { - print "component '$component_name' does not exist ... skipping.\n"; - next; - } - if (!$email) { - print "... no email ... skipped.\n"; - next; - } - my $user = Bugzilla::User->new({ name => $email, cached => 1 }); - if (!$user) { - print "... email '$email' does not exist ... skipping.\n"; - next; - } - print "to '$email' ... "; - # HACK: See extensions/ComponentWatching/Extension.pm line 175 - Bugzilla->input_params->{watch_user} = $component->watch_user->login; - $component->set_triage_owner($email); - $component->update(); - print "done.\n"; + $csv->parse($line); + my @values = $csv->fields(); + next if !@values; + my ($email, $product_name, $component_name) = @values[2 .. 4]; + print "Updating triage owner for '$product_name :: $component_name' "; + my $product = Bugzilla::Product->new({name => $product_name, cache => 1}); + if (!$product) { + print "product '$product_name' does not exist ... skipping.\n"; + next; + } + my $component = Bugzilla::Component->new( + {name => $component_name, product => $product, cache => 1}); + if (!$component) { + print "component '$component_name' does not exist ... skipping.\n"; + next; + } + if (!$email) { + print "... no email ... skipped.\n"; + next; + } + my $user = Bugzilla::User->new({name => $email, cached => 1}); + if (!$user) { + print "... email '$email' does not exist ... skipping.\n"; + next; + } + print "to '$email' ... "; + + # HACK: See extensions/ComponentWatching/Extension.pm line 175 + Bugzilla->input_params->{watch_user} = $component->watch_user->login; + $component->set_triage_owner($email); + $component->update(); + print "done.\n"; } close(CSV) || die "Could not close CSV file: $!\n"; diff --git a/scripts/undo.pl b/scripts/undo.pl index 24d6f594b..20509cd55 100755 --- a/scripts/undo.pl +++ b/scripts/undo.pl @@ -13,14 +13,15 @@ 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))); + 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 }; +BEGIN { Bugzilla->extensions } use Bugzilla::Extension::UserProfile::Util qw(tag_for_recount_from_bug); use Try::Tiny; @@ -45,38 +46,35 @@ my $query = q{ 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}, - }; - } + my @args = @_; + my $changes = get_changes(@args); + my $comments = get_comments(@args); - while ($_ = $comments->()) { - push @{ $action{ $_->{bug_id} }{$_->{bug_when}}{remove_comments} }, { - id => $_->{comment_id}, - }; - } + 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},}; + } - 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{ + 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 @@ -84,57 +82,54 @@ sub undo { 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; - }; + }, 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; } - say 'Done.'; + catch { + chomp $_; + say "Error updating $bug_id: $_"; + $dbh->bz_rollback_transaction; + }; + } + say 'Done.'; } sub get_changes { - my ($where, @bind) = @_; + my ($where, @bind) = @_; - my $sql = qq{ + my $sql = qq{ SELECT BA.id AS change_id, BA.bug_id, @@ -163,16 +158,16 @@ sub get_changes { 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); + my $sth = Bugzilla->dbh->prepare($sql); + $sth->execute(@bind); - return sub { $sth->fetchrow_hashref }; + return sub { $sth->fetchrow_hashref }; } sub get_comments { - my ($where, @bind) = @_; + my ($where, @bind) = @_; - my $sql = qq{ + my $sql = qq{ SELECT C.comment_id AS comment_id, C.bug_id AS bug_id, @@ -196,8 +191,8 @@ sub get_comments { 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); + my $sth = Bugzilla->dbh->prepare($sql); + $sth->execute(@bind); - return sub { $sth->fetchrow_hashref }; + return sub { $sth->fetchrow_hashref }; } diff --git a/scripts/update-bug-groups.pl b/scripts/update-bug-groups.pl index ef82f0ad6..cb737bb23 100755 --- a/scripts/update-bug-groups.pl +++ b/scripts/update-bug-groups.pl @@ -30,7 +30,7 @@ my $options = {}; GetOptions($options, 'add=s', 'remove=s') or exit(1); my $url = URI->new(shift); unless ($url && ($options->{add} || $options->{remove})) { - die <<EOF; + die <<EOF; Syntax: update-bug-groups.pl [--add group-name] [--remove group-name] buglist-url @@ -46,52 +46,56 @@ Synopsis: EOF } die "Invalid buglist.cgi query\n" unless $url->path =~ m#/buglist\.cgi$#; -$url->query_param( limit => 0 ); +$url->query_param(limit => 0); my ($add_group, $remove_group); -$add_group = Bugzilla::Group->check({ name => $options->{add} }) if $options->{add}; -$remove_group = Bugzilla::Group->check({ name => $options->{remove} }) if $options->{remove}; - -my $user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); -$user->{groups} = [ Bugzilla::Group->get_all ]; -$user->{bless_groups} = [ Bugzilla::Group->get_all ]; +$add_group = Bugzilla::Group->check({name => $options->{add}}) + if $options->{add}; +$remove_group = Bugzilla::Group->check({name => $options->{remove}}) + if $options->{remove}; + +my $user = Bugzilla::User->check({name => 'automation@bmo.tld'}); +$user->{groups} = [Bugzilla::Group->get_all]; +$user->{bless_groups} = [Bugzilla::Group->get_all]; Bugzilla->set_user($user); # find the bugs my $params = Bugzilla::CGI->new($url->query); my $search = Bugzilla::Search->new( - fields => [ 'bug_id', 'short_desc' ], - params => scalar $params->Vars, - user => $user, + fields => ['bug_id', 'short_desc'], + params => scalar $params->Vars, + user => $user, ); -my $bugs = $search->data; +my $bugs = $search->data; my $count = scalar @$bugs; # update die "No bugs found\n" unless $count; -print "Query matched $count bug(s)\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; +print + "Query matched $count bug(s)\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; getc(); -my $dbh = Bugzilla->dbh; +my $dbh = Bugzilla->dbh; my $updated = 0; foreach my $ra (@$bugs) { - $dbh->bz_start_transaction; - my ($bug_id, $summary) = @$ra; - print "$bug_id - $summary\n"; - my $bug = Bugzilla::Bug->check($bug_id); - $bug->add_group($add_group) if $add_group; - $bug->remove_group($remove_group) if $remove_group; - my $changes = $bug->update(); - if (scalar keys %$changes) { - $dbh->do("UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?", undef, $bug->id); - $updated++; - } - $dbh->bz_commit_transaction; - - # drop cached user objects to avoid excessive memory usage - Bugzilla::User->object_cache_clearall(); + $dbh->bz_start_transaction; + my ($bug_id, $summary) = @$ra; + print "$bug_id - $summary\n"; + my $bug = Bugzilla::Bug->check($bug_id); + $bug->add_group($add_group) if $add_group; + $bug->remove_group($remove_group) if $remove_group; + my $changes = $bug->update(); + if (scalar keys %$changes) { + $dbh->do("UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?", + undef, $bug->id); + $updated++; + } + $dbh->bz_commit_transaction; + + # drop cached user objects to avoid excessive memory usage + Bugzilla::User->object_cache_clearall(); } print "\nUpdated $updated bugs(s)\n"; diff --git a/scripts/update-crash-signatures.pl b/scripts/update-crash-signatures.pl index 292427955..324495f0e 100755 --- a/scripts/update-crash-signatures.pl +++ b/scripts/update-crash-signatures.pl @@ -13,8 +13,6 @@ use lib qw(. lib local/lib/perl5); $| = 1; - - use constant BATCH_SIZE => 100; use Bugzilla; @@ -26,9 +24,9 @@ use Text::Balanced qw( extract_bracketed extract_multiple ); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $user = Bugzilla::User->check({ name => 'automation@bmo.tld' }); -$user->{groups} = [ Bugzilla::Group->get_all ]; -$user->{bless_groups} = [ Bugzilla::Group->get_all ]; +my $user = Bugzilla::User->check({name => 'automation@bmo.tld'}); +$user->{groups} = [Bugzilla::Group->get_all]; +$user->{bless_groups} = [Bugzilla::Group->get_all]; Bugzilla->set_user($user); my $dbh = Bugzilla->dbh; @@ -36,105 +34,108 @@ my $dbh = Bugzilla->dbh; # find the bugs my $bugs = $dbh->selectall_arrayref( - "SELECT bug_id,cf_crash_signature FROM bugs WHERE resolution = '' AND cf_crash_signature != ''", - { Slice => {} } + "SELECT bug_id,cf_crash_signature FROM bugs WHERE resolution = '' AND cf_crash_signature != ''", + {Slice => {}} ); my $count = scalar @$bugs; # update die "No bugs found\n" unless $count; -print "Found $count open bug(s) with crash signatures\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; +print + "Found $count open bug(s) with crash signatures\nPress <Ctrl-C> to stop or <Enter> to continue..\n"; getc(); my $updated = 0; foreach my $rh_bug (@$bugs) { - my $bug_id = $rh_bug->{bug_id}; - my $signature = $rh_bug->{cf_crash_signature}; - - # check for updated signature - my $collapsed = collapse($signature); - next if is_same($signature, $collapsed); - - # ignore signatures malformed in a way that would result in updating on each pass - next if $collapsed ne collapse($collapsed); - - # update the bug, preventing bugmail - print "$bug_id\n"; - $dbh->bz_start_transaction; - my $bug = Bugzilla::Bug->check($bug_id); - $bug->set_all({ cf_crash_signature => $collapsed }); - $bug->update(); - $dbh->do("UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?", undef, $bug_id); - $dbh->bz_commit_transaction; - - # object caching causes us to consume a lot of memory - # process in batches - last if ++$updated == BATCH_SIZE; + my $bug_id = $rh_bug->{bug_id}; + my $signature = $rh_bug->{cf_crash_signature}; + + # check for updated signature + my $collapsed = collapse($signature); + next if is_same($signature, $collapsed); + + # ignore signatures malformed in a way that would result in updating on each pass + next if $collapsed ne collapse($collapsed); + + # update the bug, preventing bugmail + print "$bug_id\n"; + $dbh->bz_start_transaction; + my $bug = Bugzilla::Bug->check($bug_id); + $bug->set_all({cf_crash_signature => $collapsed}); + $bug->update(); + $dbh->do("UPDATE bugs SET lastdiffed = delta_ts WHERE bug_id = ?", + undef, $bug_id); + $dbh->bz_commit_transaction; + + # object caching causes us to consume a lot of memory + # process in batches + last if ++$updated == BATCH_SIZE; } print "Updated $updated bugs(s)\n"; sub is_same { - my ($old, $new) = @_; - $old =~ s/[\015\012]+/ /g; - $new =~ s/[\015\012]+/ /g; - return trim($old) eq trim($new); + my ($old, $new) = @_; + $old =~ s/[\015\012]+/ /g; + $new =~ s/[\015\012]+/ /g; + return trim($old) eq trim($new); } sub collapse { - my ($crash_signature) = @_; - - # ignore completely invalid signatures - return $crash_signature unless $crash_signature =~ /\[/ && $crash_signature =~ /\]/; - - # split - my @signatures = - grep { /\S/ } - extract_multiple($crash_signature, [ sub { extract_bracketed($_[0], '[]') } ]); - my @unbracketed = map { unbracketed($_) } @signatures; - - foreach my $signature (@signatures) { - # ignore invalid signatures - next unless $signature =~ /^\s*\[/; - next if unbracketed($signature) =~ /\.\.\.$/; - - # collpase - my $collapsed = collapse_crash_sig({ - signature => $signature, - open => '<', - replacement_open => '<', - close => '>', - replacement_close => 'T>', - exceptions => [], - }); - $collapsed = collapse_crash_sig({ - signature => $collapsed, - open => '(', - replacement_open => '', - close => ')', - replacement_close => '', - exceptions => ['anonymous namespace', 'operator'], - }); - $collapsed =~ s/\s+/ /g; - - # ignore sigs that collapse down to nothing - next if $collapsed eq '[@ ]'; - - # don't create duplicates - my $unbracketed = unbracketed($collapsed); - next if any { $unbracketed eq $_ } @unbracketed; - - push @signatures, $collapsed; - push @unbracketed, $unbracketed; - } - - return join("\015\012", map { trim($_) } @signatures); + my ($crash_signature) = @_; + + # ignore completely invalid signatures + return $crash_signature + unless $crash_signature =~ /\[/ && $crash_signature =~ /\]/; + + # split + my @signatures = grep {/\S/} + extract_multiple($crash_signature, [sub { extract_bracketed($_[0], '[]') }]); + my @unbracketed = map { unbracketed($_) } @signatures; + + foreach my $signature (@signatures) { + + # ignore invalid signatures + next unless $signature =~ /^\s*\[/; + next if unbracketed($signature) =~ /\.\.\.$/; + + # collpase + my $collapsed = collapse_crash_sig({ + signature => $signature, + open => '<', + replacement_open => '<', + close => '>', + replacement_close => 'T>', + exceptions => [], + }); + $collapsed = collapse_crash_sig({ + signature => $collapsed, + open => '(', + replacement_open => '', + close => ')', + replacement_close => '', + exceptions => ['anonymous namespace', 'operator'], + }); + $collapsed =~ s/\s+/ /g; + + # ignore sigs that collapse down to nothing + next if $collapsed eq '[@ ]'; + + # don't create duplicates + my $unbracketed = unbracketed($collapsed); + next if any { $unbracketed eq $_ } @unbracketed; + + push @signatures, $collapsed; + push @unbracketed, $unbracketed; + } + + return join("\015\012", map { trim($_) } @signatures); } sub unbracketed { - my ($signature) = @_; - $signature =~ s/(^\s*\[\s*|\s*\]\s*$)//g; - return $signature; + my ($signature) = @_; + $signature =~ s/(^\s*\[\s*|\s*\]\s*$)//g; + return $signature; } # collapsing code lifted from socorro: @@ -143,58 +144,63 @@ sub unbracketed { my ($target_counter, $exception_mode, @collapsed); sub append_if_not_in_collapse_mode { - my ($character) = @_; - if (!$target_counter) { - push @collapsed, $character; - } + my ($character) = @_; + if (!$target_counter) { + push @collapsed, $character; + } } sub is_exception { - my ($exceptions, $remaining_original_line, $line_up_to_current_position) = @_; - foreach my $exception (@$exceptions) { - if (substr($remaining_original_line, 0, length($exception)) eq $exception) { - return 1; - } - if (substr($line_up_to_current_position, -length($exception)) eq $exception) { - return 1; - } + my ($exceptions, $remaining_original_line, $line_up_to_current_position) = @_; + foreach my $exception (@$exceptions) { + if (substr($remaining_original_line, 0, length($exception)) eq $exception) { + return 1; + } + if (substr($line_up_to_current_position, -length($exception)) eq $exception) { + return 1; } - return 0; + } + return 0; } sub collapse_crash_sig { - my ($params) = @_; - - $target_counter = 0; - @collapsed = (); - $exception_mode = 0; - my $signature = $params->{signature}; - - for (my $i = 0; $i < length($signature); $i++) { - my $character = substr($signature, $i, 1); - if ($character eq $params->{open}) { - if (is_exception($params->{exceptions}, substr($signature, $i + 1), substr($signature, 0, $i))) { - $exception_mode = 1; - append_if_not_in_collapse_mode($character); - next; - } - append_if_not_in_collapse_mode($params->{replacement_open}); - $target_counter++; - } - elsif ($character eq $params->{close}) { - if ($exception_mode) { - append_if_not_in_collapse_mode($character); - $exception_mode = 0; - } - else { - $target_counter--; - append_if_not_in_collapse_mode($params->{replacement_close}); - } - } - else { - append_if_not_in_collapse_mode($character); - } + my ($params) = @_; + + $target_counter = 0; + @collapsed = (); + $exception_mode = 0; + my $signature = $params->{signature}; + + for (my $i = 0; $i < length($signature); $i++) { + my $character = substr($signature, $i, 1); + if ($character eq $params->{open}) { + if (is_exception( + $params->{exceptions}, + substr($signature, $i + 1), + substr($signature, 0, $i) + )) + { + $exception_mode = 1; + append_if_not_in_collapse_mode($character); + next; + } + append_if_not_in_collapse_mode($params->{replacement_open}); + $target_counter++; + } + elsif ($character eq $params->{close}) { + if ($exception_mode) { + append_if_not_in_collapse_mode($character); + $exception_mode = 0; + } + else { + $target_counter--; + append_if_not_in_collapse_mode($params->{replacement_close}); + } + } + else { + append_if_not_in_collapse_mode($character); } + } - return join '', @collapsed; + return join '', @collapsed; } diff --git a/scripts/update_localconfig.pl b/scripts/update_localconfig.pl index ca3329022..8ced925d5 100755 --- a/scripts/update_localconfig.pl +++ b/scripts/update_localconfig.pl @@ -21,25 +21,27 @@ use File::Slurp; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -my $localconfig = Bugzilla::Install::Localconfig::read_localconfig(); +my $localconfig = Bugzilla::Install::Localconfig::read_localconfig(); my ($param_name, $param_value) = @ARGV; die "Syntax: $0 param_name param_value\n" unless defined($param_value); -die "Invalid param name: $param_name\n" unless exists $localconfig->{$param_name}; +die "Invalid param name: $param_name\n" + unless exists $localconfig->{$param_name}; if ($localconfig->{$param_name} ne $param_value) { - my @file = read_file('localconfig'); - my $updated = 0; - foreach my $line (@file) { - next unless $line =~ /^\s*\$([\w_]+)\s*=\s*'([^']*)'/; - my ($name, $value) = ($1, $2); - if ($name eq $param_name && $value ne $param_value) { - print "setting '$name' to '$param_value'\n"; - $line = "\$$name = '$param_value';\n"; - $updated = 1; - } + my @file = read_file('localconfig'); + my $updated = 0; + foreach my $line (@file) { + next unless $line =~ /^\s*\$([\w_]+)\s*=\s*'([^']*)'/; + my ($name, $value) = ($1, $2); + if ($name eq $param_name && $value ne $param_value) { + print "setting '$name' to '$param_value'\n"; + $line = "\$$name = '$param_value';\n"; + $updated = 1; } - write_file('localconfig', @file) if $updated; -} else { - print "'$param_name' is already '$param_value'\n"; + } + write_file('localconfig', @file) if $updated; +} +else { + print "'$param_name' is already '$param_value'\n"; } diff --git a/scripts/update_params.pl b/scripts/update_params.pl index f1a069d61..a42313f42 100755 --- a/scripts/update_params.pl +++ b/scripts/update_params.pl @@ -22,12 +22,13 @@ my $params = Bugzilla->params; my ($param_name, $param_value) = @ARGV; die "Syntax: $0 param_name param_value\n" unless defined($param_value); -die "Invalid param name: $param_name\n" unless exists $params->{$param_name}; +die "Invalid param name: $param_name\n" unless exists $params->{$param_name}; if ($params->{$param_name} ne $param_value) { - SetParam($param_name, $param_value); - write_params(); - say "'$param_name' set to '$param_value'"; -} else { - say "'$param_name' is already '$param_value'"; + SetParam($param_name, $param_value); + write_params(); + say "'$param_name' set to '$param_value'"; +} +else { + say "'$param_name' is already '$param_value'"; } diff --git a/scripts/user-prefs.pl b/scripts/user-prefs.pl index dc44c5aea..f63eaf3d5 100755 --- a/scripts/user-prefs.pl +++ b/scripts/user-prefs.pl @@ -20,36 +20,44 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my ($login, $action, $param, $value) = @ARGV; ($login && $action && $action =~ /^(get|set)$/) - or die "syntax: $0 <bugzilla-login> <get|set> [param] [value]\n"; + or die "syntax: $0 <bugzilla-login> <get|set> [param] [value]\n"; -my $user = Bugzilla::User->check({ name => $login }); +my $user = Bugzilla::User->check({name => $login}); my $settings = $user->settings; if ($action eq 'get') { - if ($param eq '') { - foreach my $name (sort keys %$settings) { - printf "%s=%s\n", $name, $settings->{$name}->{value}; - } - } elsif (exists $settings->{$param}) { - say $settings->{$param}->{value}; - } else { - die "Invalid parameter name: $param\n"; + if ($param eq '') { + foreach my $name (sort keys %$settings) { + printf "%s=%s\n", $name, $settings->{$name}->{value}; } -} else { - if ($param eq '') { - die "Parameter name required\n"; - } elsif (!exists $settings->{$param}) { - die "Invalid parameter name: $param\n"; - } elsif (!defined($value) || $value eq '') { - die "Missing parameter value\n"; - } else { - my $setting = $settings->{$param}; - # not using validate_value here so we can print out a list of the legal values - my $legal_values = $setting->legal_values; - if (! grep { $value eq $_ } @$legal_values) { - die "Invalid value '$value' for param $param.\nAccepted values: " . join(' ', @$legal_values) . "\n"; - } - $setting->set($value); - say "'$param' set to '$value'"; + } + elsif (exists $settings->{$param}) { + say $settings->{$param}->{value}; + } + else { + die "Invalid parameter name: $param\n"; + } +} +else { + if ($param eq '') { + die "Parameter name required\n"; + } + elsif (!exists $settings->{$param}) { + die "Invalid parameter name: $param\n"; + } + elsif (!defined($value) || $value eq '') { + die "Missing parameter value\n"; + } + else { + my $setting = $settings->{$param}; + + # not using validate_value here so we can print out a list of the legal values + my $legal_values = $setting->legal_values; + if (!grep { $value eq $_ } @$legal_values) { + die "Invalid value '$value' for param $param.\nAccepted values: " + . join(' ', @$legal_values) . "\n"; } + $setting->set($value); + say "'$param' set to '$value'"; + } } |