Commit 92980fb7 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 311047: populating enum tables fails without localconfig, when upgrading -…

Bug 311047: populating enum tables fails without localconfig, when upgrading - Patch by Nick Barnes <nb+bz@ravenbrook.com> r=mkanat a=justdave
parent 071eabb3
...@@ -773,22 +773,6 @@ my $my_db_name = ${*{$main::{'db_name'}}{SCALAR}}; ...@@ -773,22 +773,6 @@ my $my_db_name = ${*{$main::{'db_name'}}{SCALAR}};
my $my_index_html = ${*{$main::{'index_html'}}{SCALAR}}; my $my_index_html = ${*{$main::{'index_html'}}{SCALAR}};
my $my_create_htaccess = ${*{$main::{'create_htaccess'}}{SCALAR}}; my $my_create_htaccess = ${*{$main::{'create_htaccess'}}{SCALAR}};
my $my_webservergroup = ${*{$main::{'webservergroup'}}{SCALAR}}; my $my_webservergroup = ${*{$main::{'webservergroup'}}{SCALAR}};
# mkanat@bugzilla.org - bug 17453
# The following values have been removed from localconfig.
# However, if we are upgrading from a Bugzilla with enums to a
# Bugzilla without enums, we use these values one more time so
# that we correctly populate the tables.
my @my_severities;
@my_severities = @{*{$main::{'severities'}}{ARRAY}}
if exists($main::{'severities'});
my @my_priorities;
@my_priorities = @{*{$main::{'priorities'}}{ARRAY}}
if exists($main::{'priorities'});
my @my_platforms;
@my_platforms = @{*{$main::{'platforms'}}{ARRAY}}
if exists($main::{'platforms'});
my @my_opsys;
@my_opsys = @{*{$main::{'opsys'}}{ARRAY}} if exists($main::{'opsys'});
if ($my_webservergroup && !$silent) { if ($my_webservergroup && !$silent) {
if ($^O !~ /MSWin32/i) { if ($^O !~ /MSWin32/i) {
...@@ -1809,9 +1793,50 @@ AddFDef($new_field_name, $field_description, 0); ...@@ -1809,9 +1793,50 @@ AddFDef($new_field_name, $field_description, 0);
# Detect changed local settings # Detect changed local settings
########################################################################### ###########################################################################
# mkanat@bugzilla.org - bug 17453 # Nick Barnes nb+bz@ravenbrook.com 2005-10-05
# Create the values for the tables that hold what used to be enum types. #
# Don't populate the tables if the table isn't empty. # GetEnumsValues(\%hash): takes a hash from column names to listrefs
# of values. If any of the columns are enum columns in the 'bugs'
# table, the listrefs are replaced with listrefs of the allowed enum
# values. This is all done in one function because DBD::MySQL
# provides no mechanism for getting type information for a single
# column.
#
# Possibly something like this belongs in Bugzilla/DB/Schema/Mysql.pm.
sub GetEnumsValues {
my ($hashref) = @_;
# Get a complete description of the 'bugs' table; with DBD::MySQL
# there isn't a column-by-column way of doing this. Could use
# $dbh->column_info, but it would go slower and we would have to
# use the undocumented mysql_type_name accessor to get the type
# of each row.
my $sth = $dbh->prepare("DESCRIBE bugs");
$sth->execute();
# Look for the particular columns we are interested in.
while (my ($thiscol, $thistype) = ($sth->fetchrow_array())) {
if (defined($$hashref{$thiscol})) {
# this is a column of interest.
my @value_list = ();
if ($thistype && ($thistype =~ /^enum\(/)) {
# it has an enum type; get the set of values.
while ($thistype =~ /'([^']*)'(.*)/) {
push(@value_list, $1);
$thistype = $2;
}
}
if (@value_list) {
# record the enum values found.
$$hashref{$thiscol} = \@value_list;
}
}
}
}
# PopulateEnumTable($table, @values): if the table $table has no
# entries, fill it with the entries in the list @values, in the same
# order as that list.
sub PopulateEnumTable { sub PopulateEnumTable {
my ($table, @valuelist) = @_; my ($table, @valuelist) = @_;
...@@ -1840,37 +1865,40 @@ sub PopulateEnumTable { ...@@ -1840,37 +1865,40 @@ sub PopulateEnumTable {
} }
} }
# mkanat@bugzilla.org - bug 17453 # Set default values for what used to be the enum types. These values
# Set default values for what used to be the enum types. # are no longer stored in localconfig. If we are upgrading from a
# These values are no longer stored in localconfig. # Bugzilla with enums to a Bugzilla without enums, we use the
# However, if we are upgrading from a Bugzilla with enums to a # enum values.
# Bugzilla without enums, we use the localconfig values one more time. #
# The values that you see here are ONLY DEFAULTS. They are only used # The values that you see here are ONLY DEFAULTS. They are only used
# the FIRST time you run checksetup. After that, they are either # the FIRST time you run checksetup, IF you are NOT upgrading from a
# controlled through the Bugzilla UI or through the DB. # Bugzilla with enums. After that, they are either controlled through
@my_severities = ('blocker','critical','major','normal','minor', # the Bugzilla UI or through the DB.
'trivial','enhancement') if !@my_severities;
@my_priorities = ("P1","P2","P3","P4","P5") if !@my_priorities; my %enum_values = (bug_severity =>
@my_opsys = ("All","Windows","Mac OS","Linux","Other") if !@my_opsys; ['blocker', 'critical', 'major', 'normal',
@my_platforms = ("All","PC","Macintosh","Other") if !@my_platforms; 'minor', 'trivial', 'enhancement'],
priority =>
PopulateEnumTable('bug_severity', @my_severities); ["P1","P2","P3","P4","P5"],
PopulateEnumTable('priority', @my_priorities); op_sys =>
PopulateEnumTable('op_sys', @my_opsys); ["All","Windows","Mac OS","Linux","Other"],
PopulateEnumTable('rep_platform', @my_platforms); rep_platform =>
["All","PC","Macintosh","Other"],
# The resolution and bug_status lists are absolute. On an upgrade from bug_status =>
# a Bugzilla with enums, whatever is in the enum will be replaced with ["UNCONFIRMED","NEW","ASSIGNED","REOPENED","RESOLVED",
# this. This is because Bugzilla depends on the exact names of these "VERIFIED","CLOSED"],
# resolutions in order to function properly. resolution =>
my @states = ("UNCONFIRMED","NEW","ASSIGNED","REOPENED","RESOLVED", ["","FIXED","INVALID","WONTFIX","LATER","REMIND",
"VERIFIED","CLOSED"); "DUPLICATE","WORKSFORME","MOVED"]);
my @resolutions = ("","FIXED","INVALID","WONTFIX","LATER","REMIND",
"DUPLICATE","WORKSFORME","MOVED"); # Get all the enum column values for the existing database, or the
PopulateEnumTable('bug_status', @states); # defaults if the columns are not enums.
PopulateEnumTable('resolution', @resolutions); GetEnumsValues(\%enum_values);
# Populate the enum tables.
while (my ($table, $values) = each %enum_values) {
PopulateEnumTable($table, @$values);
}
########################################################################### ###########################################################################
# Create initial test product if there are no products present. # Create initial test product if there are no products present.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment