]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 339379: Make Bugzilla::Product use Bugzilla::Object
authormkanat%bugzilla.org <>
Wed, 19 Jul 2006 04:20:05 +0000 (04:20 +0000)
committermkanat%bugzilla.org <>
Wed, 19 Jul 2006 04:20:05 +0000 (04:20 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk

Bugzilla/Product.pm
Bugzilla/User.pm
collectstats.pl
editflagtypes.cgi

index e7f33eccea00b12e1f793f517a0e9f493ae08474..53dd0140ecfe00bc8e39079ac33e93c50650dc4e 100644 (file)
@@ -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
index a5a50244626da6e25ce2628ce4975dc0e2e2db10..5133bc5f52074d4111003bb7a2b3eab7a4b869f6 100644 (file)
@@ -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);
         }
index 5ba56fe4b18d5626f1397672f91dc80ee1940a84..808badea9562616835eda6bc1aa6f6bc3114846f 100755 (executable)
@@ -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
index 61dafa923712c1a0194f49c66a88ee807b715489..79bf0dd7205d75a8f56d238cdd96b63586a51e63 100755 (executable)
@@ -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) {