summaryrefslogtreecommitdiffstats
path: root/scripts/reset_default_user.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/reset_default_user.pl')
-rwxr-xr-xscripts/reset_default_user.pl145
1 files changed, 76 insertions, 69 deletions
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();