From b03fc56082401474044c7f92f8786164ca0508a4 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 3 Oct 2008 06:37:16 +0000 Subject: Bug 456919: Implement Bugzilla::Field::Choice->remove_from_db and have editvalues.cgi use it Patch by Max Kanat-Alexander r=bbaetz, a=mkanat --- Bugzilla/Field/Choice.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'Bugzilla/Field') diff --git a/Bugzilla/Field/Choice.pm b/Bugzilla/Field/Choice.pm index 9db5c5efd..a5c5fe6b1 100644 --- a/Bugzilla/Field/Choice.pm +++ b/Bugzilla/Field/Choice.pm @@ -170,12 +170,52 @@ sub update { return $changes; } +sub remove_from_db { + my $self = shift; + if ($self->is_default) { + ThrowUserError('fieldvalue_is_default', + { field => $self->field, value => $self->name, + param_name => $self->DEFAULT_MAP->{$self->field->name}, + }); + } + if ($self->is_static) { + ThrowUserError('fieldvalue_not_deletable', + { field => $self->field, value => $self->name }); + } + if ($self->bug_count) { + ThrowUserError("fieldvalue_still_has_bugs", + { field => $self->field, value => $self->name, + count => $self->bug_count }); + } + $self->SUPER::remove_from_db(); +} + ############# # Accessors # ############# sub sortkey { return $_[0]->{'sortkey'}; } + +sub bug_count { + my $self = shift; + return $self->{bug_count} if defined $self->{bug_count}; + my $dbh = Bugzilla->dbh; + my $fname = $self->field->name; + my $count; + if ($self->field->type == FIELD_TYPE_MULTI_SELECT) { + $count = $dbh->selectrow_array("SELECT COUNT(*) FROM bug_$fname + WHERE value = ?", undef, $self->name); + } + else { + $count = $dbh->selectrow_array("SELECT COUNT(*) FROM bugs + WHERE $fname = ?", + undef, $self->name); + } + $self->{bug_count} = $count; + return $count; +} + sub field { my $invocant = shift; my $class = ref $invocant || $invocant; -- cgit v1.2.3-24-g4f1b