summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2009-01-02 14:59:22 +0100
committerlpsolit%gmail.com <>2009-01-02 14:59:22 +0100
commitf6c2d743d87f86cdc206ab4bc772639b4569eebe (patch)
treee4740db3fee1b4b67e30bcc0271696af1b4ab280 /Bugzilla
parent4c1a9a42e60496cde0565c512eec18d81050cccb (diff)
downloadbugzilla-f6c2d743d87f86cdc206ab4bc772639b4569eebe.tar.gz
bugzilla-f6c2d743d87f86cdc206ab4bc772639b4569eebe.tar.xz
Bug 313126: Clean up editclassification.cgi and make it use Bugzilla::Classification methods - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Classification.pm25
-rw-r--r--Bugzilla/User.pm16
2 files changed, 29 insertions, 12 deletions
diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm
index 2eb253aa7..7c362bc45 100644
--- a/Bugzilla/Classification.pm
+++ b/Bugzilla/Classification.pm
@@ -30,6 +30,7 @@ use base qw(Bugzilla::Object);
###############################
use constant DB_TABLE => 'classifications';
+use constant LIST_ORDER => 'sortkey, name';
use constant DB_COLUMNS => qw(
id
@@ -55,6 +56,26 @@ use constant VALIDATORS => {
};
###############################
+#### Constructors #####
+###############################
+sub remove_from_db {
+ my $self = shift;
+ my $dbh = Bugzilla->dbh;
+
+ ThrowUserError("classification_not_deletable") if ($self->id == 1);
+
+ $dbh->bz_start_transaction();
+ # Reclassify products to the default classification, if needed.
+ $dbh->do("UPDATE products SET classification_id = 1
+ WHERE classification_id = ?", undef, $self->id);
+
+ $dbh->do("DELETE FROM classifications WHERE id = ?", undef, $self->id);
+
+ $dbh->bz_commit_transaction();
+
+}
+
+###############################
#### Validators ####
###############################
@@ -93,6 +114,10 @@ sub _check_sortkey {
#### Methods ####
###############################
+sub set_name { $_[0]->set('name', $_[1]); }
+sub set_description { $_[0]->set('description', $_[1]); }
+sub set_sortkey { $_[0]->set('sortkey', $_[1]); }
+
sub product_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 5c4c8621c..0c0f45bc0 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -682,20 +682,12 @@ sub get_selectable_products {
sub get_selectable_classifications {
my ($self) = @_;
- if (defined $self->{selectable_classifications}) {
- return $self->{selectable_classifications};
- }
-
- my $products = $self->get_selectable_products;
+ if (!defined $self->{selectable_classifications}) {
+ my $products = $self->get_selectable_products;
+ my %class_ids = map { $_->classification_id => 1 } @$products;
- my $class;
- foreach my $product (@$products) {
- $class->{$product->classification_id} ||=
- new Bugzilla::Classification($product->classification_id);
+ $self->{selectable_classifications} = Bugzilla::Classification->new_from_list([keys %class_ids]);
}
- my @sorted_class = sort {$a->sortkey <=> $b->sortkey
- || lc($a->name) cmp lc($b->name)} (values %$class);
- $self->{selectable_classifications} = \@sorted_class;
return $self->{selectable_classifications};
}