summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2008-10-03 08:37:16 +0200
committermkanat%bugzilla.org <>2008-10-03 08:37:16 +0200
commitb03fc56082401474044c7f92f8786164ca0508a4 (patch)
tree060d369e1ac921ea158149379a3a2cdadb214f72 /Bugzilla
parentfab5d3a38aadaed1e6153c0fbd820449258586b2 (diff)
downloadbugzilla-b03fc56082401474044c7f92f8786164ca0508a4.tar.gz
bugzilla-b03fc56082401474044c7f92f8786164ca0508a4.tar.xz
Bug 456919: Implement Bugzilla::Field::Choice->remove_from_db and have editvalues.cgi use it
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Field/Choice.pm40
-rw-r--r--Bugzilla/Object.pm15
-rw-r--r--Bugzilla/Status.pm12
3 files changed, 67 insertions, 0 deletions
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;
diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm
index cde440b95..532b2c5bc 100644
--- a/Bugzilla/Object.pm
+++ b/Bugzilla/Object.pm
@@ -290,6 +290,15 @@ sub update {
return \%changes;
}
+sub remove_from_db {
+ my $self = shift;
+ my $table = $self->DB_TABLE;
+ my $id_field = $self->ID_FIELD;
+ Bugzilla->dbh->do("DELETE FROM $table WHERE $id_field = ?",
+ undef, $self->id);
+ undef $self;
+}
+
###############################
#### Subroutines ######
###############################
@@ -726,6 +735,12 @@ C<update>.)
=back
+=item C<remove_from_db>
+
+Removes this object from the database. Will throw an error if you can't
+remove it for some reason. The object will then be destroyed, as it is
+not safe to use the object after it has been removed from the database.
+
=back
=head2 Subclass Helpers
diff --git a/Bugzilla/Status.pm b/Bugzilla/Status.pm
index 565433850..d32b6c354 100644
--- a/Bugzilla/Status.pm
+++ b/Bugzilla/Status.pm
@@ -73,6 +73,18 @@ sub create {
return $self;
}
+sub remove_from_db {
+ my $self = shift;
+ my $dbh = Bugzilla->dbh;
+ my $id = $self->id;
+ $dbh->bz_start_transaction();
+ $self->SUPER::remove_from_db();
+ $dbh->do('DELETE FROM status_workflow
+ WHERE old_status = ? OR new_status = ?',
+ undef, $id, $id);
+ $dbh->bz_commit_transaction();
+}
+
###############################
##### Accessors ####
###############################