diff options
Diffstat (limited to 'contrib/reorg-tools')
-rw-r--r-- | contrib/reorg-tools/README | 9 | ||||
-rwxr-xr-x | contrib/reorg-tools/bmo-plan.txt | 82 | ||||
-rw-r--r-- | contrib/reorg-tools/fix_all_open_status_queries.pl | 140 | ||||
-rwxr-xr-x | contrib/reorg-tools/fixgroupqueries.pl | 119 | ||||
-rwxr-xr-x | contrib/reorg-tools/fixqueries.pl | 132 | ||||
-rwxr-xr-x | contrib/reorg-tools/migrate_crash_signatures.pl | 126 | ||||
-rw-r--r-- | contrib/reorg-tools/migrate_orange_bugs.pl | 154 | ||||
-rwxr-xr-x | contrib/reorg-tools/move_flag_types.pl | 168 | ||||
-rwxr-xr-x | contrib/reorg-tools/movebugs.pl | 172 | ||||
-rwxr-xr-x | contrib/reorg-tools/movecomponent.pl | 193 | ||||
-rw-r--r-- | contrib/reorg-tools/reset_default_user.pl | 143 | ||||
-rwxr-xr-x | contrib/reorg-tools/syncflags.pl | 86 | ||||
-rwxr-xr-x | contrib/reorg-tools/syncmsandversions.pl | 107 |
13 files changed, 1631 insertions, 0 deletions
diff --git a/contrib/reorg-tools/README b/contrib/reorg-tools/README new file mode 100644 index 000000000..4e5d6eb4d --- /dev/null +++ b/contrib/reorg-tools/README @@ -0,0 +1,9 @@ +Upstreaming attempt: https://bugzilla.mozilla.org/show_bug.cgi?id=616499 + +Included in this directory is a group of tools we've used for moving components +around in a Bugzilla 3.2 install on bugzilla.mozilla.org. + +They may require tweaking if you use them on your own install. Putting them +here to make it easier to collaborate on them and keep them up-to-date. +Hopefully Bugzilla upstream will be able to just do this from the web UI +eventually. diff --git a/contrib/reorg-tools/bmo-plan.txt b/contrib/reorg-tools/bmo-plan.txt new file mode 100755 index 000000000..838ff0ab9 --- /dev/null +++ b/contrib/reorg-tools/bmo-plan.txt @@ -0,0 +1,82 @@ +==BMO Reorg Plan== + +Do the following things, mostly in order (but see "Timing" at the end): + +1) Create new classifications using GUI: + Graveyard (Description: "Old, retired products", sort key: <last>) + +2) Rename classifications using GUI: + Client Support to Other + +3) Move products between classification using GUI: + Grendel from Client Software to Graveyard + CCK from Unclassified to Graveyard + Derivatives from Unclassified to Graveyard + MozillaClassic from Unclassified to Graveyard + UI: "reclassify" link from the top-level classification list + +4) Create new products using GUI: + Core Graveyard in Graveyard + (desc: "Old, retired Core components", closed for entry, no charts) + MailNews Core in Components + (desc: "Mail and news components common to Thunderbird and SeaMonkey", + open for bug entry, create charts) + +5) Rename products using GUI, and fix queries using fixqueries.pl: +mysql> update series_categories set name="SeaMonkey (2)" where id=32; + Mozilla Application Suite to SeaMonkey + Sumo to support.mozilla.com + +5.5) Rename versions and milestones in Toolkit to match Firefox before step 6 + +6) Sync milestones, versions and groups between products using +syncmsandversions.pl: + Core -> Core Graveyard (new) + Core -> MailNews Core (new) + Firefox -> Toolkit + Core -> SeaMonkey + mozilla.org -> Websites (only 1) + +6.5) Sync flag inclusions using syncflags.pl: + Core -> Core Graveyard (new) + Core -> MailNews Core (new) + Core -> SeaMonkey + mozilla.org -> Websites (only 1) + +6.7) Allow Firefox flags temporarily in Toolkit: + 250 | blocking-firefox3 | blocking1.9 - 387 + 419 | blocking-firefox3.1 | blocking1.9.1 - 416 + 63 | blocking0.8 | blocking1.6 - 69 + 76 | blocking0.9 | blocking1.7 - 83 + 36 | review | review - 4 + 356 | wanted-firefox3 | wanted1.9 - 357 + 418 | wanted-firefox3.1 | wanted1.9.1 - 417 + +7) Move components using movecomponent.pl. + Any instruction beginning "moved from". + Can't fix the queries for this - oh well + <Very long list> + +8) Rename components using GUI, and fix queries using fixqueries.pl. + Any instruction beginning "renamed from" or "MailNews: prefix removed". + <Long list> + +9) Create new components using GUI. + Any instruction beginning "new". + <Long list> + +10) Move open bugs using GUI: + XP Miscellany to Core/General + +11) Merge components by moving bugs using GUI: + Any instruction beginning "merge in". + Merge all bugs, including closed. Delete empty component when done. + <long list of merges> + +12) Close Core Graveyard (and Grendel if necessary) to new bugs + +13) Rename Toolkit versions and milestones back (from 5.5) + +14) Execute flag mapping SQL using Reed's mapping to update bugs in Toolkit + +15) Disable above-listed flags in point 6.7 in Toolkit again diff --git a/contrib/reorg-tools/fix_all_open_status_queries.pl b/contrib/reorg-tools/fix_all_open_status_queries.pl new file mode 100644 index 000000000..b51ac21c2 --- /dev/null +++ b/contrib/reorg-tools/fix_all_open_status_queries.pl @@ -0,0 +1,140 @@ +#!/usr/bin/perl -w +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Status; +use Bugzilla::Util; + +sub usage() { + print <<USAGE; +Usage: fix_all_open_status_queries.pl <new_open_status> + +E.g.: fix_all_open_status_queries.pl READY +This will add a new open state to user queries which currently look for +all open bugs by listing every open status in their query criteria. +For users who only look for bug_status=__open__, they will get the new +open status automatically. +USAGE +} + +sub do_namedqueries { + my ($new_status) = @_; + my $dbh = Bugzilla->dbh; + my $replace_count = 0; + + my $query = $dbh->selectall_arrayref("SELECT id, query FROM namedqueries"); + + if ($query) { + $dbh->bz_start_transaction(); + + 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(); + } + + 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"); + + if ($query) { + $dbh->bz_start_transaction(); + + my $sth = $dbh->prepare("UPDATE series SET query = ? WHERE series_id = ?"); + + 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++; + } + } + + $dbh->bz_commit_transaction(); + } + + print "series: $replace_count replacements made.\n"; +} + +sub all_open_states { + 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 ($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(); + } + + 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; +} + +############################################################################# +# MAIN CODE +############################################################################# +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 1) { + usage(); + exit(1); +} + +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 "Adding new status '$new_status'.\n\n"; + +do_namedqueries($new_status); +do_series($new_status); + +exit(0); diff --git a/contrib/reorg-tools/fixgroupqueries.pl b/contrib/reorg-tools/fixgroupqueries.pl new file mode 100755 index 000000000..1c75edb97 --- /dev/null +++ b/contrib/reorg-tools/fixgroupqueries.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Util; + +sub usage() { + print <<USAGE; +Usage: fixgroupqueries.pl <oldvalue> <newvalue> + +E.g.: fixgroupqueries.pl w-security webtools-security +will change all occurrences of "w-security" to "webtools-security" in the +appropriate places in the namedqueries. + +Note that all parameters are case-sensitive. +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++; + } + } + } + + 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++; + } + } + } + + #$dbh->bz_commit_transaction(); + print "series: $replace_count replacements made.\n"; +} + +############################################################################# +# MAIN CODE +############################################################################# +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 2) { + usage(); + exit(); +} + +my ($old, $new) = @ARGV; + +print "Changing all instances of '$old' to '$new'.\n\n"; + +#do_namedqueries($old, $new); +do_series($old, $new); + +exit(0); diff --git a/contrib/reorg-tools/fixqueries.pl b/contrib/reorg-tools/fixqueries.pl new file mode 100755 index 000000000..4b862fd72 --- /dev/null +++ b/contrib/reorg-tools/fixqueries.pl @@ -0,0 +1,132 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Util; + +sub usage() { + print <<USAGE; +Usage: fixqueries.pl <parameter> <oldvalue> <newvalue> + +E.g.: fixqueries.pl product FoodReplicator SeaMonkey +will change all occurrences of "FoodReplicator" to "Seamonkey" in the +appropriate places in the namedqueries, series and series_categories tables. + +Note that all parameters are case-sensitive. +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++; + } + } + } + + #$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); + } + } + + #$dbh->bz_commit_transaction(); + print "series: $replace_count replacements made.\n"; +} + +# series_categories +sub do_series_categories($$) { + my ($old, $new) = @_; + my $dbh = Bugzilla->dbh; + + $dbh->do("UPDATE series_categories SET name = ? WHERE name = ?", + undef, + ($new, $old)); +} + +############################################################################# +# MAIN CODE +############################################################################# +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 3) { + usage(); + exit(); +} + +my ($field, $old, $new) = @ARGV; + +print "Changing all instances of '$old' to '$new'.\n\n"; + +do_namedqueries($field, $old, $new); +do_series($field, $old, $new); +do_series_categories($old, $new); + +exit(0); + diff --git a/contrib/reorg-tools/migrate_crash_signatures.pl b/contrib/reorg-tools/migrate_crash_signatures.pl new file mode 100755 index 000000000..b12446280 --- /dev/null +++ b/contrib/reorg-tools/migrate_crash_signatures.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Initial Developer of the Original Code is Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +#=============================================================================== +# +# FILE: migrate_crash_signatures.pl +# +# USAGE: ./migrate_crash_signatures.pl +# +# DESCRIPTION: Migrate current summary data on matched bugs to the +# new cf_crash_signature custom fields. +# +# OPTIONS: No params, then performs dry-run without updating the database. +# If a true value is passed as single argument, then the database +# is updated. +# REQUIREMENTS: None +# BUGS: 577724 +# NOTES: None +# AUTHOR: David Lawrence (dkl@mozilla.com), +# COMPANY: Mozilla Corproation +# VERSION: 1.0 +# CREATED: 05/31/2011 03:57:52 PM +# REVISION: 1 +#=============================================================================== + +use strict; +use warnings; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Util; + +use Data::Dumper; + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $UPDATE_DB = shift; # Pass true value as single argument to perform database update + +my $dbh = Bugzilla->dbh; + +# User to make changes as +my $user_id = $dbh->selectrow_array( + "SELECT userid FROM profiles WHERE login_name='nobody\@mozilla.org'"); +$user_id or die "Can't find user ID for 'nobody\@mozilla.org'\n"; + +my $field_id = $dbh->selectrow_array( + "SELECT id FROM fielddefs WHERE name = 'cf_crash_signature'"); +$field_id or die "Can't find field ID for 'cf_crash_signature' field\n"; + +# Search criteria +# a) crash or topcrash keyword, +# b) not have [notacrash] in whiteboard, +# c) have a properly formulated [@ ...] + +# crash and topcrash keyword ids +my $crash_keyword_id = $dbh->selectrow_array( + "SELECT id FROM keyworddefs WHERE name = 'crash'"); +$crash_keyword_id or die "Can't find keyword id for 'crash'\n"; + +my $topcrash_keyword_id = $dbh->selectrow_array( + "SELECT id FROM keyworddefs WHERE name = 'topcrash'"); +$topcrash_keyword_id or die "Can't find keyword id for 'topcrash'\n"; + +# main search query +my $bugs = $dbh->selectall_arrayref(" + SELECT bugs.bug_id, bugs.short_desc + FROM bugs LEFT JOIN keywords ON bugs.bug_id = keywords.bug_id + WHERE (keywords.keywordid = ? OR keywords.keywordid = ?) + AND bugs.status_whiteboard NOT REGEXP '\\\\[notacrash\\\\]' + AND bugs.short_desc REGEXP '\\\\[@.+\\\\]' + AND (bugs.cf_crash_signature IS NULL OR bugs.cf_crash_signature = '') + ORDER BY bugs.bug_id", + {'Slice' => {}}, $crash_keyword_id, $topcrash_keyword_id); + +my $bug_count = scalar @$bugs; +$bug_count or die "No bugs were found in matching search criteria.\n"; + +print "Migrating $bug_count bugs to new crash signature field\n"; + +$dbh->bz_start_transaction() if $UPDATE_DB; + +foreach my $bug (@$bugs) { + my $bug_id = $bug->{'bug_id'}; + my $summary = $bug->{'short_desc'}; + + print "Updating bug $bug_id ..."; + + my @signatures; + while ($summary =~ /(\[\@(?:\[.*\]|[^\[])*\])/g) { + push(@signatures, $1); + } + + if (@signatures && $UPDATE_DB) { + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + $dbh->do("UPDATE bugs SET cf_crash_signature = ? WHERE bug_id = ?", + undef, join("\n", @signatures), $bug_id); + $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . + "VALUES (?, ?, ?, ?, '', ?)", + undef, $bug_id, $user_id, $timestamp, $field_id, join("\n", @signatures)); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); + } + elsif (@signatures) { + print Dumper(\@signatures); + } + + print "done.\n"; +} + +$dbh->bz_commit_transaction() if $UPDATE_DB; diff --git a/contrib/reorg-tools/migrate_orange_bugs.pl b/contrib/reorg-tools/migrate_orange_bugs.pl new file mode 100644 index 000000000..ae68b227c --- /dev/null +++ b/contrib/reorg-tools/migrate_orange_bugs.pl @@ -0,0 +1,154 @@ +#!/usr/bin/perl -wT +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +#=============================================================================== +# +# FILE: migrate_orange_bugs.pl +# +# USAGE: ./migrate_orange_bugs.pl [--remove] +# +# DESCRIPTION: Add intermittent-keyword to bugs with [orange] stored in +# whiteboard field. If --remove, then also remove the [orange] +# value from whiteboard. +# +# OPTIONS: Without --doit, does a dry-run without updating the database. +# If --doit is passed, then the database is updated. +# --remove will remove [orange] from the whiteboard. +# REQUIREMENTS: None +# BUGS: 791758 +# NOTES: None +# AUTHOR: David Lawrence (dkl@mozilla.com), +# COMPANY: Mozilla Corproation +# VERSION: 1.0 +# CREATED: 10/31/2012 +# REVISION: 1 +#=============================================================================== + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Field; +use Bugzilla::User; +use Bugzilla::Keyword; + +use Getopt::Long; +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); + +sub usage { + my $error = shift || ""; + print colored(['red'], $error) if $error; + print <<USAGE; +Usage: migrate_orange_bugs.pl [--remove|-r] [--help|-h] [--doit] + +E.g.: migrate_orange_bugs.pl --remove --doit +This script will add the intermittent-failure keyword to any bugs that +contant [orange] in the status whiteboard. If the --remove option is +given, then [orange] will be removed from the whiteboard as well. + +Pass --doit to make the database changes permanent. +USAGE + exit(1); +} + +# Exit if help was requested +usage() if $help; + +# User to make changes as +my $user_id = login_to_id('nobody@mozilla.org'); +$user_id or usage("Can't find user ID for 'nobody\@mozilla.org'\n"); + +my $keywords_field_id = get_field_id('keywords'); +$keywords_field_id or usage("Can't find field ID for 'keywords' field\n"); + +my $whiteboard_field_id = get_field_id('status_whiteboard'); +$whiteboard_field_id or usage("Can't find field ID for 'whiteboard' field\n"); + +# intermittent-keyword id (assumes already created) +my $keyword_obj = Bugzilla::Keyword->new({ name => 'intermittent-failure' }); +$keyword_obj or usage("Can't find keyword id for 'intermittent-failure'\n"); +my $keyword_id = $keyword_obj->id; + +my $dbh = Bugzilla->dbh; + +my $bugs = $dbh->selectall_arrayref(" + SELECT DISTINCT bugs.bug_id, bugs.status_whiteboard + FROM bugs WHERE bugs.status_whiteboard LIKE '%[orange]%' + OR bugs.status_whiteboard LIKE '%[tb-orange]%'", + {'Slice' => {}}); + +my $bug_count = scalar @$bugs; +$bug_count or usage("No bugs were found in matching search criteria.\n"); + +print colored(['green'], "Processing $bug_count [orange] bugs\n"); + +$dbh->bz_start_transaction() if $doit; + +foreach my $bug (@$bugs) { + my $bug_id = $bug->{'bug_id'}; + my $whiteboard = $bug->{'status_whiteboard'}; + + print "Checking bug $bug_id ... "; + + 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_id); + + if (!$keyword_present) { + print "adding keyword ... "; + + if ($doit) { + $dbh->do("INSERT INTO keywords (bug_id, keywordid) VALUES (?, ?)", + undef, $bug_id, $keyword_id); + $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . + "VALUES (?, ?, ?, ?, '', 'intermittent-failure')", + undef, $bug_id, $user_id, $timestamp, $keywords_field_id); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); + } + } + + if ($remove_whiteboard) { + print "removing whiteboard ... "; + + if ($doit) { + my $old_whiteboard = $whiteboard; + $whiteboard =~ s/\[(tb-)?orange\]//ig; + + $dbh->do("UPDATE bugs SET status_whiteboard = ? WHERE bug_id = ?", + undef, $whiteboard, $bug_id); + $dbh->do("INSERT INTO bugs_activity(bug_id, who, bug_when, fieldid, removed, added) " . + "VALUES (?, ?, ?, ?, ?, ?)", + undef, $bug_id, $user_id, $timestamp, $whiteboard_field_id, $old_whiteboard, $whiteboard); + $dbh->do("UPDATE bugs SET delta_ts = ?, lastdiffed = ? WHERE bug_id = ?", + undef, $timestamp, $timestamp, $bug_id); + } + } + + print "done.\n"; +} + +$dbh->bz_commit_transaction() if $doit; + +if ($doit) { + print colored(['green'], "DATABASE WAS UPDATED\n"); +} +else { + print colored(['red'], "DATABASE WAS NOT UPDATED\n"); +} + +exit(0); diff --git a/contrib/reorg-tools/move_flag_types.pl b/contrib/reorg-tools/move_flag_types.pl new file mode 100755 index 000000000..a75b7f497 --- /dev/null +++ b/contrib/reorg-tools/move_flag_types.pl @@ -0,0 +1,168 @@ +#!/usr/bin/perl +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Initial Developer of the Original Code is Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +#=============================================================================== +# +# FILE: move_flag_types.pl +# +# USAGE: ./move_flag_types.pl +# +# DESCRIPTION: Move current set flag from one type_id to another +# based on product and optionally component. +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: David Lawrence (:dkl), dkl@mozilla.com +# COMPANY: Mozilla Foundation +# VERSION: 1.0 +# CREATED: 08/22/2011 05:18:06 PM +# REVISION: --- +#=============================================================================== + +=head1 NAME + +move_flag_types.pl - Move currently set flags from one type id to another based +on product and optionally component. + +=head1 SYNOPSIS + +This script will move bugs matching a specific product (and optionally a component) +from one flag type id to another if the bug has the flag set to either +, -, or ?. + +./move_flag_types.pl --old-id 4 --new-id 720 --product Firefox --component Installer + +=head1 OPTIONS + +=over + +=item B<--help|-h|?> + +Print a brief help message and exits. + +=item B<--oldid|-o> + +Old flag type id. Use editflagtypes.cgi to determine the type id from the URL. + +=item B<--newid|-n> + +New flag type id. Use editflagtypes.cgi to determine the type id from the URL. + +=item B<--product|-p> + +The product that the bugs most be assigned to. + +=item B<--component|-c> + +Optional: The component of the given product that the bugs must be assigned to. + +=item B<--doit|-d> + +Without this argument, changes are not actually committed to the database. + +=back + +=cut + +use strict; +use warnings; + +use lib '.'; + +use Bugzilla; +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 }); +} + +# Set defaults +$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'}); + +# Find the product id +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); +} + +my @query_args = ($params{'oldid'}); + +my $flag_query = "SELECT flags.id AS flag_id, flags.bug_id AS bug_id + FROM flags JOIN bugs ON flags.bug_id = bugs.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); +} +else { + # 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); + } + } +} +else { + print "No flags to move\n"; +} diff --git a/contrib/reorg-tools/movebugs.pl b/contrib/reorg-tools/movebugs.pl new file mode 100755 index 000000000..6d6a53b51 --- /dev/null +++ b/contrib/reorg-tools/movebugs.pl @@ -0,0 +1,172 @@ +#!/usr/bin/perl -w +use strict; + +use Cwd 'abs_path'; +use File::Basename; +use FindBin; +use lib "$FindBin::Bin/../.."; +use lib "$FindBin::Bin/../../lib"; + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::FlagType; +use Bugzilla::Util; + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 4) { + die <<USAGE; +Usage: movebugs.pl <old-product> <old-component> <new-product> <new-component> + +Eg. movebugs.pl mozilla.org bmo bugzilla.mozilla.org admin +Will move all bugs in the mozilla.org:bmo component to the +bugzilla.mozilla.org:admin component. + +The new product must have matching versions, milestones, and flags from the old +product (will be validated by this script). +USAGE +} + +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 $user_id = $dbh->selectrow_array( + "SELECT userid FROM profiles WHERE login_name='nobody\@mozilla.org'"); +$user_id + or die "Can't find user ID for 'nobody\@mozilla.org'\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 $bug_count = scalar @$ra_ids; +$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"); +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; +} + +# check milestones +my @missing_milestones; +my $ra_milestones = $dbh->selectcol_arrayref( + "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; +} + +# check flags +my @missing_flags; +my $ra_old_types = $dbh->selectcol_arrayref( + "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 }); +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 . ')'; + } +} + +# show missing +my $missing_error = ''; +if (@missing_versions) { + $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"; +} +if (@missing_flags) { + $missing_error .= "'$new_product'::'$new_component' is missing the following flag(s):\n " . + join("\n ", @missing_flags) . "\n"; +} +die $missing_error if $missing_error; + +# confirmation +print <<EOF; +About to move $bug_count bugs +From '$old_product' : '$old_component' +To '$new_product' : '$new_component' + +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"; + +# update bugs +$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"); +$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) + SELECT bug_id, ?, delta_ts, ?, ?, ? FROM bugs WHERE $where_sql", + undef, + $user_id, $product_field_id, $old_product, $new_product); +$dbh->do( + "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); + +$dbh->bz_commit_transaction(); + diff --git a/contrib/reorg-tools/movecomponent.pl b/contrib/reorg-tools/movecomponent.pl new file mode 100755 index 000000000..8f8bc0abc --- /dev/null +++ b/contrib/reorg-tools/movecomponent.pl @@ -0,0 +1,193 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> + +# See also https://bugzilla.mozilla.org/show_bug.cgi?id=119569 +# + +use strict; + +use Cwd 'abs_path'; +use File::Basename; +BEGIN { + my $root = abs_path(dirname(__FILE__) . '/../..'); + chdir($root); +} +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Util; + +sub usage() { + print <<USAGE; +Usage: movecomponent.pl <oldproduct> <newproduct> <component> <doit> + +E.g.: movecomponent.pl ReplicationEngine FoodReplicator SeaMonkey +will move the component "SeaMonkey" from the product "ReplicationEngine" +to the product "FoodReplicator". + +Important: You must make sure the milestones and versions of the bugs in the +component are available in the new product. See syncmsandversions.pl. + +Pass in a true value for "doit" to make the database changes permament. +USAGE + + exit(1); +} + +############################################################################# +# MAIN CODE +############################################################################# + +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 3) { + usage(); + exit(); +} + +my ($oldproduct, $newproduct, $component, $doit) = @ARGV; + +my $dbh = Bugzilla->dbh; + +$dbh->{'AutoCommit'} = 0 unless $doit; # Turn off autocommit by default + +# Find product IDs +my $oldprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $oldproduct); +if (!$oldprodid) { + print "Can't find product ID for '$oldproduct'.\n"; + exit(1); +} + +my $newprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $newproduct); +if (!$newprodid) { + print "Can't find product ID for '$newproduct'.\n"; + exit(1); +} + +# Find component ID +my $compid = $dbh->selectrow_array("SELECT id FROM components + WHERE name = ? AND product_id = ?", + undef, $component, $oldprodid); +if (!$compid) { + print "Can't find component ID for '$component' in product " . + "'$oldproduct'.\n"; + exit(1); +} + +my $fieldid = $dbh->selectrow_array("SELECT id FROM fielddefs + WHERE name = 'product'"); +if (!$fieldid) { + print "Can't find field ID for 'product' field!\n"; + exit(1); +} + +# check versions +my @missing_versions; +my $ra_versions = $dbh->selectcol_arrayref( + "SELECT DISTINCT version FROM bugs WHERE component_id = ?", + undef, $compid); +foreach my $version (@$ra_versions) { + my $has_version = $dbh->selectrow_array( + "SELECT 1 FROM versions WHERE product_id = ? AND value = ?", + undef, $newprodid, $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, $compid); +foreach my $milestone (@$ra_milestones) { + my $has_milestone = $dbh->selectrow_array( + "SELECT 1 FROM milestones WHERE product_id=? AND value=?", + undef, $newprodid, $milestone); + push @missing_milestones, $milestone unless $has_milestone; +} + +my $missing_error = ''; +if (@missing_versions) { + $missing_error .= "'$newproduct' is missing the following version(s):\n " . + join("\n ", @missing_versions) . "\n"; +} +if (@missing_milestones) { + $missing_error .= "'$newproduct' is missing the following milestone(s):\n " . + join("\n ", @missing_milestones) . "\n"; +} +die $missing_error if $missing_error; + +# confirmation +print <<EOF; +About to move the component '$component' +From '$oldproduct' +To '$newproduct' + +Press <Ctrl-C> to stop or <Enter> to continue... +EOF +getc(); + +print "Moving '$component' from '$oldproduct' to '$newproduct'...\n\n"; +$dbh->bz_start_transaction() if $doit; + +# Bugs table +$dbh->do("UPDATE bugs SET product_id = ? WHERE component_id = ?", + undef, + ($newprodid, $compid)); + +# Flags tables +$dbh->do("UPDATE flaginclusions SET product_id = ? WHERE component_id = ?", + undef, + ($newprodid, $compid)); + +$dbh->do("UPDATE flagexclusions SET product_id = ? WHERE component_id = ?", + undef, + ($newprodid, $compid)); + +# Components +$dbh->do("UPDATE components SET product_id = ? WHERE id = ?", + undef, + ($newprodid, $compid)); + +# Mark bugs as touched +$dbh->do("UPDATE bugs SET delta_ts = NOW() + WHERE component_id = ?", undef, $compid); +$dbh->do("UPDATE bugs SET lastdiffed = NOW() + WHERE component_id = ?", undef, $compid); + +# Update bugs_activity +my $userid = 1; # nobody@mozilla.org + +$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, $fieldid, $oldproduct, $newproduct, $compid)); + +$dbh->bz_commit_transaction() if $doit; + +exit(0); + diff --git a/contrib/reorg-tools/reset_default_user.pl b/contrib/reorg-tools/reset_default_user.pl new file mode 100644 index 000000000..42a7998de --- /dev/null +++ b/contrib/reorg-tools/reset_default_user.pl @@ -0,0 +1,143 @@ +#!/usr/bin/perl -wT +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +use strict; + +use lib '.'; + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::User; +use Bugzilla::Field; +use Bugzilla::Util qw(trick_taint); + +use Getopt::Long; + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $dbh = Bugzilla->dbh; + +my $field_name = ""; +my $product = ""; +my $component = ""; +my $help = ""; +my %user_cache = (); + +my $result = GetOptions('field=s' => \$field_name, + 'product=s' => \$product, + 'component=s' => \$component, + 'help|h' => \$help); + +sub 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, +and reset the default user value back to the default value for the component. +Valid field names are assigned_to and qa_contact. +USAGE +} + +if (!$product || $help + || ($field_name ne 'assigned_to' && $field_name ne 'qa_contact')) +{ + usage(); + exit(1); +} + +# We will need these for entering into bugs_activity +my $who = Bugzilla::User->new({ name => 'nobody@mozilla.org' }); +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); +$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); +} + +# build list of bugs +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); +} + +my $bugs = $dbh->selectall_arrayref($bugs_query, {Slice => {}}, @args); +my $bug_count = scalar @$bugs; +$bug_count + or die "No bugs were found.\n"; + +# confirmation +print <<EOF; +About to reset $field_name for $bug_count bugs. + +Press <Ctrl-C> to stop or <Enter> to continue... +EOF +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); + + print "done.\n"; + } +} + +$dbh->bz_commit_transaction(); diff --git a/contrib/reorg-tools/syncflags.pl b/contrib/reorg-tools/syncflags.pl new file mode 100755 index 000000000..6c5b8293a --- /dev/null +++ b/contrib/reorg-tools/syncflags.pl @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> + +# See also https://bugzilla.mozilla.org/show_bug.cgi?id=119569 + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; + +sub usage() { + print <<USAGE; +Usage: syncflags.pl <srcproduct> <tgtproduct> + +E.g.: syncflags.pl FoodReplicator SeaMonkey +will copy any flag inclusions (only) for the product "FoodReplicator" +so matching inclusions exist for the product "SeaMonkey". This script is +normally used prior to moving components from srcproduct to tgtproduct. +USAGE + + exit(1); +} + +############################################################################# +# MAIN CODE +############################################################################# + +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 2) { + usage(); + exit(); +} + +my ($srcproduct, $tgtproduct) = @ARGV; + +my $dbh = Bugzilla->dbh; + +# Find product IDs +my $srcprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $srcproduct); +if (!$srcprodid) { + print "Can't find product ID for '$srcproduct'.\n"; + exit(1); +} + +my $tgtprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $tgtproduct); +if (!$tgtprodid) { + print "Can't find product ID for '$tgtproduct'.\n"; + exit(1); +} + +$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); + +exit(0); diff --git a/contrib/reorg-tools/syncmsandversions.pl b/contrib/reorg-tools/syncmsandversions.pl new file mode 100755 index 000000000..b25b3348b --- /dev/null +++ b/contrib/reorg-tools/syncmsandversions.pl @@ -0,0 +1,107 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> + +# See also https://bugzilla.mozilla.org/show_bug.cgi?id=119569 + +use strict; + +use lib qw(. lib); + +use Bugzilla; +use Bugzilla::Constants; + +sub usage() { + print <<USAGE; +Usage: syncmsandversions.pl <srcproduct> <tgtproduct> + +E.g.: syncmsandversions.pl FoodReplicator SeaMonkey +will copy any versions and milstones in the product "FoodReplicator" +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); +} + +############################################################################# +# MAIN CODE +############################################################################# + +# This is a pure command line script. +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +if (scalar @ARGV < 2) { + usage(); + exit(); +} + +my ($srcproduct, $tgtproduct) = @ARGV; + +my $dbh = Bugzilla->dbh; + +# Find product IDs +my $srcprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $srcproduct); +if (!$srcprodid) { + print "Can't find product ID for '$srcproduct'.\n"; + exit(1); +} + +my $tgtprodid = $dbh->selectrow_array("SELECT id FROM products WHERE name = ?", + undef, $tgtproduct); +if (!$tgtprodid) { + print "Can't find product ID for '$tgtproduct'.\n"; + exit(1); +} + +#$dbh->bz_start_transaction(); + +$dbh->do("INSERT INTO milestones(value, sortkey, product_id) + SELECT m1.value, m1.sortkey, ? FROM milestones m1 + LEFT JOIN milestones m2 ON m1.value = m2.value AND + m2.product_id = ? + WHERE m1.product_id = ? AND m2.value IS NULL", + undef, + $tgtprodid, $tgtprodid, $srcprodid); + +$dbh->do("INSERT INTO versions(value, product_id) + SELECT v1.value, ? FROM versions v1 + LEFT JOIN versions v2 ON v1.value = v2.value AND + v2.product_id = ? + WHERE v1.product_id = ? AND v2.value IS NULL", + undef, + $tgtprodid, $tgtprodid, $srcprodid); + +$dbh->do("INSERT INTO group_control_map (group_id, product_id, entry, membercontrol, othercontrol, canedit, editcomponents, editbugs, canconfirm) + SELECT g1.group_id, ?, g1.entry, g1.membercontrol, g1.othercontrol, g1.canedit, g1.editcomponents, g1.editbugs, g1.canconfirm + FROM group_control_map g1 + LEFT JOIN group_control_map g2 ON g1.product_id = ? AND + g2.product_id = ? AND + g1.group_id = g2.group_id + WHERE g1.product_id = ? AND g2.group_id IS NULL", + undef, + $tgtprodid, $srcprodid, $tgtprodid, $srcprodid); + +#$dbh->bz_commit_transaction(); + +exit(0); + |