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 |
|
85 |
my $plugin_enabled = $plugin->retrieve_data('__ENABLED__'); |
86 |
$plugin->{enabled} = $plugin_enabled; |
87 |
|
88 |
# Want all plugins. Not only enabled ones. |
89 |
if ( defined($params->{all}) && $params->{all} ) { |
90 |
$plugin_enabled = 1; |
91 |
} |
92 |
|
93 |
next unless $plugin_enabled; |
94 |
|
95 |
push @plugins, $plugin; |
96 |
} |
97 |
return @plugins; |
98 |
} |
99 |
|
100 |
=head2 |
101 |
|
102 |
Koha::Plugins::InstallPlugins() |
103 |
|
104 |
This method iterates through all plugins physically present on a system. |
105 |
For each plugin module found, it will test that the plugin can be loaded, |
106 |
and if it can, will store its available methods in the plugin_methods table. |
107 |
|
108 |
=cut |
109 |
|
110 |
sub InstallPlugins { |
111 |
my ( $self, $params ) = @_; |
112 |
|
73 |
my @plugin_classes = $self->plugins(); |
113 |
my @plugin_classes = $self->plugins(); |
74 |
my @plugins; |
114 |
my @plugins; |
75 |
|
115 |
|
Lines 79-100
sub GetPlugins {
Link Here
|
79 |
|
119 |
|
80 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
120 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
81 |
|
121 |
|
82 |
my $plugin_enabled = $plugin->retrieve_data('__ENABLED__'); |
122 |
Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); |
83 |
$plugin->{enabled} = $plugin_enabled; |
|
|
84 |
|
123 |
|
85 |
# Want all plugins. Not only enabled ones. |
124 |
foreach my $method ( @{ Class::Inspector->methods($plugin_class) } ) { |
86 |
if ( defined($params->{all}) && $params->{all} ) { |
125 |
Koha::Plugins::Method->new( |
87 |
$plugin_enabled = 1; |
126 |
{ |
|
|
127 |
plugin_class => $plugin_class, |
128 |
plugin_method => $method, |
129 |
} |
130 |
)->store(); |
88 |
} |
131 |
} |
89 |
|
132 |
|
90 |
next unless $plugin_enabled; |
|
|
91 |
|
92 |
# Limit results by method or metadata |
93 |
next if $method && !$plugin->can($method); |
94 |
my $plugin_metadata = $plugin->get_metadata; |
95 |
next if $plugin_metadata |
96 |
and %$req_metadata |
97 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
98 |
push @plugins, $plugin; |
133 |
push @plugins, $plugin; |
99 |
} else { |
134 |
} else { |
100 |
my $error = $Module::Load::Conditional::ERROR; |
135 |
my $error = $Module::Load::Conditional::ERROR; |