Lines 81-87
sub call {
Link Here
|
81 |
return unless C4::Context->config('enable_plugins'); |
81 |
return unless C4::Context->config('enable_plugins'); |
82 |
|
82 |
|
83 |
my @responses; |
83 |
my @responses; |
84 |
my @plugins = $class->get_enabled_plugins(); |
84 |
my @plugins = $class->get_enabled_plugins( { verbose => 0 } ); |
85 |
@plugins = grep { $_->can($method) } @plugins; |
85 |
@plugins = grep { $_->can($method) } @plugins; |
86 |
|
86 |
|
87 |
# TODO: Remove warn when after_hold_create is removed from the codebase |
87 |
# TODO: Remove warn when after_hold_create is removed from the codebase |
Lines 167-173
sub feature_enabled {
Link Here
|
167 |
my $key = "ENABLED_PLUGIN_FEATURE_" . $method; |
167 |
my $key = "ENABLED_PLUGIN_FEATURE_" . $method; |
168 |
my $feature = Koha::Cache::Memory::Lite->get_from_cache($key); |
168 |
my $feature = Koha::Cache::Memory::Lite->get_from_cache($key); |
169 |
unless ( defined($feature) ) { |
169 |
unless ( defined($feature) ) { |
170 |
my @plugins = $class->get_enabled_plugins(); |
170 |
my @plugins = $class->get_enabled_plugins( { verbose => 0 } ); |
171 |
my $enabled = any { $_->can($method) } @plugins; |
171 |
my $enabled = any { $_->can($method) } @plugins; |
172 |
Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled ); |
172 |
Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled ); |
173 |
} |
173 |
} |
Lines 182-193
method or metadata value.
Link Here
|
182 |
my @plugins = Koha::Plugins::GetPlugins({ |
182 |
my @plugins = Koha::Plugins::GetPlugins({ |
183 |
method => 'some_method', |
183 |
method => 'some_method', |
184 |
metadata => { some_key => 'some_value' }, |
184 |
metadata => { some_key => 'some_value' }, |
185 |
[ verbose => 1 ], |
185 |
[ all => 1, errors => 1, verbose => 1 ], |
186 |
}); |
186 |
}); |
187 |
|
187 |
|
188 |
The method and metadata parameters are optional. |
188 |
The method and metadata parameters are optional. |
189 |
If you pass multiple keys in the metadata hash, all keys must match. |
189 |
If you pass multiple keys in the metadata hash, all keys must match. |
190 |
|
190 |
|
|
|
191 |
If you pass errors (only used in plugins-home), we return two arrayrefs: |
192 |
|
193 |
( $good, $bad ) = Koha::Plugins::GetPlugins( { errors => 1 } ); |
194 |
|
195 |
If you pass verbose, you can enable or disable explicitly warnings |
196 |
from Module::Load::Conditional. Disabled by default to not flood |
197 |
the logs. |
198 |
|
191 |
=cut |
199 |
=cut |
192 |
|
200 |
|
193 |
sub GetPlugins { |
201 |
sub GetPlugins { |
Lines 195-201
sub GetPlugins {
Link Here
|
195 |
|
203 |
|
196 |
my $method = $params->{method}; |
204 |
my $method = $params->{method}; |
197 |
my $req_metadata = $params->{metadata} // {}; |
205 |
my $req_metadata = $params->{metadata} // {}; |
198 |
my $verbose = delete $params->{verbose} // $self->_verbose; |
206 |
my $errors = $params->{errors}; |
|
|
207 |
|
208 |
# By default dont warn here unless asked to do so. |
209 |
my $verbose = $params->{verbose} // 0; |
199 |
|
210 |
|
200 |
my $filter = ( $method ) ? { plugin_method => $method } : undef; |
211 |
my $filter = ( $method ) ? { plugin_method => $method } : undef; |
201 |
|
212 |
|
Lines 206-216
sub GetPlugins {
Link Here
|
206 |
} |
217 |
} |
207 |
)->_resultset->get_column('plugin_class'); |
218 |
)->_resultset->get_column('plugin_class'); |
208 |
|
219 |
|
209 |
my @plugins; |
|
|
210 |
|
220 |
|
211 |
# Loop through all plugins that implement at least a method |
221 |
# Loop through all plugins that implement at least a method |
|
|
222 |
my ( @plugins, @failing ); |
212 |
while ( my $plugin_class = $plugin_classes->next ) { |
223 |
while ( my $plugin_class = $plugin_classes->next ) { |
213 |
|
|
|
214 |
if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) { |
224 |
if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) { |
215 |
|
225 |
|
216 |
my $plugin; |
226 |
my $plugin; |
Lines 241-253
sub GetPlugins {
Link Here
|
241 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
251 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
242 |
|
252 |
|
243 |
push @plugins, $plugin; |
253 |
push @plugins, $plugin; |
244 |
} elsif ( defined($params->{errors}) && $params->{errors} ){ |
254 |
} elsif( $errors ) { |
245 |
push @plugins, { error => 'cannot_load', name => $plugin_class }; |
255 |
push @failing, { error => 1, name => $plugin_class }; |
246 |
} |
256 |
} |
247 |
|
|
|
248 |
} |
257 |
} |
249 |
|
258 |
|
250 |
return @plugins; |
259 |
return $errors ? ( \@plugins, \@failing ) : @plugins; |
251 |
} |
260 |
} |
252 |
|
261 |
|
253 |
=head2 InstallPlugins |
262 |
=head2 InstallPlugins |