Lines 19-30
package Koha::Plugins;
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
|
|
22 |
use Class::Inspector; |
23 |
use List::MoreUtils qw( any ); |
22 |
use Module::Load::Conditional qw(can_load); |
24 |
use Module::Load::Conditional qw(can_load); |
|
|
25 |
use Module::Load qw(load); |
23 |
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; |
26 |
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; |
24 |
use List::MoreUtils qw( any ); |
|
|
25 |
|
27 |
|
26 |
use C4::Context; |
28 |
use C4::Context; |
27 |
use C4::Output; |
29 |
use C4::Output; |
|
|
30 |
use Koha::Plugins::Methods; |
28 |
|
31 |
|
29 |
BEGIN { |
32 |
BEGIN { |
30 |
my $pluginsdir = C4::Context->config("pluginsdir"); |
33 |
my $pluginsdir = C4::Context->config("pluginsdir"); |
Lines 70-75
sub GetPlugins {
Link Here
|
70 |
my $method = $params->{method}; |
73 |
my $method = $params->{method}; |
71 |
my $req_metadata = $params->{metadata} // {}; |
74 |
my $req_metadata = $params->{metadata} // {}; |
72 |
|
75 |
|
|
|
76 |
my $dbh = C4::Context->dbh; |
77 |
my $plugin_classes = $dbh->selectcol_arrayref('SELECT DISTINCT(plugin_class) FROM plugin_methods'); |
78 |
my @plugins; |
79 |
|
80 |
foreach my $plugin_class (@$plugin_classes) { |
81 |
next if $method && !Koha::Plugins::Methods->search({ plugin_class => $plugin_class, plugin_method => $method })->count; |
82 |
load $plugin_class; |
83 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
84 |
push @plugins, $plugin; |
85 |
} |
86 |
return @plugins; |
87 |
} |
88 |
|
89 |
=head2 |
90 |
|
91 |
Koha::Plugins::InstallPlugins() |
92 |
|
93 |
This method iterates through all plugins physically present on a system. |
94 |
For each plugin module found, it will test that the plugin can be loaded, |
95 |
and if it can, will store its available methods in the plugin_methods table. |
96 |
|
97 |
=cut |
98 |
|
99 |
sub InstallPlugins { |
100 |
my ( $self, $params ) = @_; |
101 |
|
73 |
my @plugin_classes = $self->plugins(); |
102 |
my @plugin_classes = $self->plugins(); |
74 |
my @plugins; |
103 |
my @plugins; |
75 |
|
104 |
|
Lines 79-90
sub GetPlugins {
Link Here
|
79 |
|
108 |
|
80 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
109 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
81 |
|
110 |
|
82 |
# Limit results by method or metadata |
111 |
Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); |
83 |
next if $method && !$plugin->can($method); |
112 |
|
84 |
my $plugin_metadata = $plugin->get_metadata; |
113 |
foreach my $method ( @{ Class::Inspector->methods($plugin_class) } ) { |
85 |
next if $plugin_metadata |
114 |
Koha::Plugins::Method->new( |
86 |
and %$req_metadata |
115 |
{ |
87 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
116 |
plugin_class => $plugin_class, |
|
|
117 |
plugin_method => $method, |
118 |
} |
119 |
)->store(); |
120 |
} |
121 |
|
88 |
push @plugins, $plugin; |
122 |
push @plugins, $plugin; |
89 |
} else { |
123 |
} else { |
90 |
my $error = $Module::Load::Conditional::ERROR; |
124 |
my $error = $Module::Load::Conditional::ERROR; |