From 782a89bc8bd905fa5ac3532c984ad2b4b149e8fd Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Fri, 30 Dec 2005 06:27:25 +0000 Subject: Bug 311047: populating enum tables fails without localconfig, when upgrading Patch By Max Kanat-Alexander and Nick Barnes r=mkanat, r=LpSolit, a=justdave --- Bugzilla/DB.pm | 27 +++++++++++++++++++++++++++ Bugzilla/DB/Mysql.pm | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'Bugzilla') 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 + + 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 ##################################################################### -- cgit v1.2.3-24-g4f1b