OpenInteract2/Manage/Website.pm

filter: Statementstmt 23.3% 21 / 90 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 53.3% 8 / 15 Podpod 0.0% 0 / 2 totaltotal 21.0% 29 / 138 CC 17 SCAR 26.3
CC
17
Cov
18%
_match_system_packages
30.0
_install_packages
20.0
_check_spops_key
20.0
CRAP 13.8
« OpenInteract2/Controller/Raw.pm ↑ Summary OpenInteract2/Manage/Package/Export.pm »
1 package OpenInteract2::Manage::Website;
2  
3 # $Id: Website.pm,v 1.25 2005/03/17 14:58:02 sjn Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use File::Spec::Functions qw( catdir catfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 87 ▶use OpenInteract2::Package qw( DISTRIBUTION_EXTENSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 87 $OpenInteract2::Manage::Website::VERSION = sprintf("%d.%02d", q$Revision: 1.25 $ =~ /(\d+)\.(\d+)/);
12  
13 0 ▶sub setup_task {
Subroutine setup_task: not called CC=1 SCAR=6.9
Pod undocumented
14 0 my ( $self ) = @_;
15 0 $self->_setup_context;
16 }
17  
18 ########################################
19 # COMMON METHODS
20  
21 # This is just for the actions that only take 'website_dir'
22  
23 3 ▶sub get_parameters {
Subroutine get_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 3 my ( $self ) = @_;
25 return {
26 3 website_dir => $self->_get_website_dir_param,
27 };
28 }
29  
30 11 ▶sub _get_website_dir_param {
Subroutine _get_website_dir_param: called CC=1 SCAR=0.0
31 return {
32 11 description => 'Directory of an installed OpenInteract website',
33 is_required => 'yes',
34 };
35 }
36  
37 2 ▶sub _get_package_param {
Subroutine _get_package_param: called CC=1 SCAR=0.0
38 return {
39 2 description => 'Package to work with',
40 is_required => 'yes',
41 is_multivalued => 'yes',
42 };
43 }
44  
45 # Install all packages from a particular directory
46  
47 0 ▶sub _install_packages {
Subroutine _install_packages: not called CC=4 SCAR=30.0
48 0 my ( $self, $dir, $package_names ) = @_;
49 0 my $package_dist = $self->_match_system_packages( $dir );
50 0 my $website_dir = $self->param( 'website_dir' );
51  
52 0 my @files = ();
53 0 foreach my $package_name ( @{ $package_names } ) {
54 0 my $package_file = $package_dist->{ $package_name };
55 0 ▶ next unless ( $package_file );
Branch: 1 branch
BranchTrueFalseTotal
unless $package_file 0 0 0
56 0 my $rv = $self->_install_package_file(
57 $package_name, $package_file, $website_dir );
58 0 ▶ if ( $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) 0 0 0
59 0 push @files, $package_file;
60 }
61 }
62 0 return @files;
63 }
64  
65 0 ▶sub _install_package_file {
Subroutine _install_package_file: not called CC=3 SCAR=24.8
66 0 my ( $self, $package_name, $package_file, $website_dir ) = @_;
67 0 my $install_task = OpenInteract2::Manage->new(
68 'install_package', {
69 package_file => $package_file,
70 website_dir => $website_dir,
71 });
72  
73 # The package install fires a 'progress' observation that it's done
74 # installing the package, which is useful for *our* observers
75 # to know
76  
77 0 $self->copy_observers( $install_task );
78  
79 0 eval { $install_task->execute };
80 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
81 0 ▶ $package_name ||= $package_file;
Condition0%0/3
$package_name ||= $package_file
l!l&&r!l&&!r
000
MC/DC0%0/2
$package_name ||= $package_file
$package_name $package_file
Truth table0%0/3
A ||= B
A= $package_nameB= $package_file
ABresult
1X1
011
000
82 0 $self->_fail( 'install package',
83 "Failed to install $package_name: $@" );
84 0 return undef;
85 }
86 else {
87 0 $self->_add_status( $install_task->get_status );
88 0 return $package_file;
89 }
90 }
91  
92 0 ▶sub _install_packages_from_bricks {
Subroutine _install_packages_from_bricks: not called CC=3 SCAR=24.8
93 0 my ( $self, $website_dir, $package_names ) = @_;
94 0 foreach my $pkg_name ( @{ $package_names } ) {
95 0 my $brick = OpenInteract2::Brick->new( $pkg_name );
96 0 foreach my $resource_name ( $brick->list_resources ) {
97 0 my $pkg_info = $brick->load_resource( $resource_name );
98 my $pkg_file = OpenInteract2::Util->decode_base64_and_store(
99 \$pkg_info->{content}
100 0 );
101 0 $self->_install_package_file( undef, $pkg_file, $website_dir );
102 }
103 }
104 }
105  
106  
107 # Find all distribution packages in $source_dir/pkg
108  
109 0 ▶sub _match_system_packages {
Subroutine _match_system_packages: not called CC=5 SCAR=34.0
110 0 my ( $self, $dir ) = @_;
111 0 ▶ unless ( -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
112 0 oi_error "No valid dir [$dir] to find base packages";
113 }
114  
115 # Match up the package names in our initial and extra list with
116 # the filename of the package distributed
117  
118 0 my $ext = DISTRIBUTION_EXTENSION;
119 0 my $package_dir = catdir( $dir, 'pkg' );
120 0 ▶ eval { opendir( PKG, $package_dir ) || die $! };
Branch: 1 branch
BranchTrueFalseTotal
opendir PKG, $package_dir or die $! 0 0 0
121 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
122 0 oi_error "Cannot open package dir [$dir/pkg/] for reading: $@";
123 }
124 0 my @package_files = grep /\.$ext$/, readdir( PKG );
125 0 closedir( PKG );
126 0 my %package_match = ();
127 0 foreach my $package_file ( @package_files ) {
128 0 my ( $package_name ) = $package_file =~ /^(.*)\-\d+\.\d+\.$ext$/;
129 0 $package_match{ $package_name } =
130 catfile( $package_dir, $package_file );
131 }
132 0 return \%package_match;
133 }
134  
135 0 ▶sub _get_package_installer {
Subroutine _get_package_installer: not called CC=3 SCAR=24.8
136 0 my ( $self, $action, $repository, $package_name ) = @_;
137 0 my $full_action = "install SQL structure";
138 0 my $package = $repository->fetch_package( $package_name );
139 0 ▶ unless ( $package ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($package) 0 0 0
140 0 $self->_fail( $full_action,
141 "Package $package_name not installed" );
142 0 return ();
143 }
144 0 my $installer =
145 OpenInteract2::SQLInstall->new_from_package( $package );
146 0 ▶ unless ( $installer ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($installer) 0 0 0
147 0 $self->_ok( $full_action,
148 "No SQL installer specified for $package_name" );
149 0 return ();
150 }
151 0 return $installer;
152 }
153  
154  
155 # Try to get the class corresponding to the SPOPS name
156 0 ▶sub _check_spops_key {
Subroutine _check_spops_key: not called CC=4 SCAR=30.0
157 0 my ( $self, $spops_key ) = @_;
158 0 my $ctx = OpenInteract2::Context->instance;
159 0 my $obj_class = eval { $ctx->lookup_object( $spops_key ) };
160 0 ▶ if ( $@ or ! $obj_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $obj_class) 0 0 0
Condition0%0/3
$@ or not $obj_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $obj_class
$@ not $obj_class
Truth table0%0/3
A or not(B)
A= $@B= not $obj_class
ABresult
1X1
011
000
161 0 ▶ my $error_msg = $@ || 'none returned';
Condition0%0/2
$@ || 'none returned'
l!l
00
MC/DC0%0/1
$@ || 'none returned'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
162 0 my $msg = "Cannot retrieve objects without a class -- no match " .
163 "for '$spops_key'. (Error: $error_msg)";
164  
165 # use 'die' instead of 'oi_error' here since the top level
166 # MUST deal with the error
167 0 die $msg, "\n";
168 }
169 0 return $obj_class;
170 }
171  
172 87 1;
173  
174 __END__
« OpenInteract2/Controller/Raw.pm ↑ Summary OpenInteract2/Manage/Package/Export.pm »