Commit e92cc4c9 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 17453: Enumerators in Bugzilla are not cross-DB compatible. This removes all…

Bug 17453: Enumerators in Bugzilla are not cross-DB compatible. This removes all 'enum' types in the database from Bugzilla. Patch By Max Kanat-Alexander <mkanat@kerio.com> r=joel, a=justdave
parent 80c0cdba
...@@ -50,14 +50,26 @@ use Date::Parse; ...@@ -50,14 +50,26 @@ use Date::Parse;
# Each field points to an array that contains the fields mapped # Each field points to an array that contains the fields mapped
# to, in order. # to, in order.
our %specialorder = ( our %specialorder = (
'bugs.target_milestone' => [ 'ms_order.sortkey','ms_order.value' ] 'bugs.target_milestone' => [ 'ms_order.sortkey','ms_order.value' ],
'bugs.bug_status' => [ 'bug_status.sortkey','bug_status.value' ],
'bugs.rep_platform' => [ 'rep_platform.sortkey','rep_platform.value' ],
'bugs.priority' => [ 'priority.sortkey','priority.value' ],
'bugs.op_sys' => [ 'op_sys.sortkey','op_sys.value' ],
'bugs.resolution' => [ 'resolution.sortkey', 'resolution.value' ],
'bugs.bug_severity' => [ 'bug_severity.sortkey','bug_severity.value' ]
); );
# When we add certain fields to the ORDER BY, we need to then add a # When we add certain fields to the ORDER BY, we need to then add a
# table join to the FROM statement. This hash maps input fields to # table join to the FROM statement. This hash maps input fields to
# the join statements that ned to be added. # the join statements that ned to be added.
our %specialorderjoin = ( our %specialorderjoin = (
'bugs.target_milestone' => 'LEFT JOIN milestones AS ms_order ON ms_order.value = bugs.target_milestone AND ms_order.product_id = bugs.product_id' 'bugs.target_milestone' => 'LEFT JOIN milestones AS ms_order ON ms_order.value = bugs.target_milestone AND ms_order.product_id = bugs.product_id',
'bugs.bug_status' => 'LEFT JOIN bug_status ON bug_status.value = bugs.bug_status',
'bugs.rep_platform' => 'LEFT JOIN rep_platform ON rep_platform.value = bugs.rep_platform',
'bugs.priority' => 'LEFT JOIN priority ON priority.value = bugs.priority',
'bugs.op_sys' => 'LEFT JOIN op_sys ON op_sys.value = bugs.op_sys',
'bugs.resolution' => 'LEFT JOIN resolution ON resolution.value = bugs.resolution',
'bugs.bug_severity' => 'LEFT JOIN bug_severity ON bug_severity.value = bugs.bug_severity'
); );
# Create a new Search # Create a new Search
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
# Jacob Steenhagen <jake@bugzilla.org> # Jacob Steenhagen <jake@bugzilla.org>
# Bradley Baetz <bbaetz@student.usyd.edu.au> # Bradley Baetz <bbaetz@student.usyd.edu.au>
# Christopher Aillon <christopher@aillon.com> # Christopher Aillon <christopher@aillon.com>
# Joel Peshkin <bugreport@peshkin.net> # Joel Peshkin <bugreport@peshkin.net>
# Dave Lawrence <dkl@redhat.com>
# Max Kanat-Alexander <mkanat@kerio.com>
# Contains some global variables and routines used throughout bugzilla. # Contains some global variables and routines used throughout bugzilla.
...@@ -225,12 +227,12 @@ sub GenerateVersionTable { ...@@ -225,12 +227,12 @@ sub GenerateVersionTable {
} }
@::log_columns = (sort(@::log_columns)); @::log_columns = (sort(@::log_columns));
@::legal_priority = SplitEnumType($cols->{"priority,type"}); @::legal_priority = get_legal_field_values("priority");
@::legal_severity = SplitEnumType($cols->{"bug_severity,type"}); @::legal_severity = get_legal_field_values("bug_severity");
@::legal_platform = SplitEnumType($cols->{"rep_platform,type"}); @::legal_platform = get_legal_field_values("rep_platform");
@::legal_opsys = SplitEnumType($cols->{"op_sys,type"}); @::legal_opsys = get_legal_field_values("op_sys");
@::legal_bug_status = SplitEnumType($cols->{"bug_status,type"}); @::legal_bug_status = get_legal_field_values("bug_status");
@::legal_resolution = SplitEnumType($cols->{"resolution,type"}); @::legal_resolution = get_legal_field_values("resolution");
# 'settable_resolution' is the list of resolutions that may be set # 'settable_resolution' is the list of resolutions that may be set
# directly by hand in the bug form. Start with the list of legal # directly by hand in the bug form. Start with the list of legal
...@@ -1026,22 +1028,13 @@ sub LearnAboutColumns { ...@@ -1026,22 +1028,13 @@ sub LearnAboutColumns {
return \%a; return \%a;
} }
# Returns a list of all the legal values for a field that has a
# list of legal values, like rep_platform or resolution.
# If the above returned a enum type, take that type and parse it into the sub get_legal_field_values {
# list of values. Assumes that enums don't ever contain an apostrophe! my ($field) = @_;
my $dbh = Bugzilla->dbh;
sub SplitEnumType { my $result_ref = $dbh->selectcol_arrayref("SELECT value FROM $field");
my ($str) = (@_); return @$result_ref;
my @result = ();
if ($str =~ /^enum\((.*)\)$/) {
my $guts = $1 . ",";
while ($guts =~ /^\'([^\']*)\',(.*)$/) {
push @result, $1;
$guts = $2;
}
}
return @result;
} }
sub UserInGroup { sub UserInGroup {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# #
# Contributor(s): Terry Weissman <terry@mozilla.org> # Contributor(s): Terry Weissman <terry@mozilla.org>
# Matthew Tuck <matty@chariot.net.au> # Matthew Tuck <matty@chariot.net.au>
# Max Kanat-Alexander <mkanat@kerio.com>
use strict; use strict;
...@@ -200,29 +201,6 @@ if (defined $cgi->param('rescanallBugMail')) { ...@@ -200,29 +201,6 @@ if (defined $cgi->param('rescanallBugMail')) {
print "OK, now running sanity checks.<p>\n"; print "OK, now running sanity checks.<p>\n";
########################################################################### ###########################################################################
# Check enumeration values
###########################################################################
# This one goes first, because if this is wrong, then the below tests
# will probably fail too
# This isn't extensible. Thats OK; we're not adding any more enum fields
Status("Checking for invalid enumeration values");
foreach my $field (("bug_severity", "bug_status", "op_sys",
"priority", "rep_platform", "resolution")) {
# undefined enum values in mysql are an empty string which equals 0
SendSQL("SELECT bug_id FROM bugs WHERE $field=0 ORDER BY bug_id");
my @invalid;
while (MoreSQLData()) {
push (@invalid, FetchOneColumn());
}
if (@invalid) {
Alert("Bug(s) found with invalid $field value: ".
BugListLinks(@invalid));
}
}
###########################################################################
# Perform referential (cross) checks # Perform referential (cross) checks
########################################################################### ###########################################################################
...@@ -352,6 +330,25 @@ CrossCheck("products", "id", ...@@ -352,6 +330,25 @@ CrossCheck("products", "id",
["flaginclusions", "product_id", "type_id"], ["flaginclusions", "product_id", "type_id"],
["flagexclusions", "product_id", "type_id"]); ["flagexclusions", "product_id", "type_id"]);
# Check the former enum types -mkanat@kerio.com
CrossCheck("bug_status", "value",
["bugs", "bug_status"]);
CrossCheck("resolution", "value",
["bugs", "resolution"]);
CrossCheck("bug_severity", "value",
["bugs", "bug_severity"]);
CrossCheck("op_sys", "value",
["bugs", "op_sys"]);
CrossCheck("priority", "value",
["bugs", "priority"]);
CrossCheck("rep_platform", "value",
["bugs", "rep_platform"]);
CrossCheck('series', 'series_id', CrossCheck('series', 'series_id',
['series_data', 'series_id']); ['series_data', 'series_id']);
......
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