Lines 25-35
use List::MoreUtils qw(any);
Link Here
|
25 |
use Module::Load qw(load); |
25 |
use Module::Load qw(load); |
26 |
use Module::Load::Conditional qw(can_load); |
26 |
use Module::Load::Conditional qw(can_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 |
use YAML qw(LoadFile); |
28 |
use YAML qw(Load Dump); |
29 |
|
29 |
|
30 |
use C4::Context; |
30 |
use C4::Context; |
31 |
use C4::Output; |
31 |
use C4::Output; |
32 |
use Koha::Plugins::Methods; |
32 |
use Koha::Plugins::Methods; |
|
|
33 |
use Koha::Plugins::Data; |
33 |
|
34 |
|
34 |
our @pluginsdir; |
35 |
our @pluginsdir; |
35 |
|
36 |
|
Lines 131-159
sub GetPluginsMetadata {
Link Here
|
131 |
} |
132 |
} |
132 |
)->_resultset->get_column('plugin_class'); |
133 |
)->_resultset->get_column('plugin_class'); |
133 |
|
134 |
|
134 |
my @metafiles = File::Find::Rule->file()->name('PLUGIN.yml')->in( @pluginsdir ); |
|
|
135 |
|
136 |
my @plugins; |
135 |
my @plugins; |
137 |
while ( my $plugin_class = $plugin_classes->next ) { |
136 |
while ( my $plugin_class = $plugin_classes->next ) { |
138 |
my $plugin_path = $plugin_class; |
137 |
my $plugin_metadata = Koha::Plugins::Data->find( |
139 |
$plugin_path =~ s/::/\//g; # Take class name, transform :: to / to get path |
138 |
{ |
140 |
my $yaml_to_find = "$plugin_path/PLUGIN.yml"; |
139 |
plugin_class => $plugin_class, |
141 |
$plugin_path =~ s/$/.pm/; # Add .pm to the end |
140 |
plugin_key => 'metadata', |
142 |
|
141 |
} |
143 |
# Find the full path to the file, it's somewhere in the list of metafiles we found when this module as loaded |
142 |
); |
144 |
my ( $meta_yaml ) = grep { $yaml_to_find eq substr( $_, -length($yaml_to_find) ) } @metafiles; |
|
|
145 |
|
146 |
my $plugin_metadata; |
147 |
if ( -r $meta_yaml ) { # If the metafile exists and is readable, use it |
148 |
$plugin_metadata = YAML::LoadFile($meta_yaml); |
149 |
} else { # Fall back to loading the plugin to get the metadata if there is no PLUGIN.yml file to read |
150 |
load $plugin_class; |
151 |
my $plugin = $plugin_class->new({ |
152 |
enable_plugins => $self->{'enable_plugins'} |
153 |
}); |
154 |
|
143 |
|
155 |
# filter the plugin out by metadata |
144 |
if ( $plugin_metadata ) { |
|
|
145 |
$plugin_metadata = YAML::Load( $plugin_metadata->plugin_value ); |
146 |
} |
147 |
else { |
148 |
load $plugin_class; |
149 |
my $plugin = $plugin_class->new( |
150 |
{ |
151 |
enable_plugins => $self->{enable_plugins} |
152 |
} |
153 |
); |
156 |
$plugin_metadata = $plugin->get_metadata; |
154 |
$plugin_metadata = $plugin->get_metadata; |
|
|
155 |
|
156 |
Koha::Plugins::Datum->new( |
157 |
{ |
158 |
plugin_class => $plugin_class, |
159 |
plugin_key => 'metadata', |
160 |
plugin_value => YAML::Dump( $plugin_metadata ), |
161 |
} |
162 |
); |
157 |
} |
163 |
} |
158 |
|
164 |
|
159 |
next |
165 |
next |
Lines 193-198
sub InstallPlugins {
Link Here
|
193 |
|
199 |
|
194 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
200 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
195 |
|
201 |
|
|
|
202 |
# Force update plugin metadata in the database |
203 |
my $metadata = $plugin->get_metadata( { skip_database => 1 } ); |
204 |
my $params = { |
205 |
plugin_class => $plugin_class, |
206 |
plugin_key => 'metadata', |
207 |
}; |
208 |
my $db_metadata = Koha::Plugins::Data->find( $params ) || Koha::Plugins::Datum->new( $params ); |
209 |
$db_metadata->plugin_value( YAML::Dump($metadata) ); |
210 |
$db_metadata->store(); |
211 |
|
196 |
Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); |
212 |
Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); |
197 |
|
213 |
|
198 |
foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) { |
214 |
foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) { |