@@ -, +, @@ plugins ->new on a plugin eventually triggers a call to ->install (this has die "plugin, die!"; $ koha-mysql kohadev > DELETE FROM plugin_data; $ kshell k$ prove t/db_dependent/Koha/Plugins/Plugins.t \ t/Koha/Exceptions.t $ restart_all $ kshell k$ perl misc/devel/install_plugins.pl --- Koha/Plugins.pm | 39 ++++++++++++++++++++++++++++++++------- Koha/Plugins/Base.pm | 33 +++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 17 deletions(-) --- a/Koha/Plugins.pm +++ a/Koha/Plugins.pm @@ -25,10 +25,12 @@ use List::MoreUtils qw( any ); use Module::Load::Conditional qw( can_load ); use Module::Load; use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; - +use Try::Tiny; use C4::Context; use C4::Output; + +use Koha::Exceptions::Plugin; use Koha::Plugins::Methods; BEGIN { @@ -120,11 +122,23 @@ sub GetPlugins { while ( my $plugin_class = $plugin_classes->next ) { if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { - my $plugin = $plugin_class->new({ - enable_plugins => $self->{'enable_plugins'} - # loads even if plugins are disabled - # FIXME: is this for testing without bothering to mock config? - }); + + my $plugin; + my $failed_instantiation; + + try { + $plugin = $plugin_class->new({ + enable_plugins => $self->{'enable_plugins'} + # loads even if plugins are disabled + # FIXME: is this for testing without bothering to mock config? + }); + } + catch { + warn "$_"; + $failed_instantiation = 1; + }; + + next if $failed_instantiation; next unless $plugin->is_enabled or defined($params->{all}) && $params->{all}; @@ -169,7 +183,18 @@ sub InstallPlugins { if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { next unless $plugin_class->isa('Koha::Plugins::Base'); - my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); + my $plugin; + my $failed_instantiation; + + try { + $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); + } + catch { + warn "$_"; + $failed_instantiation = 1; + }; + + next if $failed_instantiation; Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); --- a/Koha/Plugins/Base.pm +++ a/Koha/Plugins/Base.pm @@ -21,12 +21,15 @@ use Modern::Perl; use Cwd qw( abs_path ); use List::Util qw( max ); +use Try::Tiny; use base qw{Module::Bundled::Files}; use C4::Context; use C4::Output qw( output_with_http_headers ); +use Koha::Exceptions::Plugin; + =head1 NAME Koha::Plugins::Base - Base Module for plugins @@ -48,21 +51,31 @@ sub new { ## Run the installation method if it exists and hasn't been run before if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) { - if ( $self->install() ) { - $self->store_data( { '__INSTALLED__' => 1, '__ENABLED__' => 1 } ); - if ( my $version = $plugin_version ) { - $self->store_data({ '__INSTALLED_VERSION__' => $version }); + try { + if ( $self->install() ) { + $self->store_data( { '__INSTALLED__' => 1, '__ENABLED__' => 1 } ); + if ( my $version = $plugin_version ) { + $self->store_data({ '__INSTALLED_VERSION__' => $version }); + } + } else { + warn "Plugin $class failed during installation!"; } - } else { - warn "Plugin $class failed during installation!"; } + catch { + Koha::Exceptions::Plugin::InstallDied->throw( plugin_class => $class ); + }; } elsif ( $self->can('upgrade') ) { if ( _version_compare( $plugin_version, $database_version ) == 1 ) { - if ( $self->upgrade() ) { - $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version }); - } else { - warn "Plugin $class failed during upgrade!"; + try { + if ( $self->upgrade() ) { + $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version }); + } else { + warn "Plugin $class failed during upgrade!"; + } } + catch { + Koha::Exceptions::Plugin::UpgradeDied->throw( plugin_class => $class ); + }; } } elsif ( $plugin_version ne $database_version ) { $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version }); --