diff options
author | mkanat%bugzilla.org <> | 2006-07-19 06:20:05 +0200 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2006-07-19 06:20:05 +0200 |
commit | 78094dfe411b41a33d930c7f0c623cc2eb216c28 (patch) | |
tree | 3a683755359017bc2fe1e17e002ddc5e79cac4b0 | |
parent | 33bdddf6e4a18a65dbabbf74047090de579f593f (diff) | |
download | bugzilla-78094dfe411b41a33d930c7f0c623cc2eb216c28.tar.gz bugzilla-78094dfe411b41a33d930c7f0c623cc2eb216c28.tar.xz |
Bug 339379: Make Bugzilla::Product use Bugzilla::Object
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk
-rw-r--r-- | Bugzilla/Product.pm | 99 | ||||
-rw-r--r-- | Bugzilla/User.pm | 2 | ||||
-rwxr-xr-x | collectstats.pl | 2 | ||||
-rwxr-xr-x | editflagtypes.cgi | 2 |
4 files changed, 18 insertions, 87 deletions
diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index e7f33ecce..53dd0140e 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -25,12 +25,16 @@ use Bugzilla::Util; use Bugzilla::Group; use Bugzilla::Error; +use base qw(Bugzilla::Object); + use constant DEFAULT_CLASSIFICATION_ID => 1; ############################### #### Initialization #### ############################### +use constant DB_TABLE => 'products'; + use constant DB_COLUMNS => qw( products.id products.name @@ -44,52 +48,6 @@ use constant DB_COLUMNS => qw( products.defaultmilestone ); -my $columns = join(", ", DB_COLUMNS); - -sub new { - my $invocant = shift; - my $class = ref($invocant) || $invocant; - my $self = {}; - bless($self, $class); - return $self->_init(@_); -} - -sub _init { - my $self = shift; - my ($param) = @_; - my $dbh = Bugzilla->dbh; - - my $id = $param unless (ref $param eq 'HASH'); - my $product; - - if (defined $id) { - detaint_natural($id) - || ThrowCodeError('param_must_be_numeric', - {function => 'Bugzilla::Product::_init'}); - - $product = $dbh->selectrow_hashref(qq{ - SELECT $columns FROM products - WHERE id = ?}, undef, $id); - - } elsif (defined $param->{'name'}) { - - trick_taint($param->{'name'}); - $product = $dbh->selectrow_hashref(qq{ - SELECT $columns FROM products - WHERE name = ?}, undef, $param->{'name'}); - } else { - ThrowCodeError('bad_arg', - {argument => 'param', - function => 'Bugzilla::Product::_init'}); - } - - return undef unless (defined $product); - - foreach my $field (keys %$product) { - $self->{$field} = $product->{$field}; - } - return $self; -} ############################### #### Methods #### @@ -211,8 +169,6 @@ sub bug_ids { #### Accessors ###### ############################### -sub id { return $_[0]->{'id'}; } -sub name { return $_[0]->{'name'}; } sub description { return $_[0]->{'description'}; } sub milestone_url { return $_[0]->{'milestoneurl'}; } sub disallow_new { return $_[0]->{'disallownew'}; } @@ -226,19 +182,6 @@ sub classification_id { return $_[0]->{'classification_id'}; } #### Subroutines ###### ############################### -sub get_all_products { - my $dbh = Bugzilla->dbh; - - my $ids = $dbh->selectcol_arrayref(q{ - SELECT id FROM products ORDER BY name}); - - my @products; - foreach my $id (@$ids) { - push @products, new Bugzilla::Product($id); - } - return @products; -} - sub check_product { my ($product_name) = @_; @@ -266,7 +209,7 @@ Bugzilla::Product - Bugzilla product class. use Bugzilla::Product; my $product = new Bugzilla::Product(1); - my $product = new Bugzilla::Product('AcmeProduct'); + my $product = new Bugzilla::Product({ name => 'AcmeProduct' }); my @components = $product->components(); my $groups_controls = $product->group_controls(); @@ -288,25 +231,17 @@ Bugzilla::Product - Bugzilla product class. =head1 DESCRIPTION -Product.pm represents a product object. +Product.pm represents a product object. It is an implementation +of L<Bugzilla::Object>, and thus provides all methods that +L<Bugzilla::Object> provides. + +The methods that are specific to C<Bugzilla::Product> are listed +below. =head1 METHODS =over -=item C<new($param)> - - Description: The constructor is used to load an existing product - by passing a product id or a hash. - - Params: $param - If you pass an integer, the integer is the - product id from the database that we want to - read in. If you pass in a hash with 'name' key, - then the value of the name key is the name of a - product from the DB. - - Returns: A Bugzilla::Product object. - =item C<components()> Description: Returns an array of component objects belonging to @@ -365,14 +300,6 @@ Product.pm represents a product object. =over -=item C<get_all_products()> - - Description: Returns all products from the database. - - Params: none. - - Returns: Bugzilla::Product object list. - =item C<check_product($product_name)> Description: Checks if the product name was passed in and if is a valid @@ -384,4 +311,8 @@ Product.pm represents a product object. =back +=head1 SEE ALSO + +L<Bugzilla::Object> + =cut diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index a5a502446..5133bc5f5 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -632,7 +632,7 @@ sub get_enterable_products { } my @products; - foreach my $product (Bugzilla::Product::get_all_products()) { + foreach my $product (Bugzilla::Product->get_all) { if ($self->can_enter_product($product->name)) { push(@products, $product); } diff --git a/collectstats.pl b/collectstats.pl index 5ba56fe4b..808badea9 100755 --- a/collectstats.pl +++ b/collectstats.pl @@ -68,7 +68,7 @@ if ($#ARGV >= 0 && $ARGV[0] eq "--regenerate") { my $datadir = bz_locations()->{'datadir'}; -my @myproducts = map {$_->name} Bugzilla::Product::get_all_products(); +my @myproducts = map {$_->name} Bugzilla::Product->get_all; unshift(@myproducts, "-All-"); # As we can now customize the list of resolutions, looking at the actual list diff --git a/editflagtypes.cgi b/editflagtypes.cgi index 61dafa923..79bf0dd72 100755 --- a/editflagtypes.cgi +++ b/editflagtypes.cgi @@ -517,7 +517,7 @@ sub deactivate { sub get_products_and_components { my $vars = shift; - my @products = Bugzilla::Product::get_all_products(); + my @products = Bugzilla::Product->get_all; # We require all unique component names. my %components; foreach my $product (@products) { |