@@ -2783,85 +2783,102 @@ sub _initialize_workflow {
27832783 my $old_params = shift ;
27842784 my $dbh = Bugzilla-> dbh;
27852785
2786- if (!$dbh -> bz_column_info(' bug_status' , ' is_open' )) {
2787- $dbh -> bz_add_column(' bug_status' , ' is_open' ,
2788- {TYPE => ' BOOLEAN' , NOTNULL => 1, DEFAULT => ' TRUE' });
2789-
2790- # Till now, bug statuses were not customizable. Nevertheless, local
2791- # changes are possible and so we will try to respect these changes.
2792- # This means: get the status of bugs having a resolution different from ''
2793- # and mark these statuses as 'closed', even if some of these statuses are
2794- # expected to be open statuses. Bug statuses we have no information about
2795- # are left as 'open'.
2796- my @statuses =
2797- @{$dbh -> selectcol_arrayref(' SELECT DISTINCT bug_status FROM bugs
2798- WHERE resolution != ?' , undef , ' ' )};
2786+ $dbh -> bz_add_column(' bug_status' , ' is_open' ,
2787+ {TYPE => ' BOOLEAN' , NOTNULL => 1, DEFAULT => ' TRUE' });
27992788
2800- # Append the default list of closed statuses. Duplicated statuses don't hurt.
2801- @statuses = map {$dbh -> quote($_ )} (@statuses , qw( RESOLVED VERIFIED CLOSED) );
2789+ # Till now, bug statuses were not customizable. Nevertheless, local
2790+ # changes are possible and so we will try to respect these changes.
2791+ # This means: get the status of bugs having a resolution different from ''
2792+ # and mark these statuses as 'closed', even if some of these statuses are
2793+ # expected to be open statuses. Bug statuses we have no information about
2794+ # are left as 'open'.
2795+ my @closed_statuses =
2796+ @{$dbh -> selectcol_arrayref(' SELECT DISTINCT bug_status FROM bugs
2797+ WHERE resolution != ?' , undef , ' ' )};
2798+
2799+ # Append the default list of closed statuses *unless* we detect at least
2800+ # one closed state in the DB (i.e. with is_open = 0). This would mean that
2801+ # the DB has already been updated at least once and maybe the admin decided
2802+ # that e.g. 'RESOLVED' is now an open state, in which case we don't want to
2803+ # override this attribute. At least one bug status has to be a closed state
2804+ # anyway (due to the 'duplicate_or_move_bug_status' parameter) so it's safe
2805+ # to use this criteria.
2806+ my $num_closed_states = $dbh -> selectrow_array(' SELECT COUNT(*) FROM bug_status
2807+ WHERE is_open = 0' );
2808+
2809+ if (!$num_closed_states ) {
2810+ @closed_statuses =
2811+ map {$dbh -> quote($_ )} (@closed_statuses , qw( RESOLVED VERIFIED CLOSED) );
28022812
28032813 print " Marking closed bug statuses as such...\n " ;
28042814 $dbh -> do(' UPDATE bug_status SET is_open = 0 WHERE value IN (' .
2805- join (' , ' , @statuses ) . ' )' );
2815+ join (' , ' , @closed_statuses ) . ' )' );
28062816 }
28072817
28082818 # Populate the status_workflow table. We do nothing if the table already
28092819 # has entries. If all bug status transitions have been deleted, the
28102820 # workflow will be restored to its default schema.
28112821 my $count = $dbh -> selectrow_array(' SELECT COUNT(*) FROM status_workflow' );
2812- return if $count ;
2813-
2814- my $create = $old_params -> {' commentoncreate' };
2815- my $confirm = $old_params -> {' commentonconfirm' };
2816- my $accept = $old_params -> {' commentonaccept' };
2817- my $resolve = $old_params -> {' commentonresolve' };
2818- my $verify = $old_params -> {' commentonverify' };
2819- my $close = $old_params -> {' commentonclose' };
2820- my $reopen = $old_params -> {' commentonreopen' };
2821- # This was till recently the only way to get back to NEW for
2822- # confirmed bugs, so we use this parameter here.
2823- my $reassign = $old_params -> {' commentonreassign' };
2824-
2825- # This is the default workflow.
2826- my @workflow = ([undef , ' UNCONFIRMED' , $create ],
2827- [undef , ' NEW' , $create ],
2828- [undef , ' ASSIGNED' , $create ],
2829- [' UNCONFIRMED' , ' NEW' , $confirm ],
2830- [' UNCONFIRMED' , ' ASSIGNED' , $accept ],
2831- [' UNCONFIRMED' , ' RESOLVED' , $resolve ],
2832- [' NEW' , ' ASSIGNED' , $accept ],
2833- [' NEW' , ' RESOLVED' , $resolve ],
2834- [' ASSIGNED' , ' NEW' , $reassign ],
2835- [' ASSIGNED' , ' RESOLVED' , $resolve ],
2836- [' REOPENED' , ' NEW' , $reassign ],
2837- [' REOPENED' , ' ASSIGNED' , $accept ],
2838- [' REOPENED' , ' RESOLVED' , $resolve ],
2839- [' RESOLVED' , ' UNCONFIRMED' , $reopen ],
2840- [' RESOLVED' , ' REOPENED' , $reopen ],
2841- [' RESOLVED' , ' VERIFIED' , $verify ],
2842- [' RESOLVED' , ' CLOSED' , $close ],
2843- [' VERIFIED' , ' UNCONFIRMED' , $reopen ],
2844- [' VERIFIED' , ' REOPENED' , $reopen ],
2845- [' VERIFIED' , ' CLOSED' , $close ],
2846- [' CLOSED' , ' UNCONFIRMED' , $reopen ],
2847- [' CLOSED' , ' REOPENED' , $reopen ]);
2848-
2849- print " Now filling the 'status_workflow' table with valid bug status transitions...\n " ;
2850- my $sth_select = $dbh -> prepare(' SELECT id FROM bug_status WHERE value = ?' );
2851- my $sth = $dbh -> prepare(' INSERT INTO status_workflow (old_status, new_status,
2852- require_comment) VALUES (?, ?, ?)' );
2853-
2854- foreach my $transition (@workflow ) {
2855- my ($from , $to );
2856- # If it's an initial state, there is no "old" value.
2857- $from = $dbh -> selectrow_array($sth_select , undef , $transition -> [0])
2858- if $transition -> [0];
2859- $to = $dbh -> selectrow_array($sth_select , undef , $transition -> [1]);
2860- # If one of the bug statuses doesn't exist, the transition is invalid.
2861- next if (($transition -> [0] && !$from ) || !$to );
2862-
2863- $sth -> execute($from , $to , $transition -> [2] ? 1 : 0);
2822+
2823+ if (!$count ) {
2824+ # Make sure the variables below are defined as
2825+ # status_workflow.require_comment cannot be NULL.
2826+ my $create = $old_params -> {' commentoncreate' } || 0;
2827+ my $confirm = $old_params -> {' commentonconfirm' } || 0;
2828+ my $accept = $old_params -> {' commentonaccept' } || 0;
2829+ my $resolve = $old_params -> {' commentonresolve' } || 0;
2830+ my $verify = $old_params -> {' commentonverify' } || 0;
2831+ my $close = $old_params -> {' commentonclose' } || 0;
2832+ my $reopen = $old_params -> {' commentonreopen' } || 0;
2833+ # This was till recently the only way to get back to NEW for
2834+ # confirmed bugs, so we use this parameter here.
2835+ my $reassign = $old_params -> {' commentonreassign' } || 0;
2836+
2837+ # This is the default workflow.
2838+ my @workflow = ([undef , ' UNCONFIRMED' , $create ],
2839+ [undef , ' NEW' , $create ],
2840+ [undef , ' ASSIGNED' , $create ],
2841+ [' UNCONFIRMED' , ' NEW' , $confirm ],
2842+ [' UNCONFIRMED' , ' ASSIGNED' , $accept ],
2843+ [' UNCONFIRMED' , ' RESOLVED' , $resolve ],
2844+ [' NEW' , ' ASSIGNED' , $accept ],
2845+ [' NEW' , ' RESOLVED' , $resolve ],
2846+ [' ASSIGNED' , ' NEW' , $reassign ],
2847+ [' ASSIGNED' , ' RESOLVED' , $resolve ],
2848+ [' REOPENED' , ' NEW' , $reassign ],
2849+ [' REOPENED' , ' ASSIGNED' , $accept ],
2850+ [' REOPENED' , ' RESOLVED' , $resolve ],
2851+ [' RESOLVED' , ' UNCONFIRMED' , $reopen ],
2852+ [' RESOLVED' , ' REOPENED' , $reopen ],
2853+ [' RESOLVED' , ' VERIFIED' , $verify ],
2854+ [' RESOLVED' , ' CLOSED' , $close ],
2855+ [' VERIFIED' , ' UNCONFIRMED' , $reopen ],
2856+ [' VERIFIED' , ' REOPENED' , $reopen ],
2857+ [' VERIFIED' , ' CLOSED' , $close ],
2858+ [' CLOSED' , ' UNCONFIRMED' , $reopen ],
2859+ [' CLOSED' , ' REOPENED' , $reopen ]);
2860+
2861+ print " Now filling the 'status_workflow' table with valid bug status transitions...\n " ;
2862+ my $sth_select = $dbh -> prepare(' SELECT id FROM bug_status WHERE value = ?' );
2863+ my $sth = $dbh -> prepare(' INSERT INTO status_workflow (old_status, new_status,
2864+ require_comment) VALUES (?, ?, ?)' );
2865+
2866+ foreach my $transition (@workflow ) {
2867+ my ($from , $to );
2868+ # If it's an initial state, there is no "old" value.
2869+ $from = $dbh -> selectrow_array($sth_select , undef , $transition -> [0])
2870+ if $transition -> [0];
2871+ $to = $dbh -> selectrow_array($sth_select , undef , $transition -> [1]);
2872+ # If one of the bug statuses doesn't exist, the transition is invalid.
2873+ next if (($transition -> [0] && !$from ) || !$to );
2874+
2875+ $sth -> execute($from , $to , $transition -> [2] ? 1 : 0);
2876+ }
28642877 }
2878+
2879+ # Make sure the bug status used by the 'duplicate_or_move_bug_status'
2880+ # parameter has all the required transitions set.
2881+ Bugzilla::Status::add_missing_bug_status_transitions();
28652882}
28662883
286728841;
0 commit comments