Commit af7d2134 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 309749: Remove get_x_by_y functions from the new .pm files, in favor of object methods

Patch By André Batosti <batosti@async.com.br> r=LpSolit, a=justdave
parent b808272b
...@@ -145,32 +145,6 @@ sub product_id { return $_[0]->{'product_id'}; } ...@@ -145,32 +145,6 @@ sub product_id { return $_[0]->{'product_id'}; }
#### Subroutines #### #### Subroutines ####
############################### ###############################
sub get_components_by_product {
my ($product_id) = @_;
my $dbh = Bugzilla->dbh;
my $stored_product_id = $product_id;
unless (detaint_natural($product_id)) {
ThrowCodeError(
'invalid_numeric_argument',
{argument => 'product_id',
value => $stored_product_id,
function =>
'Bugzilla::Component::get_components_by_product'}
);
}
my $ids = $dbh->selectcol_arrayref(q{
SELECT id FROM components
WHERE product_id = ?}, undef, $product_id);
my @components;
foreach my $id (@$ids) {
push @components, new Bugzilla::Component($id);
}
return @components;
}
sub check_component { sub check_component {
my ($product, $comp_name) = @_; my ($product, $comp_name) = @_;
...@@ -217,7 +191,6 @@ Bugzilla::Component - Bugzilla product component class. ...@@ -217,7 +191,6 @@ Bugzilla::Component - Bugzilla product component class.
my $default_assignee = $component->default_assignee; my $default_assignee = $component->default_assignee;
my $default_qa_contact = $component->default_qa_contact; my $default_qa_contact = $component->default_qa_contact;
my @components = Bugzilla::Component::get_components_by_product($id);
my $component = Bugzilla::Component::check_component($product, 'AcmeComp'); my $component = Bugzilla::Component::check_component($product, 'AcmeComp');
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -282,15 +255,6 @@ Component.pm represents a Product Component object. ...@@ -282,15 +255,6 @@ Component.pm represents a Product Component object.
=over =over
=item C<get_components_by_product($product_id)>
Description: Returns all components that belong to the supplied product.
Params: $product_id - Integer with a Bugzilla product id.
Returns: An array of Bugzilla::Component objects.
=item C<check_component($product, $comp_name)> =item C<check_component($product, $comp_name)>
Description: Checks if the component name was passed in and if it is a valid Description: Checks if the component name was passed in and if it is a valid
......
...@@ -124,27 +124,6 @@ sub ValidateGroupName { ...@@ -124,27 +124,6 @@ sub ValidateGroupName {
return $ret; return $ret;
} }
sub get_group_controls_by_product {
my ($product_id) = @_;
my $dbh = Bugzilla->dbh;
my $query = qq{SELECT
$columns,
group_control_map.entry,
group_control_map.membercontrol,
group_control_map.othercontrol,
group_control_map.canedit
FROM groups
LEFT JOIN group_control_map
ON groups.id = group_control_map.group_id
WHERE group_control_map.product_id = ?
AND groups.isbuggroup != 0
ORDER BY groups.name};
my $groups = $dbh->selectall_hashref($query, 'id', undef,
($product_id));
return $groups;
}
sub get_all_groups { sub get_all_groups {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
...@@ -181,7 +160,6 @@ Bugzilla::Group - Bugzilla group class. ...@@ -181,7 +160,6 @@ Bugzilla::Group - Bugzilla group class.
my $is_active = $group->is_active; my $is_active = $group->is_active;
my $group_id = Bugzilla::Group::ValidateGroupName('admin', @users); my $group_id = Bugzilla::Group::ValidateGroupName('admin', @users);
my $groups = Bugzilla::Group::get_group_controls_by_product(1);
my @groups = Bugzilla::get_all_groups(); my @groups = Bugzilla::get_all_groups();
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -223,17 +201,6 @@ Group.pm represents a Bugzilla Group object. ...@@ -223,17 +201,6 @@ Group.pm represents a Bugzilla Group object.
Returns: It returns the group id if successful Returns: It returns the group id if successful
and undef otherwise. and undef otherwise.
=item C<get_group_controls_by_product($product_id)>
Description: Returns all group controls of a specific product.
It is encouraged to use Bugzilla::Product object
instead of directly calling this routine.
Params: $product_id - Integer with a Bugzilla product id.
Returns: A hash with group id as key and hash containing the
group data as value.
=item C<get_all_groups()> =item C<get_all_groups()>
Description: Returns all groups available, including both Description: Returns all groups available, including both
......
...@@ -98,32 +98,6 @@ sub sortkey { return $_[0]->{'sortkey'}; } ...@@ -98,32 +98,6 @@ sub sortkey { return $_[0]->{'sortkey'}; }
##### Subroutines ##### ##### Subroutines #####
################################ ################################
sub get_milestones_by_product {
my ($product_id) = @_;
my $dbh = Bugzilla->dbh;
my $stored_product_id = $product_id;
unless (detaint_natural($product_id)) {
ThrowCodeError(
'invalid_numeric_argument',
{argument => 'product_id',
value => $stored_product_id,
function =>
'Bugzilla::Milestone::get_milestones_by_product'}
);
}
my $values = $dbh->selectcol_arrayref(q{
SELECT value FROM milestones
WHERE product_id = ?}, undef, $product_id);
my @milestones;
foreach my $value (@$values) {
push @milestones, new Bugzilla::Milestone($product_id, $value);
}
return @milestones;
}
sub check_milestone { sub check_milestone {
my ($product, $milestone_name) = @_; my ($product, $milestone_name) = @_;
...@@ -172,7 +146,6 @@ Bugzilla::Milestone - Bugzilla product milestone class. ...@@ -172,7 +146,6 @@ Bugzilla::Milestone - Bugzilla product milestone class.
my $product_id = $milestone->product_id; my $product_id = $milestone->product_id;
my $value = $milestone->value; my $value = $milestone->value;
my $hash_ref = Bugzilla::Milestone::get_milestones_by_product(1);
my $milestone = $hash_ref->{'milestone_value'}; my $milestone = $hash_ref->{'milestone_value'};
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -207,15 +180,6 @@ Milestone.pm represents a Product Milestone object. ...@@ -207,15 +180,6 @@ Milestone.pm represents a Product Milestone object.
=over =over
=item C<get_milestones_by_product($product_id)>
Description: Returns all product milestones that belong
to the supplied product.
Params: $product_id - Integer with a product id.
Returns: Bugzilla::Milestone object list.
=item C<check_milestone($product, $milestone_name)> =item C<check_milestone($product, $milestone_name)>
Description: Checks if a milestone name was passed in Description: Checks if a milestone name was passed in
......
...@@ -96,10 +96,17 @@ sub _init { ...@@ -96,10 +96,17 @@ sub _init {
sub components { sub components {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh;
if (!defined $self->{components}) { if (!defined $self->{components}) {
my @components = my $ids = $dbh->selectcol_arrayref(q{
Bugzilla::Component::get_components_by_product($self->id); SELECT id FROM components
WHERE product_id = ?}, undef, $self->id);
my @components;
foreach my $id (@$ids) {
push @components, new Bugzilla::Component($id);
}
$self->{components} = \@components; $self->{components} = \@components;
} }
return $self->{components}; return $self->{components};
...@@ -117,20 +124,46 @@ sub classification { ...@@ -117,20 +124,46 @@ sub classification {
sub group_controls { sub group_controls {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh;
if (!defined $self->{group_controls}) { if (!defined $self->{group_controls}) {
$self->{group_controls} = my $query = qq{SELECT
Bugzilla::Group::get_group_controls_by_product($self->id); groups.id,
groups.name,
groups.description,
groups.isbuggroup,
groups.last_changed,
groups.userregexp,
groups.isactive,
group_control_map.entry,
group_control_map.membercontrol,
group_control_map.othercontrol,
group_control_map.canedit
FROM groups
LEFT JOIN group_control_map
ON groups.id = group_control_map.group_id
WHERE group_control_map.product_id = ?
AND groups.isbuggroup != 0
ORDER BY groups.name};
my $self->{group_controls} =
$dbh->selectall_hashref($query, 'id', undef, $self->id);
} }
return $self->{group_controls}; return $self->{group_controls};
} }
sub versions { sub versions {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh;
if (!defined $self->{versions}) { if (!defined $self->{versions}) {
my @versions = my $values = $dbh->selectcol_arrayref(q{
Bugzilla::Version::get_versions_by_product($self->id); SELECT value FROM versions
WHERE product_id = ?}, undef, $self->id);
my @versions;
foreach my $value (@$values) {
push @versions, new Bugzilla::Version($self->id, $value);
}
$self->{versions} = \@versions; $self->{versions} = \@versions;
} }
return $self->{versions}; return $self->{versions};
...@@ -138,10 +171,17 @@ sub versions { ...@@ -138,10 +171,17 @@ sub versions {
sub milestones { sub milestones {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh;
if (!defined $self->{milestones}) { if (!defined $self->{milestones}) {
my @milestones = my $values = $dbh->selectcol_arrayref(q{
Bugzilla::Milestone::get_milestones_by_product($self->id); SELECT value FROM milestones
WHERE product_id = ?}, undef, $self->id);
my @milestones;
foreach my $value (@$values) {
push @milestones, new Bugzilla::Milestone($self->id, $value);
}
$self->{milestones} = \@milestones; $self->{milestones} = \@milestones;
} }
return $self->{milestones}; return $self->{milestones};
......
...@@ -96,32 +96,6 @@ sub product_id { return $_[0]->{'product_id'}; } ...@@ -96,32 +96,6 @@ sub product_id { return $_[0]->{'product_id'}; }
##### Subroutines ### ##### Subroutines ###
############################### ###############################
sub get_versions_by_product {
my ($product_id) = @_;
my $dbh = Bugzilla->dbh;
my $stored_product_id = $product_id;
unless (detaint_natural($product_id)) {
ThrowCodeError(
'invalid_numeric_argument',
{argument => 'product_id',
value => $stored_product_id,
function =>
'Bugzilla::Version::get_versions_by_product'}
);
}
my $values = $dbh->selectcol_arrayref(q{
SELECT value FROM versions
WHERE product_id = ?}, undef, $product_id);
my @versions;
foreach my $value (@$values) {
push @versions, new Bugzilla::Version($product_id, $value);
}
return @versions;
}
sub check_version { sub check_version {
my ($product, $version_name) = @_; my ($product, $version_name) = @_;
...@@ -152,7 +126,6 @@ Bugzilla::Version - Bugzilla product version class. ...@@ -152,7 +126,6 @@ Bugzilla::Version - Bugzilla product version class.
my $product_id = $version->product_id; my $product_id = $version->product_id;
my $value = $version->value; my $value = $version->value;
my $hash_ref = Bugzilla::Version::get_versions_by_product(1);
my $version = $hash_ref->{'version_value'}; my $version = $hash_ref->{'version_value'};
my $version = Bugzilla::Version::check_version($product_obj, my $version = Bugzilla::Version::check_version($product_obj,
...@@ -190,15 +163,6 @@ Version.pm represents a Product Version object. ...@@ -190,15 +163,6 @@ Version.pm represents a Product Version object.
=over =over
=item C<get_versions_by_product($product_id)>
Description: Returns all product versions that belong
to the supplied product.
Params: $product_id - Integer with a product id.
Returns: Bugzilla::Version object list.
=item C<check_version($product, $version_name)> =item C<check_version($product, $version_name)>
Description: Checks if the version name exists for the product name. Description: Checks if the version name exists for the product name.
......
...@@ -92,12 +92,9 @@ my $product = Bugzilla::Product::check_product($product_name); ...@@ -92,12 +92,9 @@ my $product = Bugzilla::Product::check_product($product_name);
unless ($action) { unless ($action) {
my @components =
Bugzilla::Component::get_components_by_product($product->id);
$vars->{'showbugcounts'} = $showbugcounts; $vars->{'showbugcounts'} = $showbugcounts;
$vars->{'product'} = $product->name; $vars->{'product'} = $product->name;
$vars->{'components'} = \@components; $vars->{'components'} = $product->components;
$template->process("admin/components/list.html.tmpl", $vars) $template->process("admin/components/list.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
......
...@@ -80,12 +80,9 @@ my $product = Bugzilla::Product::check_product($product_name); ...@@ -80,12 +80,9 @@ my $product = Bugzilla::Product::check_product($product_name);
unless ($action) { unless ($action) {
my @milestones =
Bugzilla::Milestone::get_milestones_by_product($product->id);
$vars->{'showbugcounts'} = $showbugcounts; $vars->{'showbugcounts'} = $showbugcounts;
$vars->{'product'} = $product->name; $vars->{'product'} = $product->name;
$vars->{'milestones'} = \@milestones; $vars->{'milestones'} = $product->milestones;
$vars->{'default_milestone'} = $product->default_milestone; $vars->{'default_milestone'} = $product->default_milestone;
$template->process("admin/milestones/list.html.tmpl", $template->process("admin/milestones/list.html.tmpl",
$vars) $vars)
......
...@@ -88,12 +88,9 @@ my $product = Bugzilla::Product::check_product($product_name); ...@@ -88,12 +88,9 @@ my $product = Bugzilla::Product::check_product($product_name);
# #
unless ($action) { unless ($action) {
my @versions =
Bugzilla::Version::get_versions_by_product($product->id);
$vars->{'showbugcounts'} = $showbugcounts; $vars->{'showbugcounts'} = $showbugcounts;
$vars->{'product'} = $product->name; $vars->{'product'} = $product->name;
$vars->{'versions'} = \@versions; $vars->{'versions'} = $product->versions;
$template->process("admin/versions/list.html.tmpl", $template->process("admin/versions/list.html.tmpl",
$vars) $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment