From 10b02af4fa2bd908adc442b39ac5880b573b011c Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Thu, 28 Jul 2005 07:35:50 +0000 Subject: Bug 300952: Change the editmilestones.cgi code to use Milestone.pm and Product.pm - Patch by Tiago R. Mello r=LpSolit a=justdave --- Bugzilla/Milestone.pm | 78 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) (limited to 'Bugzilla/Milestone.pm') diff --git a/Bugzilla/Milestone.pm b/Bugzilla/Milestone.pm index dad8b6c11..6956d5313 100644 --- a/Bugzilla/Milestone.pm +++ b/Bugzilla/Milestone.pm @@ -74,11 +74,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(q{ + SELECT COUNT(*) FROM bugs + WHERE product_id = ? AND target_milestone = ?}, + 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'}; } sub sortkey { return $_[0]->{'sortkey'}; } @@ -105,12 +118,42 @@ sub get_milestones_by_product ($) { SELECT value FROM milestones WHERE product_id = ?}, undef, $product_id); - my $milestones; + my @milestones; foreach my $value (@$values) { - $milestones->{$value} = new Bugzilla::Milestone($product_id, - $value); + push @milestones, new Bugzilla::Milestone($product_id, $value); } - return $milestones; + return @milestones; +} + +sub check_milestone ($$) { + my ($product, $milestone_name) = @_; + + unless ($milestone_name) { + ThrowUserError('milestone_not_specified'); + } + + my $milestone = new Bugzilla::Milestone($product->id, + $milestone_name); + unless ($milestone) { + ThrowUserError('milestone_not_valid', + {'product' => $product->name, + 'milestone' => $milestone_name}); + } + return $milestone; +} + +sub check_sort_key ($$) { + my ($milestone_name, $sortkey) = @_; + # Keep a copy in case detaint_signed() clears the sortkey + my $stored_sortkey = $sortkey; + + if (!detaint_signed($sortkey) || $sortkey < -32768 + || $sortkey > 32767) { + ThrowUserError('milestone_sortkey_invalid', + {'name' => $milestone_name, + 'sortkey' => $stored_sortkey}); + } + return $sortkey; } 1; @@ -151,6 +194,14 @@ Milestone.pm represents a Product Milestone object. Returns: A Bugzilla::Milestone object. +=item C + + Description: Returns the total of bugs that belong to the milestone. + + Params: none. + + Returns: Integer with the number of bugs. + =back =head1 SUBROUTINES @@ -159,13 +210,22 @@ Milestone.pm represents a Product Milestone object. =item C - Description: Returns all Bugzilla product milestones that belong + Description: Returns all product milestones 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::Milestone object list. + +=item C + + Description: Checks if a milestone name was passed in + and if it is a valid milestone. + + Params: $product - Bugzilla::Product object. + $milestone_name - String with a milestone name. - Returns: A hash with milestone value as key and a - Bugzilla::Milestone object as hash value. + Returns: Bugzilla::Milestone object. =back -- cgit v1.2.3-24-g4f1b