From 0e11b4a741c9104db967a2c51fa77b071cb087f5 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 14 Oct 2015 15:53:48 +0000 Subject: Bug 1195952 - Please add the following choices to the CAB review drop down area of bugzilla --- scripts/migrate-cab-review.pl | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 scripts/migrate-cab-review.pl (limited to 'scripts') diff --git a/scripts/migrate-cab-review.pl b/scripts/migrate-cab-review.pl new file mode 100755 index 000000000..2d6a0c209 --- /dev/null +++ b/scripts/migrate-cab-review.pl @@ -0,0 +1,102 @@ +#!/usr/bin/perl + +# 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 warnings; + +use FindBin qw($RealBin); +use lib "$RealBin/../../.."; + +use Bugzilla; +use Bugzilla::Bug; +use Bugzilla::Constants; +use Bugzilla::Field; +use Bugzilla::Group; +use Bugzilla::Install::Util qw(indicate_progress); +use Bugzilla::User; + +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 ]; +Bugzilla->set_user($auto_user); + +# cab-review flag values to custom field values mapping +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' }); +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"; + } +} + +# Grab list of bugs with cab-review flag set +my $sql = <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 "Press to start, or ^C to cancel...\n"; +<>; + +foreach my $bug_id (@$bugs) { + indicate_progress({ current => $current++, total => $total, every => 5 }); + + # 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; + } + + my $timestamp = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + + $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}); + + # Clear the old cab-review flag + $bug->set_flags([{ id => $cab_flag->id, status => 'X' }], []); + + # 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); + + $dbh->bz_commit_transaction; + $updated++; +} + +print "Bugs updated: $updated\n"; -- cgit v1.2.3-24-g4f1b