summaryrefslogtreecommitdiffstats
path: root/scripts/move_flag_types.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/move_flag_types.pl')
-rwxr-xr-xscripts/move_flag_types.pl103
1 files changed, 57 insertions, 46 deletions
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";
}