RSS

(root)/bugzilla/4.2 : 7271 : contrib/convert-workflow.pl

To get this branch, use:
bzr branch /bugzilla/4.2

« back to all changes in this revision

Viewing changes to contrib/convert-workflow.pl

Max Kanat-Alexander
2010-07-05 17:42:57
Revision ID: mkanat@bugzilla.org-20100706004257-9wg4e8f3s52lbqhi
Bug 486292: Change the default workflow to UNCONFIRMED, CONFIRMED,
IN_PROGRESS, RESOLVED, VERIFIED.
r=LpSolit, a=mkanat

Show diffs side-by-side

added added

removed removed

 
1
#!/usr/bin/perl -w
 
2
#
 
3
# The contents of this file are subject to the Mozilla Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/MPL/
 
7
#
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
#
 
13
# The Original Code is the Bugzilla Bug Tracking System.
 
14
#
 
15
# The Initial Developer of the Original Code is Everything Solved, Inc.
 
16
# Portions created by the Initial Developer are Copyright (C) 2009 the
 
17
# Initial Developer. All Rights Reserved.
 
18
#
 
19
# Contributor(s):
 
20
#   Max Kanat-Alexander <mkanat@bugzilla.org>
 
21
 
 
22
use strict;
 
23
use warnings;
 
24
use lib qw(. lib);
 
25
 
 
26
use Bugzilla;
 
27
use Bugzilla::Config qw(:admin);
 
28
use Bugzilla::Status;
 
29
 
 
30
my $confirmed   = new Bugzilla::Status({ name => 'CONFIRMED' });
 
31
my $in_progress = new Bugzilla::Status({ name => 'IN_PROGRESS' });
 
32
 
 
33
if ($confirmed and $in_progress) {
 
34
    print "You are already using the new workflow.\n";
 
35
    exit 1;
 
36
}
 
37
 
 
38
print <<END;
 
39
WARNING: This will convert the status of all bugs using the following
 
40
system:
 
41
 
 
42
  "NEW" will become "CONFIRMED"
 
43
  "ASSIGNED" will become "IN_PROGRESS"
 
44
  "REOPENED" will become "CONFIRMED" (and the "REOPENED" status will be removed)
 
45
  "CLOSED" will become "VERIFIED" (and the "CLOSED" status will be removed)
 
46
 
 
47
This change will be immediate. The history of each bug will also be changed
 
48
so that it appears that these statuses were always in existence.
 
49
 
 
50
Emails will not be sent for the change.
 
51
 
 
52
To continue, press any key, or press Ctrl-C to stop this program...
 
53
END
 
54
getc;
 
55
 
 
56
my $dbh = Bugzilla->dbh;
 
57
my %translation = (
 
58
    NEW      => 'CONFIRMED',
 
59
    ASSIGNED => 'IN_PROGRESS',
 
60
    REOPENED => 'CONFIRMED',
 
61
    CLOSED   => 'VERIFIED',
 
62
);
 
63
 
 
64
my $status_field = Bugzilla::Field->check('bug_status');
 
65
$dbh->bz_start_transaction();
 
66
while (my ($from, $to) = each %translation) {
 
67
    print "Converting $from to $to...\n";
 
68
    $dbh->do('UPDATE bugs SET bug_status = ? WHERE bug_status = ?',
 
69
             undef, $to, $from);
 
70
 
 
71
    if (Bugzilla->params->{'duplicate_or_move_bug_status'} eq $from) {
 
72
        SetParam('duplicate_or_move_bug_status', $to);
 
73
        write_params();
 
74
    }
 
75
 
 
76
    foreach my $what (qw(added removed)) {
 
77
        $dbh->do("UPDATE bugs_activity SET $what = ? 
 
78
                   WHERE fieldid = ? AND $what = ?",
 
79
                 undef, $to, $status_field->id, $from);
 
80
    }
 
81
 
 
82
    # Delete any transitions where it now appears that
 
83
    # a bug moved from a status to itself.
 
84
    $dbh->do('DELETE FROM bugs_activity WHERE fieldid = ? AND added = removed',
 
85
             undef, $status_field->id);
 
86
 
 
87
    # If the new status already exists, just delete the old one, but retain
 
88
    # the workflow items from it.
 
89
    if (my $existing = new Bugzilla::Status({ name => $to })) {
 
90
        $dbh->do('DELETE FROM bug_status WHERE value = ?', undef, $from);
 
91
    }
 
92
    # Otherwise, rename the old status to the new one.
 
93
    else {
 
94
        $dbh->do('UPDATE bug_status SET value = ? WHERE value = ?',
 
95
                 undef, $to, $from);
 
96
    }
 
97
}
 
98
 
 
99
$dbh->bz_commit_transaction();
 
100
 
 
101
print <<END;
 
102
Done. There are some things you may want to fix, now:
 
103
 
 
104
  * You may want to run ./collectstats.pl --regenerate to regenerate
 
105
    data for the Old Charts system. 
 
106
  * You may have to fix the Status Workflow using the Status Workflow
 
107
    panel in "Administration".
 
108
  * You will probably want to update the "mybugstemplate" and "defaultquery"
 
109
    parameters using the Parameters panel in "Administration". (Just
 
110
    resetting them to the default will work.)
 
111
END

Loggerhead 1.18.1 is a web-based interface for Bazaar branches