summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/DB.pm27
-rw-r--r--Bugzilla/DB/Mysql.pm32
-rwxr-xr-xchecksetup.pl84
3 files changed, 94 insertions, 49 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 1da845942..a36ca909d 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -336,6 +336,13 @@ sub bz_setup_database {
}
}
+# The defauly implementation just returns what you passed-in. This function
+# really exists just to be overridden in Bugzilla::DB::Mysql.
+sub bz_enum_initial_values {
+ my ($self, $enum_defaults) = @_;
+ return $enum_defaults;
+}
+
#####################################################################
# Schema Modification Methods
#####################################################################
@@ -1283,6 +1290,26 @@ These methods return information about data in the database.
=back
+=head2 Database Setup Methods
+
+These methods are used by the Bugzilla installation programs to set up
+the database.
+
+=over 4
+
+=item C<bz_enum_initial_values(\%enum_defaults)>
+
+ Description: For an upgrade or an initial installation, provides
+ what the values should be for the "enum"-type fields,
+ such as version, op_sys, rep_platform, etc.
+ Params: \%enum_defaults - The default initial list of values for
+ each enum field. A hash, with the field
+ names pointing to an arrayref of values.
+ Returns: A hashref with the correct initial values for the enum fields.
+
+=back
+
+
=head2 Schema Modification Methods
These methods modify the current Bugzilla Schema.
diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm
index e2e0e840f..e03fbc910 100644
--- a/Bugzilla/DB/Mysql.pm
+++ b/Bugzilla/DB/Mysql.pm
@@ -540,6 +540,38 @@ sub bz_setup_database {
}
+sub bz_enum_initial_values {
+ my ($self, $enum_defaults) = @_;
+ my %enum_values = %$enum_defaults;
+ # 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 = $self->prepare("DESCRIBE bugs");
+ $sth->execute();
+ # Look for the particular columns we are interested in.
+ while (my ($thiscol, $thistype) = $sth->fetchrow_array()) {
+ if (defined $enum_values{$thiscol}) {
+ # this is a column of interest.
+ my @value_list;
+ if ($thistype and ($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.
+ $enum_values{$thiscol} = \@value_list;
+ }
+ }
+ }
+
+ return \%enum_values;
+}
+
#####################################################################
# MySQL-specific Database-Reading Methods
#####################################################################
diff --git a/checksetup.pl b/checksetup.pl
index e21600ebf..a7ebd953c 100755
--- a/checksetup.pl
+++ b/checksetup.pl
@@ -773,22 +773,6 @@ my $my_db_name = ${*{$main::{'db_name'}}{SCALAR}};
my $my_index_html = ${*{$main::{'index_html'}}{SCALAR}};
my $my_create_htaccess = ${*{$main::{'create_htaccess'}}{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 ($^O !~ /MSWin32/i) {
@@ -1809,9 +1793,12 @@ AddFDef($new_field_name, $field_description, 0);
# Detect changed local settings
###########################################################################
-# mkanat@bugzilla.org - bug 17453
-# 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.
+# Nick Barnes nb+bz@ravenbrook.com 2005-10-05
+#
+# 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 {
my ($table, @valuelist) = @_;
@@ -1840,37 +1827,36 @@ sub PopulateEnumTable {
}
}
-# mkanat@bugzilla.org - bug 17453
-# Set default values for what used to be the enum types.
-# These values are no longer stored in localconfig.
-# However, if we are upgrading from a Bugzilla with enums to a
-# Bugzilla without enums, we use the localconfig values one more time.
-
+# Set default values for what used to be the enum types. These values
+# are no longer stored in localconfig. If we are upgrading from a
+# Bugzilla with enums to a Bugzilla without enums, we use the
+# enum values.
+#
# The values that you see here are ONLY DEFAULTS. They are only used
-# the FIRST time you run checksetup. After that, they are either
-# controlled through the Bugzilla UI or through the DB.
-@my_severities = ('blocker','critical','major','normal','minor',
- 'trivial','enhancement') if !@my_severities;
-@my_priorities = ("P1","P2","P3","P4","P5") if !@my_priorities;
-@my_opsys = ("All","Windows","Mac OS","Linux","Other") if !@my_opsys;
-@my_platforms = ("All","PC","Macintosh","Other") if !@my_platforms;
-
-PopulateEnumTable('bug_severity', @my_severities);
-PopulateEnumTable('priority', @my_priorities);
-PopulateEnumTable('op_sys', @my_opsys);
-PopulateEnumTable('rep_platform', @my_platforms);
-
-# The resolution and bug_status lists are absolute. On an upgrade from
-# a Bugzilla with enums, whatever is in the enum will be replaced with
-# this. This is because Bugzilla depends on the exact names of these
-# resolutions in order to function properly.
-my @states = ("UNCONFIRMED","NEW","ASSIGNED","REOPENED","RESOLVED",
- "VERIFIED","CLOSED");
-my @resolutions = ("","FIXED","INVALID","WONTFIX","LATER","REMIND",
- "DUPLICATE","WORKSFORME","MOVED");
-PopulateEnumTable('bug_status', @states);
-PopulateEnumTable('resolution', @resolutions);
-
+# the FIRST time you run checksetup, IF you are NOT upgrading from a
+# Bugzilla with enums. After that, they are either controlled through
+# the Bugzilla UI or through the DB.
+
+my $enum_defaults = {
+ bug_severity => ['blocker', 'critical', 'major', 'normal',
+ 'minor', 'trivial', 'enhancement'],
+ priority => ["P1","P2","P3","P4","P5"],
+ op_sys => ["All","Windows","Mac OS","Linux","Other"],
+ rep_platform => ["All","PC","Macintosh","Other"],
+ bug_status => ["UNCONFIRMED","NEW","ASSIGNED","REOPENED","RESOLVED",
+ "VERIFIED","CLOSED"],
+ resolution => ["","FIXED","INVALID","WONTFIX","LATER","REMIND",
+ "DUPLICATE","WORKSFORME","MOVED"],
+};
+
+# Get all the enum column values for the existing database, or the
+# defaults if the columns are not enums.
+my $enum_values = $dbh->bz_enum_initial_values($enum_defaults);
+
+# Populate the enum tables.
+while (my ($table, $values) = each %$enum_values) {
+ PopulateEnumTable($table, @$values);
+}
###########################################################################
# Create initial test product if there are no products present.