Clean out dependency loops in modules

git-svn-id: svn://10.0.0.236/trunk@248370 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ghendricks%novell.com 2008-03-21 19:51:54 +00:00
parent c1f8363069
commit 4f9c8e1af1
8 changed files with 80 additions and 49 deletions

View File

@ -455,7 +455,7 @@ sub contents {
sub datasize {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
# return $self->{'datasize'} if exists $self->{'datasize'};
return $self->{'datasize'} if exists $self->{'datasize'};
my ($datasize) = $dbh->selectrow_array("SELECT LENGTH(contents)
FROM test_attachment_data
@ -468,6 +468,9 @@ sub datasize {
sub cases {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::TestCase;
return $self->{'cases'} if exists $self->{'cases'};
my $caseids = $dbh->selectcol_arrayref(
"SELECT case_id FROM test_case_attachments
@ -485,6 +488,9 @@ sub cases {
sub plans {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::TestPlan;
return $self->{'plans'} if exists $self->{'plans'};
my $planids = $dbh->selectcol_arrayref(
"SELECT plan_id FROM test_plan_attachments

View File

@ -96,9 +96,12 @@ sub _check_product {
$product_id = trim($product_id);
require Bugzilla::Testopia::Product;
my $product;
if (trim($product_id) !~ /^\d+$/ ){
$product = Bugzilla::Product::check_product($product_id);
$product = Bugzilla::Testopia::Product->new($product_id);
}
else {
$product = Bugzilla::Testopia::Product->new($product_id);
@ -913,10 +916,9 @@ sub product {
my $self = shift;
my $dbh = Bugzilla->dbh;
return $self->{'product'} if exists $self->{'product'};
require Bugzilla::Testopia::Product;
$self->{'product'} = Bugzilla::Product->new($self->{'product_id'});
return $self->{'product'};
}
=head2 runs
@ -929,7 +931,9 @@ sub runs {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
return $self->{'runs'} if exists $self->{'runs'};
require Bugzilla::Testopia::TestRun;
my $runids = $dbh->selectcol_arrayref("SELECT run_id FROM test_runs
WHERE environment_id = ?",
undef, $self->id);
@ -952,6 +956,8 @@ sub caseruns {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
return $self->{'caseruns'} if exists $self->{'caseruns'};
require Bugzilla::Testopia::TestCaseRun;
my $ids = $dbh->selectcol_arrayref("SELECT case_run_id FROM test_case_runs
WHERE environment_id = ?",

View File

@ -34,6 +34,8 @@ sub environments {
return $self->{'environments'} if defined $self->{'environments'};
require Bugzilla::Testopia::Environment;
my $query = "SELECT environment_id";
$query .= " FROM test_environments";
$query .= " WHERE product_id = ?";
@ -48,10 +50,10 @@ sub environments {
}
my @objs;
require Bugzilla::Testopia::Environment;
foreach my $id (@{$ref}){
push @objs, Bugzilla::Testopia::Environment->new($id);
}
$self->{'environments'} = \@objs;
return $self->{'environments'};
}
@ -60,6 +62,8 @@ sub builds {
my $self = shift;
my($active, $current) = @_;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::Build;
my $query = "SELECT build_id FROM test_builds WHERE product_id = ?";
if ($active && $current){
@ -82,10 +86,10 @@ sub builds {
}
my @objs;
require Bugzilla::Testopia::Build;
foreach my $id (@{$ref}){
push @objs, Bugzilla::Testopia::Build->new($id);
}
$self->{'builds'} = \@objs;
return $self->{'builds'};
}
@ -113,6 +117,10 @@ sub plans {
my $self = shift;
my $dbh = Bugzilla->dbh;
return $self->{'plans'} if exists $self->{'plans'};
require Bugzilla::Testopia::TestPlan;
my $ref = $dbh->selectcol_arrayref(
"SELECT plan_id
FROM test_plans
@ -120,7 +128,7 @@ sub plans {
ORDER BY name",
undef, $self->{'id'});
my @objs;
require Bugzilla::Testopia::TestPlan;
foreach my $id (@{$ref}){
push @objs, Bugzilla::Testopia::TestPlan->new($id);
}
@ -132,13 +140,16 @@ sub cases {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
return $self->{'cases'} if exists $self->{'cases'};
require Bugzilla::Testopia::TestCase;
my $caseids = $dbh->selectcol_arrayref(
"SELECT case_id FROM test_case_plans
INNER JOIN test_plans on test_case_plans.plan_id = test_plans.plan_id
WHERE test_plans.product_id = ?",
undef, $self->id);
my @cases;
require Bugzilla::Testopia::TestCase;
foreach my $id (@{$caseids}){
push @cases, Bugzilla::Testopia::TestCase->new($id);
}
@ -152,13 +163,15 @@ sub runs {
my $dbh = Bugzilla->dbh;
return $self->{'runs'} if exists $self->{'runs'};
require Bugzilla::Testopia::TestRun;
my $runids = $dbh->selectcol_arrayref(
"SELECT run_id FROM test_runs
INNER JOIN test_plans ON test_runs.plan_id = test_plans.plan_id
WHERE test_plans.product_id = ?",
undef, $self->id);
my @runs;
require Bugzilla::Testopia::TestRun;
foreach my $id (@{$runids}){
push @runs, Bugzilla::Testopia::TestRun->new($id);
}
@ -227,6 +240,9 @@ sub milestones {
sub tags {
my $self = shift;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::TestTag;
my $ref = $dbh->selectcol_arrayref(
"(SELECT test_tags.tag_id, test_tags.tag_name AS name
FROM test_tags
@ -251,7 +267,6 @@ sub tags {
ORDER BY name", undef, ($self->id,$self->id,$self->id));
my @product_tags;
require Bugzilla::Testopia::TestTag;
foreach my $id (@$ref){
push @product_tags, Bugzilla::Testopia::TestTag->new($id);
}
@ -260,25 +275,12 @@ sub tags {
return $self->{'tags'};
}
=head2 type
Returns 'product'
=cut
sub type {
my $self = shift;
$self->{'type'} = 'product';
return $self->{'type'};
}
=head2 type
Returns true if logged in user has rights to edit Testopia objects
associated with this product.
=cut
sub canedit {
my $self = shift;
my ($user) = @_;

View File

@ -39,12 +39,14 @@ use Bugzilla::User;
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Constants;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestPlan;
use Bugzilla::Testopia::TestRun;
use Bugzilla::Testopia::TestCaseRun;
use Bugzilla::Testopia::Category;
use Bugzilla::Testopia::Attachment;
use JSON;
use Text::Diff;
@ -355,7 +357,7 @@ sub _check_components {
@comp_ids = @$components;
}
else {
@comp_ids = split(',', $components);
@comp_ids = split(/[\s,]+/, $components);
}
foreach my $id (@comp_ids){
Bugzilla::Testopia::Util::validate_selection($id, 'id', 'components');
@ -617,15 +619,6 @@ sub lookup_default_tester {
###############################
#### Methods ####
###############################
=head2 get_selectable_components
Returns a reference to a list of selectable components not already
associated with this case.
=cut
sub get_selectable_components {
my $self = shift;
my ($byid) = @_;
@ -792,7 +785,7 @@ sub add_tag {
if (ref $t eq 'ARRAY'){
push @tags, $_ foreach @$t;
}
push @tags, split(',', $t);
push @tags, split(/[\s,]+/, $t);
}
foreach my $name (@tags){
@ -945,17 +938,14 @@ sub remove_blocks {
my @cases;
foreach my $case (split /,/, $case_ids)
{
foreach my $case (split /[\s,]+/, $case_ids){
detaint_natural($case);
push @cases, $case;
}
my $query =<<QUERY;
DELETE
my $query ="DELETE
FROM test_case_dependencies
WHERE dependson = ?
QUERY
WHERE dependson = ?";
$query .= "AND (";
$query .= join(" or ", map {"blocked = ?"} @cases);
@ -1015,17 +1005,17 @@ sub remove_dependson {
my @cases;
foreach my $case (split /,/, $case_ids)
foreach my $case (split /[\s,]+/, $case_ids)
{
detaint_natural($case);
push @cases, $case;
}
my $query =<<QUERY;
my $query = "
DELETE
FROM test_case_dependencies
WHERE blocked = ?
QUERY
WHERE blocked = ?";
$query .= "AND (";
$query .= join(" or ", map {"dependson = ?"} @cases);

View File

@ -26,12 +26,15 @@ use strict;
use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::User;
use Bugzilla::Bug;
use Bugzilla::Config;
use Bugzilla::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::Environment;
use Bugzilla::Testopia::Build;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Attachment;
use Bugzilla::Bug;
use Date::Format;
use Date::Parse;
@ -812,6 +815,7 @@ Returns the TestRun object that this case-run is associated with
sub run {
my $self = shift;
return $self->{'run'} if exists $self->{'run'};
require Bugzilla::Testopia::TestRun;
$self->{'run'} = Bugzilla::Testopia::TestRun->new($self->{'run_id'});
return $self->{'run'};
}
@ -826,6 +830,7 @@ Returns the TestCase object that this case-run is associated with
sub case {
my $self = shift;
return $self->{'case'} if exists $self->{'case'};
require Bugzilla::Testopia::TestCase;
$self->{'case'} = Bugzilla::Testopia::TestCase->new($self->{'case_id'});
return $self->{'case'};
}

View File

@ -28,14 +28,13 @@ use Bugzilla::Error;
use Bugzilla::Config;
use Bugzilla::Constants;
use Bugzilla::Version;
use Bugzilla::Bug;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestRun;
use Bugzilla::Testopia::Category;
use Bugzilla::Testopia::Build;
use Bugzilla::Testopia::TestTag;
use Bugzilla::Testopia::Product;
use Bugzilla::Bug;
use Bugzilla::Testopia::Attachment;
use Text::Diff;
use JSON;
@ -252,6 +251,7 @@ sub create {
# Create default category
unless (scalar @{$self->product->categories}){
require Bugzilla::Testopia::Category;
my $category = Bugzilla::Testopia::Category->create(
{'name' => '--default--',
'description' => 'Default product category for test cases',
@ -1170,6 +1170,9 @@ sub test_cases {
my ($self) = @_;
my $dbh = Bugzilla->dbh;
return $self->{'test_cases'} if exists $self->{'test_cases'};
require Bugzilla::Testopia::TestCase;
my $caseids = $dbh->selectcol_arrayref(
"SELECT case_id FROM test_case_plans
WHERE plan_id = ?",
@ -1265,6 +1268,9 @@ sub builds_seen {
my $self = shift;
my ($status_id) = @_;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::Build;
my $ref = $dbh->selectcol_arrayref(
"SELECT DISTINCT test_case_runs.build_id
FROM test_case_runs
@ -1283,6 +1289,9 @@ sub environments_seen {
my $self = shift;
my ($status_id) = @_;
my $dbh = Bugzilla->dbh;
require Bugzilla::Testopia::Environment;
my $ref = $dbh->selectcol_arrayref(
"SELECT DISTINCT test_case_runs.environment_id
FROM test_case_runs

View File

@ -29,8 +29,10 @@ use Bugzilla::User;
use Bugzilla::Constants;
use Bugzilla::Bug;
use Bugzilla::Config;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Environment;
use Bugzilla::Testopia::Build;
use JSON;
use base qw(Exporter Bugzilla::Object);
@ -220,6 +222,8 @@ sub run_create_validators {
sub create {
my ($class, $params) = @_;
require Bugzilla::Testopia::TestPlan;
$class->SUPER::check_required_create_fields($params);
my $field_values = $class->run_create_validators($params);
my $timestamp = Bugzilla::Testopia::Util::get_time_stamp();
@ -1226,6 +1230,9 @@ sub current_caseruns {
my $self = shift;
my $dbh = Bugzilla->dbh;
return $self->{'current_caseruns'} if exists $self->{'current_caseruns'};
require Bugzilla::Testopia::TestCaseRun;
my $ref = $dbh->selectcol_arrayref(
"SELECT case_run_id FROM test_case_runs
WHERE run_id=? AND iscurrent=1", undef,
@ -1250,6 +1257,9 @@ sub caseruns {
my $self = shift;
my $dbh = Bugzilla->dbh;
return $self->{'caseruns'} if exists $self->{'caseruns'};
require Bugzilla::Testopia::TestCaseRun;
my $ref = $dbh->selectcol_arrayref(
"SELECT case_run_id FROM test_case_runs
WHERE run_id=?", undef, $self->{'run_id'});

View File

@ -30,6 +30,9 @@ use Bugzilla::Constants;
use Bugzilla::Testopia::Constants;
use Bugzilla::Testopia::Util;
use Bugzilla::Testopia::TestRun;
use Bugzilla::Testopia::TestCaseRun;
use Bugzilla::Testopia::TestCase;
use JSON;
Bugzilla->error_mode(ERROR_MODE_AJAX);