From a67c69cb3b6df3064a91aca86eccea43af190d12 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sat, 5 Jan 2008 02:15:57 +0000 Subject: Bug 410823: Bugzilla fails when editing or deleting a multi-select field value - Patch by Ronaldo Maia r/a=LpSolit --- editvalues.cgi | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'editvalues.cgi') diff --git a/editvalues.cgi b/editvalues.cgi index 9be6b5440..9408acd80 100755 --- a/editvalues.cgi +++ b/editvalues.cgi @@ -165,7 +165,8 @@ unless ($field) { } # At this point, the field is defined. -$vars->{'field'} = FieldMustExist($field); +my $field_obj = FieldMustExist($field); +$vars->{'field'} = $field_obj; trick_taint($field); # @@ -271,10 +272,18 @@ if ($action eq 'del') { trick_taint($value); # See if any bugs are still using this value. - $vars->{'bug_count'} = - $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?", - undef, $value) || 0; - $vars->{'value_count'} = + if ($field_obj->type != FIELD_TYPE_MULTI_SELECT) { + $vars->{'bug_count'} = + $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?", + undef, $value); + } + else { + $vars->{'bug_count'} = + $dbh->selectrow_array("SELECT COUNT(*) FROM bug_$field WHERE value = ?", + undef, $value); + } + + $vars->{'value_count'} = $dbh->selectrow_array("SELECT COUNT(*) FROM $field"); $vars->{'value'} = $value; @@ -319,15 +328,25 @@ if ($action eq 'delete') { $dbh->bz_start_transaction(); # Check if there are any bugs that still have this value. - my $bug_ids = $dbh->selectcol_arrayref( - "SELECT bug_id FROM bugs WHERE $field = ?", undef, $value); + my $bug_count; + if ($field_obj->type != FIELD_TYPE_MULTI_SELECT) { + $bug_count = + $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?", + undef, $value); + } + else { + $bug_count = + $dbh->selectrow_array("SELECT COUNT(*) FROM bug_$field WHERE value = ?", + undef, $value); + } - if (scalar(@$bug_ids)) { + + if ($bug_count) { # You tried to delete a field that bugs are still using. # You can't just delete the bugs. That's ridiculous. ThrowUserError("fieldvalue_still_has_bugs", { field => $field, value => $value, - count => scalar(@$bug_ids) }); + count => $bug_count }); } if ($field eq 'bug_status') { @@ -435,8 +454,14 @@ if ($action eq 'update') { } trick_taint($value); - $dbh->do("UPDATE bugs SET $field = ? WHERE $field = ?", - undef, $value, $valueold); + if ($field_obj->type != FIELD_TYPE_MULTI_SELECT) { + $dbh->do("UPDATE bugs SET $field = ? WHERE $field = ?", + undef, $value, $valueold); + } + else { + $dbh->do("UPDATE bug_$field SET value = ? WHERE value = ?", + undef, $value, $valueold); + } $dbh->do("UPDATE $field SET value = ? WHERE value = ?", undef, $value, $valueold); -- cgit v1.2.1