summaryrefslogtreecommitdiffstats
path: root/scripts/movecomponent.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/movecomponent.pl')
-rwxr-xr-xscripts/movecomponent.pl124
1 files changed, 70 insertions, 54 deletions
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));
+ }
}