Commit a67c69cb authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 410823: Bugzilla fails when editing or deleting a multi-select field value -…

Bug 410823: Bugzilla fails when editing or deleting a multi-select field value - Patch by Ronaldo Maia <romaia@async.com.br> r/a=LpSolit
parent aebf6053
...@@ -165,7 +165,8 @@ unless ($field) { ...@@ -165,7 +165,8 @@ unless ($field) {
} }
# At this point, the field is defined. # At this point, the field is defined.
$vars->{'field'} = FieldMustExist($field); my $field_obj = FieldMustExist($field);
$vars->{'field'} = $field_obj;
trick_taint($field); trick_taint($field);
# #
...@@ -271,9 +272,17 @@ if ($action eq 'del') { ...@@ -271,9 +272,17 @@ if ($action eq 'del') {
trick_taint($value); trick_taint($value);
# See if any bugs are still using this value. # See if any bugs are still using this value.
if ($field_obj->type != FIELD_TYPE_MULTI_SELECT) {
$vars->{'bug_count'} = $vars->{'bug_count'} =
$dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?", $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?",
undef, $value) || 0; undef, $value);
}
else {
$vars->{'bug_count'} =
$dbh->selectrow_array("SELECT COUNT(*) FROM bug_$field WHERE value = ?",
undef, $value);
}
$vars->{'value_count'} = $vars->{'value_count'} =
$dbh->selectrow_array("SELECT COUNT(*) FROM $field"); $dbh->selectrow_array("SELECT COUNT(*) FROM $field");
...@@ -319,15 +328,25 @@ if ($action eq 'delete') { ...@@ -319,15 +328,25 @@ if ($action eq 'delete') {
$dbh->bz_start_transaction(); $dbh->bz_start_transaction();
# Check if there are any bugs that still have this value. # Check if there are any bugs that still have this value.
my $bug_ids = $dbh->selectcol_arrayref( my $bug_count;
"SELECT bug_id FROM bugs WHERE $field = ?", undef, $value); 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 tried to delete a field that bugs are still using.
# You can't just delete the bugs. That's ridiculous. # You can't just delete the bugs. That's ridiculous.
ThrowUserError("fieldvalue_still_has_bugs", ThrowUserError("fieldvalue_still_has_bugs",
{ field => $field, value => $value, { field => $field, value => $value,
count => scalar(@$bug_ids) }); count => $bug_count });
} }
if ($field eq 'bug_status') { if ($field eq 'bug_status') {
...@@ -435,8 +454,14 @@ if ($action eq 'update') { ...@@ -435,8 +454,14 @@ if ($action eq 'update') {
} }
trick_taint($value); trick_taint($value);
if ($field_obj->type != FIELD_TYPE_MULTI_SELECT) {
$dbh->do("UPDATE bugs SET $field = ? WHERE $field = ?", $dbh->do("UPDATE bugs SET $field = ? WHERE $field = ?",
undef, $value, $valueold); undef, $value, $valueold);
}
else {
$dbh->do("UPDATE bug_$field SET value = ? WHERE value = ?",
undef, $value, $valueold);
}
$dbh->do("UPDATE $field SET value = ? WHERE value = ?", $dbh->do("UPDATE $field SET value = ? WHERE value = ?",
undef, $value, $valueold); undef, $value, $valueold);
......
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