|
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 160-166
sub feature_enabled {
Link Here
|
| 160 |
my $key = "ENABLED_PLUGIN_FEATURE_" . $method; |
160 |
my $key = "ENABLED_PLUGIN_FEATURE_" . $method; |
| 161 |
my $feature = Koha::Cache::Memory::Lite->get_from_cache($key); |
161 |
my $feature = Koha::Cache::Memory::Lite->get_from_cache($key); |
| 162 |
unless ( defined($feature) ) { |
162 |
unless ( defined($feature) ) { |
| 163 |
my @plugins = $class->get_enabled_plugins(); |
163 |
my @plugins = $class->get_enabled_plugins( { verbose => 0 } ); |
| 164 |
my $enabled = any { $_->can($method) } @plugins; |
164 |
my $enabled = any { $_->can($method) } @plugins; |
| 165 |
Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled ); |
165 |
Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled ); |
| 166 |
} |
166 |
} |
|
Lines 175-186
method or metadata value.
Link Here
|
| 175 |
my @plugins = Koha::Plugins::GetPlugins({ |
175 |
my @plugins = Koha::Plugins::GetPlugins({ |
| 176 |
method => 'some_method', |
176 |
method => 'some_method', |
| 177 |
metadata => { some_key => 'some_value' }, |
177 |
metadata => { some_key => 'some_value' }, |
| 178 |
[ verbose => 1 ], |
178 |
[ all => 1, errors => 1, verbose => 1 ], |
| 179 |
}); |
179 |
}); |
| 180 |
|
180 |
|
| 181 |
The method and metadata parameters are optional. |
181 |
The method and metadata parameters are optional. |
| 182 |
If you pass multiple keys in the metadata hash, all keys must match. |
182 |
If you pass multiple keys in the metadata hash, all keys must match. |
| 183 |
|
183 |
|
|
|
184 |
If you pass errors (only used in plugins-home), we return two arrayrefs: |
| 185 |
|
| 186 |
( $good, $bad ) = Koha::Plugins::GetPlugins( { errors => 1 } ); |
| 187 |
|
| 188 |
If you pass verbose, you can enable or disable explicitly warnings |
| 189 |
from Module::Load::Conditional. Disabled by default to not flood |
| 190 |
the logs. |
| 191 |
|
| 184 |
=cut |
192 |
=cut |
| 185 |
|
193 |
|
| 186 |
sub GetPlugins { |
194 |
sub GetPlugins { |
|
Lines 188-194
sub GetPlugins {
Link Here
|
| 188 |
|
196 |
|
| 189 |
my $method = $params->{method}; |
197 |
my $method = $params->{method}; |
| 190 |
my $req_metadata = $params->{metadata} // {}; |
198 |
my $req_metadata = $params->{metadata} // {}; |
| 191 |
my $verbose = delete $params->{verbose} // $self->_verbose; |
199 |
my $errors = $params->{errors}; |
|
|
200 |
|
| 201 |
# By default dont warn here unless asked to do so. |
| 202 |
my $verbose = $params->{verbose} // 0; |
| 192 |
|
203 |
|
| 193 |
my $filter = ( $method ) ? { plugin_method => $method } : undef; |
204 |
my $filter = ( $method ) ? { plugin_method => $method } : undef; |
| 194 |
|
205 |
|
|
Lines 199-209
sub GetPlugins {
Link Here
|
| 199 |
} |
210 |
} |
| 200 |
)->_resultset->get_column('plugin_class'); |
211 |
)->_resultset->get_column('plugin_class'); |
| 201 |
|
212 |
|
| 202 |
my @plugins; |
|
|
| 203 |
|
213 |
|
| 204 |
# Loop through all plugins that implement at least a method |
214 |
# Loop through all plugins that implement at least a method |
|
|
215 |
my ( @plugins, @failing ); |
| 205 |
while ( my $plugin_class = $plugin_classes->next ) { |
216 |
while ( my $plugin_class = $plugin_classes->next ) { |
| 206 |
|
|
|
| 207 |
if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) { |
217 |
if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) { |
| 208 |
|
218 |
|
| 209 |
my $plugin; |
219 |
my $plugin; |
|
Lines 234-246
sub GetPlugins {
Link Here
|
| 234 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
244 |
and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; |
| 235 |
|
245 |
|
| 236 |
push @plugins, $plugin; |
246 |
push @plugins, $plugin; |
| 237 |
} elsif ( defined($params->{errors}) && $params->{errors} ){ |
247 |
} elsif( $errors ) { |
| 238 |
push @plugins, { error => 'cannot_load', name => $plugin_class }; |
248 |
push @failing, { error => 1, name => $plugin_class }; |
| 239 |
} |
249 |
} |
| 240 |
|
|
|
| 241 |
} |
250 |
} |
| 242 |
|
251 |
|
| 243 |
return @plugins; |
252 |
return $errors ? ( \@plugins, \@failing ) : @plugins; |
| 244 |
} |
253 |
} |
| 245 |
|
254 |
|
| 246 |
=head2 InstallPlugins |
255 |
=head2 InstallPlugins |