| 1 | package OpenInteract2::Manage::Website::InstallPackage; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: InstallPackage.pm,v 1.20 2005/03/17 14:58:04 sjn Exp $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( OpenInteract2::Manage::Website ); | ||||||||||||||||||||||||||
|
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::Context qw( CTX ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 87 | ▶ | use OpenInteract2::Exception qw( oi_error ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 87 | ▶ | use OpenInteract2::Repository; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 87 | $OpenInteract2::Manage::Website::Install::VERSION = sprintf("%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # METADATA | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 87 | ▶ | sub get_name { | ||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 87 | return 'install_package'; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub get_brief_description { | ||||||||||||||||||||||||||
|
Subroutine
get_brief_description: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | return 'Install a package distribution to a website'; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub get_parameters { | ||||||||||||||||||||||||||
|
Subroutine
get_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 26 | return { | ||||||||||||||||||||||||||||
| 27 | 1 | website_dir => $self->_get_website_dir_param, | |||||||||||||||||||||||||||
| 28 | package_file => { | ||||||||||||||||||||||||||||
| 29 | description => | ||||||||||||||||||||||||||||
| 30 | 'Package distribution filename to install to website', | ||||||||||||||||||||||||||||
| 31 | is_required => 'no', | ||||||||||||||||||||||||||||
| 32 | do_validate => 'yes', | ||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | package_class => { | ||||||||||||||||||||||||||||
| 35 | description => | ||||||||||||||||||||||||||||
| 36 | 'Package distribution application class that can perform installation', | ||||||||||||||||||||||||||||
| 37 | is_required => 'no', | ||||||||||||||||||||||||||||
| 38 | do_validate => 'yes', | ||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub validate_param { | ||||||||||||||||||||||||||
|
Subroutine
validate_param: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ( $self, $name, $value ) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $name eq 'package_class' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 46 | 0 | my $pkg_file = $self->param( 'package_file' ); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | unless ( $value or $pkg_file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value or $pkg_file
MC/DC0%0/2
$value or $pkg_file
$value
$pkg_file
Truth table0%0/3
A or B
A= $valueB= $pkg_file
| |||||||||||||||||||||||||||||
| 48 | 0 | return "Either 'package_class' or 'package_file' must be defined."; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | elsif ( $name eq 'package_file' ) { | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return unless ( $value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | return $self->SUPER::validate_param( $name, $value ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub setup_task {} | ||||||||||||||||||||||||||
|
Subroutine
setup_task: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # RUN | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub run_task { | ||||||||||||||||||||||||||
|
Subroutine
run_task: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | my %status = ( | |||||||||||||||||||||||||||
| 66 | action => 'install package', | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( my $package_file = $self->param( 'package_file' ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 69 | 0 | $self->_install_file( $package_file, \%status ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | elsif ( my $app_class = $self->param( 'package_class' ) ) { | ||||||||||||||||||||||||||||
| 72 | 0 | $self->_install_app( $app_class, \%status ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | $self->_add_status( \%status ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _install_file { | ||||||||||||||||||||||||||
|
Subroutine
_install_file: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 78 | 0 | my ( $self, $package_file, $status ) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | $status->{filename} = $package_file; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my $package = OpenInteract2::Package->new({ | |||||||||||||||||||||||||||
| 82 | package_file => $package_file | ||||||||||||||||||||||||||||
| 83 | }); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | $self->_setup_context({ skip => 'read packages' }); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $is_installed = $self->_check_package_exists( | |||||||||||||||||||||||||||
| 88 | $package->name, $package->version, $status ); | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return if ( $is_installed ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $full_package_name = $package->full_name; | |||||||||||||||||||||||||||
| 92 | 0 | my $installed_package = eval { | |||||||||||||||||||||||||||
| 93 | 0 | OpenInteract2::Package->install({ | |||||||||||||||||||||||||||
| 94 | package_file => $package_file, | ||||||||||||||||||||||||||||
| 95 | repository => CTX->repository | ||||||||||||||||||||||||||||
| 96 | }) | ||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $status->{is_ok} = 'no'; | |||||||||||||||||||||||||||
| 100 | 0 | $status->{message} = "Error: $@"; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||
| 103 | 0 | $status->{is_ok} = 'yes'; | |||||||||||||||||||||||||||
| 104 | 0 | $status->{package} = $installed_package->name; | |||||||||||||||||||||||||||
| 105 | 0 | $status->{version} = $installed_package->version; | |||||||||||||||||||||||||||
| 106 | $status->{message} = | ||||||||||||||||||||||||||||
| 107 | 0 | sprintf( 'Installed package %s-%s to website %s', | |||||||||||||||||||||||||||
| 108 | $installed_package->name, $installed_package->version, | ||||||||||||||||||||||||||||
| 109 | $self->param( 'website_dir' ) ); | ||||||||||||||||||||||||||||
| 110 | 0 | eval { | |||||||||||||||||||||||||||
| 111 | 0 | $self->_create_temp_lib_refresh( $installed_package->name ) | |||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $status->{message} .= "\nNOTE: Could not create temp lib refresh " . | |||||||||||||||||||||||||||
| 115 | "file, so you may need to delete it manually."; | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | $self->param( package => $installed_package ); | |||||||||||||||||||||||||||
| 119 | 0 | $self->notify_observers( | |||||||||||||||||||||||||||
| 120 | progress => "Finished with installation of $full_package_name" ); | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub _install_app { | ||||||||||||||||||||||||||
|
Subroutine
_install_app: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 124 | 0 | my ( $self, $app_class, $status ) = @_; | |||||||||||||||||||||||||||
| 125 | 0 | $status->{class} = $app_class; | |||||||||||||||||||||||||||
| 126 | 0 | eval "require $app_class"; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | $status->{is_ok} = 'no'; | |||||||||||||||||||||||||||
| 129 | 0 | $status->{message} = "Failed to require '$app_class': $@"; | |||||||||||||||||||||||||||
| 130 | 0 | return; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 0 | my $app = $app_class->new(); | |||||||||||||||||||||||||||
| 133 | 0 | my $name = $app->name; | |||||||||||||||||||||||||||
| 134 | 0 | my $version = $app->version; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # put this off so we don't load older versions... | ||||||||||||||||||||||||||||
| 137 | 0 | $self->_setup_context({ skip => 'read packages' }); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $is_installed = $self->_check_package_exists( | |||||||||||||||||||||||||||
| 140 | $name, $version, $status ); | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return if ( $is_installed ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | my $brick_name = $app->get_brick_name(); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | unless ( $brick_name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | oi_error "Cannot install from class $app_class - it does not have ", | |||||||||||||||||||||||||||
| 146 | "method 'get_brick_name()' defined."; | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | my $brick = OpenInteract2::Brick->new( $brick_name ); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | my $base_pkg_dir = CTX->lookup_directory( 'package' ); | |||||||||||||||||||||||||||
| 151 | 0 | my $pkg_dir = catdir( $base_pkg_dir, "$name-$version" ); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | $brick->copy_all_resources_to( $pkg_dir ); | |||||||||||||||||||||||||||
| 154 | 0 | my $repository = CTX->repository; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # the package directory is stocked, so instantiate | ||||||||||||||||||||||||||||
| 157 | 0 | my $package = OpenInteract2::Package->new({ | |||||||||||||||||||||||||||
| 158 | directory => $pkg_dir, | ||||||||||||||||||||||||||||
| 159 | repository => $repository, | ||||||||||||||||||||||||||||
| 160 | }); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # ...and copy the conf/ files to the site as working copies | ||||||||||||||||||||||||||||
| 163 | 0 | $package->copy_configuration_to_website(); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | $repository->add_package( $package ); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | $status->{is_ok} = 'yes'; | |||||||||||||||||||||||||||
| 168 | 0 | $status->{package} = $name; | |||||||||||||||||||||||||||
| 169 | 0 | $status->{version} = $version; | |||||||||||||||||||||||||||
| 170 | 0 | $status->{message} = sprintf( | |||||||||||||||||||||||||||
| 171 | 'Installed package %s-%s to website %s', | ||||||||||||||||||||||||||||
| 172 | $name, $version, $self->param( 'website_dir' ) | ||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | $self->notify_observers( | |||||||||||||||||||||||||||
| 176 | progress => "Finished with installation of $name-$version" ); | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub _check_package_exists { | ||||||||||||||||||||||||||
|
Subroutine
_check_package_exists: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 180 | 0 | my ( $self, $name, $version, $status ) = @_; | |||||||||||||||||||||||||||
| 181 | 0 | my $repository = CTX->repository; | |||||||||||||||||||||||||||
| 182 | 0 | my $info = $repository->get_package_info( $name ); | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( $info && $info->{version} == $version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info and $info->{"version"} == $version
MC/DC0%0/2
$info and $info->{"version"} == $version
$info
$info->{"version"} == $version
Truth table0%0/3
A and B
A= $infoB= $info->{"version"} == $version
| |||||||||||||||||||||||||||||
| 184 | 0 | $status->{is_ok} = 'yes'; | |||||||||||||||||||||||||||
| 185 | 0 | $status->{package} = $name; | |||||||||||||||||||||||||||
| 186 | 0 | $status->{version} = $version; | |||||||||||||||||||||||||||
| 187 | 0 | $status->{message} = sprintf( | |||||||||||||||||||||||||||
| 188 | 'Package %s-%s not upgraded, this version already installed', | ||||||||||||||||||||||||||||
| 189 | $name, $version | ||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||
| 191 | 0 | return 1; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | return 0; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # Let the site know that a new package has been installed by creating | ||||||||||||||||||||||||||||
| 198 | # the 'refresh' file for the temporary library | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub _create_temp_lib_refresh { | ||||||||||||||||||||||||||
|
Subroutine
_create_temp_lib_refresh: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 201 | 0 | my ( $self, $package_name ) = @_; | |||||||||||||||||||||||||||
| 202 | 0 | my $temp_lib_dir = CTX->lookup_temp_lib_directory; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | return unless ( -d $temp_lib_dir ); # nothing to refresh! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | my $refresh_file = catfile( | |||||||||||||||||||||||||||
| 205 | $temp_lib_dir, CTX->lookup_temp_lib_refresh_filename | ||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return if ( -f $refresh_file ); # someone already refreshed! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | open( REFRESH, '>', $refresh_file ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | || die "Cannot open refresh file: $!"; | ||||||||||||||||||||||||||||
| 210 | 0 | print REFRESH "Forced refresh from package '$package_name' ", | |||||||||||||||||||||||||||
| 211 | "installed on ", scalar( localtime ); | ||||||||||||||||||||||||||||
| 212 | 0 | close( REFRESH ); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 87 | OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 87 | 1; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | __END__ | ||||||||||||||||||||||||||||