|
Lines 30-35
use Try::Tiny;
Link Here
|
| 30 |
use C4::Context; |
30 |
use C4::Context; |
| 31 |
use C4::Output; |
31 |
use C4::Output; |
| 32 |
|
32 |
|
|
|
33 |
use Koha::Cache::Memory::Lite; |
| 33 |
use Koha::Exceptions::Plugin; |
34 |
use Koha::Exceptions::Plugin; |
| 34 |
use Koha::Plugins::Methods; |
35 |
use Koha::Plugins::Methods; |
| 35 |
|
36 |
|
|
Lines 74-95
updated by preceding plugins, provided that these plugins support that.
Link Here
|
| 74 |
sub call { |
75 |
sub call { |
| 75 |
my ($class, $method, @args) = @_; |
76 |
my ($class, $method, @args) = @_; |
| 76 |
|
77 |
|
|
|
78 |
return unless C4::Context->config('enable_plugins'); |
| 79 |
|
| 77 |
my @responses; |
80 |
my @responses; |
| 78 |
if (C4::Context->config('enable_plugins')) { |
81 |
my @plugins = $class->get_enabled_plugins(); |
| 79 |
my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method }); |
82 |
@plugins = grep { $_->can($method) } @plugins; |
| 80 |
@plugins = grep { $_->can($method) } @plugins; |
83 |
foreach my $plugin (@plugins) { |
| 81 |
foreach my $plugin (@plugins) { |
84 |
my $response = eval { $plugin->$method(@args) }; |
| 82 |
my $response = eval { $plugin->$method(@args) }; |
85 |
if ($@) { |
| 83 |
if ($@) { |
86 |
warn sprintf("Plugin error (%s): %s", $plugin->get_metadata->{name}, $@); |
| 84 |
warn sprintf("Plugin error (%s): %s", $plugin->get_metadata->{name}, $@); |
87 |
next; |
|
|
88 |
} |
| 89 |
|
| 90 |
push @responses, $response; |
| 91 |
} |
| 92 |
|
| 93 |
return @responses; |
| 94 |
} |
| 95 |
|
| 96 |
sub get_enabled_plugins { |
| 97 |
my ($class) = @_; |
| 98 |
|
| 99 |
return unless C4::Context->config('enable_plugins'); |
| 100 |
|
| 101 |
my $cache_key = 'enabled_plugins'; |
| 102 |
my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache($cache_key); |
| 103 |
unless ($enabled_plugins) { |
| 104 |
$enabled_plugins = []; |
| 105 |
my $rs = Koha::Database->schema->resultset('PluginData'); |
| 106 |
$rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 }); |
| 107 |
my @plugin_classes = $rs->get_column('plugin_class')->all(); |
| 108 |
foreach my $plugin_class (@plugin_classes) { |
| 109 |
unless (can_load(modules => { $plugin_class => undef }, nocache => 1)) { |
| 110 |
warn "Failed to load $plugin_class: $Module::Load::Conditional::ERROR"; |
| 85 |
next; |
111 |
next; |
| 86 |
} |
112 |
} |
| 87 |
|
113 |
|
| 88 |
push @responses, $response; |
114 |
my $plugin = eval { $plugin_class->new() }; |
| 89 |
} |
115 |
if ($@ || !$plugin) { |
|
|
116 |
warn "Failed to instantiate plugin $plugin_class: $@"; |
| 117 |
next; |
| 118 |
} |
| 90 |
|
119 |
|
|
|
120 |
push @$enabled_plugins, $plugin; |
| 121 |
} |
| 122 |
Koha::Cache::Memory::Lite->set_in_cache($cache_key, $enabled_plugins); |
| 91 |
} |
123 |
} |
| 92 |
return @responses; |
124 |
|
|
|
125 |
return @$enabled_plugins; |
| 93 |
} |
126 |
} |
| 94 |
|
127 |
|
| 95 |
=head2 GetPlugins |
128 |
=head2 GetPlugins |