1
# -*- Mode: perl; indent-tabs-mode: nil -*-
3
# The contents of this file are subject to the Mozilla Public
4
# License Version 1.1 (the "License"); you may not use this file
5
# except in compliance with the License. You may obtain a copy of
6
# the License at http://www.mozilla.org/MPL/
8
# Software distributed under the License is distributed on an "AS
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
# implied. See the License for the specific language governing
11
# rights and limitations under the License.
13
# The Original Code is the Bugzilla Bug Tracking System.
15
# Contributor(s): Tiago R. Mello <timello@async.com.br>
16
# Max Kanat-Alexander <mkanat@bugzilla.org>
20
package Bugzilla::Milestone;
22
use base qw(Bugzilla::Object);
27
################################
28
##### Initialization #####
29
################################
31
use constant DEFAULT_SORTKEY => 0;
33
use constant DB_TABLE => 'milestones';
35
use constant DB_COLUMNS => qw(
42
use constant NAME_FIELD => 'value';
43
use constant LIST_ORDER => 'sortkey, value';
48
my $dbh = Bugzilla->dbh;
52
$product = $param->{product};
53
my $name = $param->{name};
54
if (!defined $product) {
55
ThrowCodeError('bad_arg',
56
{argument => 'product',
57
function => "${class}::new"});
60
ThrowCodeError('bad_arg',
62
function => "${class}::new"});
65
my $condition = 'product_id = ? AND value = ?';
66
my @values = ($product->id, $name);
67
$param = { condition => $condition, values => \@values };
71
return $class->SUPER::new(@_);
76
my $dbh = Bugzilla->dbh;
78
if (!defined $self->{'bug_count'}) {
79
$self->{'bug_count'} = $dbh->selectrow_array(q{
80
SELECT COUNT(*) FROM bugs
81
WHERE product_id = ? AND target_milestone = ?},
82
undef, $self->product_id, $self->name) || 0;
84
return $self->{'bug_count'};
87
################################
88
##### Accessors ######
89
################################
91
sub name { return $_[0]->{'value'}; }
92
sub product_id { return $_[0]->{'product_id'}; }
93
sub sortkey { return $_[0]->{'sortkey'}; }
95
################################
96
##### Subroutines #####
97
################################
100
my ($product, $milestone_name) = @_;
102
unless ($milestone_name) {
103
ThrowUserError('milestone_not_specified');
106
my $milestone = new Bugzilla::Milestone({ product => $product,
107
name => $milestone_name });
108
unless ($milestone) {
109
ThrowUserError('milestone_not_valid',
110
{'product' => $product->name,
111
'milestone' => $milestone_name});
117
my ($milestone_name, $sortkey) = @_;
118
# Keep a copy in case detaint_signed() clears the sortkey
119
my $stored_sortkey = $sortkey;
121
if (!detaint_signed($sortkey) || $sortkey < -32768
122
|| $sortkey > 32767) {
123
ThrowUserError('milestone_sortkey_invalid',
124
{'name' => $milestone_name,
125
'sortkey' => $stored_sortkey});
136
Bugzilla::Milestone - Bugzilla product milestone class.
140
use Bugzilla::Milestone;
142
my $milestone = new Bugzilla::Milestone(
143
{ product => $product, name => 'milestone_value' });
145
my $product_id = $milestone->product_id;
146
my $value = $milestone->value;
148
my $milestone = $hash_ref->{'milestone_value'};
152
Milestone.pm represents a Product Milestone object.
158
=item C<new($product_id, $value)>
160
Description: The constructor is used to load an existing milestone
161
by passing a product id and a milestone value.
163
Params: $product_id - Integer with a Bugzilla product id.
164
$value - String with a milestone value.
166
Returns: A Bugzilla::Milestone object.
170
Description: Returns the total of bugs that belong to the milestone.
174
Returns: Integer with the number of bugs.
182
=item C<check_milestone($product, $milestone_name)>
184
Description: Checks if a milestone name was passed in
185
and if it is a valid milestone.
187
Params: $product - Bugzilla::Product object.
188
$milestone_name - String with a milestone name.
190
Returns: Bugzilla::Milestone object.