View | Details | Raw Unified | Return to bug 29121
Collapse All | Expand All

(-)a/Koha/Plugins.pm (-7 / +32 lines)
Lines 25-34 use List::MoreUtils qw( any ); Link Here
25
use Module::Load::Conditional qw( can_load );
25
use Module::Load::Conditional qw( can_load );
26
use Module::Load;
26
use Module::Load;
27
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
27
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
28
28
use Try::Tiny;
29
29
30
use C4::Context;
30
use C4::Context;
31
use C4::Output;
31
use C4::Output;
32
33
use Koha::Exceptions::Plugin;
32
use Koha::Plugins::Methods;
34
use Koha::Plugins::Methods;
33
35
34
BEGIN {
36
BEGIN {
Lines 120-130 sub GetPlugins { Link Here
120
    while ( my $plugin_class = $plugin_classes->next ) {
122
    while ( my $plugin_class = $plugin_classes->next ) {
121
123
122
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
124
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
123
            my $plugin = $plugin_class->new({
125
124
                enable_plugins => $self->{'enable_plugins'}
126
            my $plugin;
125
                    # loads even if plugins are disabled
127
            my $failed_instantiation;
126
                    # FIXME: is this for testing without bothering to mock config?
128
127
            });
129
            try {
130
                $plugin = $plugin_class->new({
131
                    enable_plugins => $self->{'enable_plugins'}
132
                        # loads even if plugins are disabled
133
                        # FIXME: is this for testing without bothering to mock config?
134
                });
135
            }
136
            catch {
137
                warn "$_";
138
                $failed_instantiation = 1;
139
            };
140
141
            next if $failed_instantiation;
128
142
129
            next unless $plugin->is_enabled or
143
            next unless $plugin->is_enabled or
130
                        defined($params->{all}) && $params->{all};
144
                        defined($params->{all}) && $params->{all};
Lines 169-175 sub InstallPlugins { Link Here
169
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
183
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
170
            next unless $plugin_class->isa('Koha::Plugins::Base');
184
            next unless $plugin_class->isa('Koha::Plugins::Base');
171
185
172
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
186
            my $plugin;
187
            my $failed_instantiation;
188
189
            try {
190
                $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
191
            }
192
            catch {
193
                warn "$_";
194
                $failed_instantiation = 1;
195
            };
196
197
            next if $failed_instantiation;
173
198
174
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
199
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
175
200
(-)a/Koha/Plugins/Base.pm (-11 / +23 lines)
Lines 21-32 use Modern::Perl; Link Here
21
21
22
use Cwd qw( abs_path );
22
use Cwd qw( abs_path );
23
use List::Util qw( max );
23
use List::Util qw( max );
24
use Try::Tiny;
24
25
25
use base qw{Module::Bundled::Files};
26
use base qw{Module::Bundled::Files};
26
27
27
use C4::Context;
28
use C4::Context;
28
use C4::Output qw( output_with_http_headers );
29
use C4::Output qw( output_with_http_headers );
29
30
31
use Koha::Exceptions::Plugin;
32
30
=head1 NAME
33
=head1 NAME
31
34
32
Koha::Plugins::Base - Base Module for plugins
35
Koha::Plugins::Base - Base Module for plugins
Lines 48-68 sub new { Link Here
48
51
49
    ## Run the installation method if it exists and hasn't been run before
52
    ## Run the installation method if it exists and hasn't been run before
50
    if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) {
53
    if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) {
51
        if ( $self->install() ) {
54
        try {
52
            $self->store_data( { '__INSTALLED__' => 1, '__ENABLED__' => 1 } );
55
            if ( $self->install() ) {
53
            if ( my $version = $plugin_version ) {
56
                $self->store_data( { '__INSTALLED__' => 1, '__ENABLED__' => 1 } );
54
                $self->store_data({ '__INSTALLED_VERSION__' => $version });
57
                if ( my $version = $plugin_version ) {
58
                    $self->store_data({ '__INSTALLED_VERSION__' => $version });
59
                }
60
            } else {
61
                warn "Plugin $class failed during installation!";
55
            }
62
            }
56
        } else {
57
            warn "Plugin $class failed during installation!";
58
        }
63
        }
64
        catch {
65
            Koha::Exceptions::Plugin::InstallDied->throw( plugin_class => $class );
66
        };
59
    } elsif ( $self->can('upgrade') ) {
67
    } elsif ( $self->can('upgrade') ) {
60
        if ( _version_compare( $plugin_version, $database_version ) == 1 ) {
68
        if ( _version_compare( $plugin_version, $database_version ) == 1 ) {
61
            if ( $self->upgrade() ) {
69
            try {
62
                $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
70
                if ( $self->upgrade() ) {
63
            } else {
71
                    $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
64
                warn "Plugin $class failed during upgrade!";
72
                } else {
73
                    warn "Plugin $class failed during upgrade!";
74
                }
65
            }
75
            }
76
            catch {
77
                Koha::Exceptions::Plugin::UpgradeDied->throw( plugin_class => $class );
78
            };
66
        }
79
        }
67
    } elsif ( $plugin_version ne $database_version ) {
80
    } elsif ( $plugin_version ne $database_version ) {
68
        $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
81
        $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
69
- 

Return to bug 29121