summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-07-19 09:05:10 +0200
committerlpsolit%gmail.com <>2005-07-19 09:05:10 +0200
commit534173a0d5d06a945cd48da84815e4f003ebf727 (patch)
tree17c8d114e1d3eb194be1aaab9fe0a2a958d94374 /Bugzilla
parent0b6e85450a54b205afcda501b78d2dd2982d269e (diff)
downloadbugzilla-534173a0d5d06a945cd48da84815e4f003ebf727.tar.gz
bugzilla-534173a0d5d06a945cd48da84815e4f003ebf727.tar.xz
Bug 300532: Update editversions.cgi to use routines from Version.pm and Product.pm - Patch by Tiago R. Mello <timello@async.com.br> r=LpSolit a=myk
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Product.pm46
-rw-r--r--Bugzilla/Version.pm64
2 files changed, 99 insertions, 11 deletions
diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm
index 28f1e73c0..37ef86a62 100644
--- a/Bugzilla/Product.pm
+++ b/Bugzilla/Product.pm
@@ -205,6 +205,33 @@ sub get_products_by_classification ($) {
return $products;
}
+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) = @_;
+
+ unless ($product_name) {
+ ThrowUserError('product_not_specified');
+ }
+ my $product = new Bugzilla::Product({name => $product_name});
+ unless ($product) {
+ ThrowUserError('product_doesnt_exist',
+ {'product' => $product_name});
+ }
+ return $product;
+}
+
1;
__END__
@@ -326,11 +353,28 @@ Product.pm represents a product object.
Description: Returns all products for a specific classification id.
- Params: none.
+ Params: $class_id - Integer with classification id.
Returns: A hash with product id as key and a Bugzilla::Product
object as value.
+=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
+ product.
+
+ Params: $product_name - String with a product name.
+
+ Returns: Bugzilla::Product object.
+
=back
=cut
diff --git a/Bugzilla/Version.pm b/Bugzilla/Version.pm
index 5cd5b2aeb..3a460e028 100644
--- a/Bugzilla/Version.pm
+++ b/Bugzilla/Version.pm
@@ -73,11 +73,24 @@ sub _init {
return $self;
}
+sub bug_count {
+ my $self = shift;
+ my $dbh = Bugzilla->dbh;
+
+ if (!defined $self->{'bug_count'}) {
+ $self->{'bug_count'} = $dbh->selectrow_array(qq{
+ SELECT COUNT(*) FROM bugs
+ WHERE product_id = ? AND version = ?}, undef,
+ ($self->product_id, $self->name)) || 0;
+ }
+ return $self->{'bug_count'};
+}
+
###############################
##### Accessors ####
###############################
-sub value { return $_[0]->{'value'}; }
+sub name { return $_[0]->{'value'}; }
sub product_id { return $_[0]->{'product_id'}; }
###############################
@@ -103,12 +116,24 @@ sub get_versions_by_product ($) {
SELECT value FROM versions
WHERE product_id = ?}, undef, $product_id);
- my $versions;
+ my @versions;
foreach my $value (@$values) {
- $versions->{$value} = new Bugzilla::Version($product_id,
- $value);
+ push @versions, new Bugzilla::Version($product_id, $value);
+ }
+ return @versions;
+}
+
+sub check_version ($$) {
+ my ($product, $version_name) = @_;
+
+ $version_name || ThrowUserError('version_not_specified');
+ my $version = new Bugzilla::Version($product->id, $version_name);
+ unless ($version) {
+ ThrowUserError('version_not_valid',
+ {'product' => $product->name,
+ 'version' => $version_name});
}
- return $versions;
+ return $version;
}
1;
@@ -131,6 +156,9 @@ Bugzilla::Version - Bugzilla product version class.
my $hash_ref = Bugzilla::Version::get_versions_by_product(1);
my $version = $hash_ref->{'version_value'};
+ my $version = Bugzilla::Version::check_version($product_obj,
+ 'acme_version');
+
=head1 DESCRIPTION
Version.pm represents a Product Version object.
@@ -144,11 +172,19 @@ Version.pm represents a Product Version object.
Description: The constructor is used to load an existing version
by passing a product id and a version value.
- Params: $product_id - Integer with a Bugzilla product id.
+ Params: $product_id - Integer with a product id.
$value - String with a version value.
Returns: A Bugzilla::Version object.
+=item C<bug_count()>
+
+ Description: Returns the total of bugs that belong to the version.
+
+ Params: none.
+
+ Returns: Integer with the number of bugs.
+
=back
=head1 SUBROUTINES
@@ -157,13 +193,21 @@ Version.pm represents a Product Version object.
=item C<get_versions_by_product($product_id)>
- Description: Returns all Bugzilla product versions that belong
+ Description: Returns all product versions that belong
to the supplied product.
- Params: $product_id - Integer with a Bugzilla product id.
+ Params: $product_id - Integer with a product id.
+
+ Returns: Bugzilla::Version object list.
+
+=item C<check_version($product, $version_name)>
+
+ Description: Checks if the version name exists for the product name.
+
+ Params: $product - A Bugzilla::Product object.
+ $version_name - String with a version name.
- Returns: A hash with version value as key and a Bugzilla::Version
- objects as value.
+ Returns: Bugzilla::Version object.
=back