View | Details | Raw Unified | Return to bug 31503
Collapse All | Expand All

(-)a/Koha/Plugins.pm (+24 lines)
Lines 139-144 sub get_enabled_plugins { Link Here
139
    return @$enabled_plugins;
139
    return @$enabled_plugins;
140
}
140
}
141
141
142
143
=head2 feature_enabled
144
145
Returns a boolean denoting whether a plugin based feature is enabled or not.
146
147
    $enabled = Koha::Plugins->feature_enabled('method_name');
148
149
=cut
150
151
sub feature_enabled {
152
    my ( $class, $method ) = @_;
153
154
    return 0 unless C4::Context->config('enable_plugins');
155
156
    my $key     = "ENABLED_PLUGIN_FEATURE_" . $method;
157
    my $feature = Koha::Cache::Memory::Lite->get_from_cache($key);
158
    unless ( defined($feature) ) {
159
        my @plugins = $class->get_enabled_plugins();
160
        my $enabled = any { $_->can($method) } @plugins;
161
        Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled );
162
    }
163
    return $feature;
164
}
165
142
=head2 GetPlugins
166
=head2 GetPlugins
143
167
144
This will return a list of all available plugins, optionally limited by
168
This will return a list of all available plugins, optionally limited by
(-)a/Koha/Template/Plugin/KohaPlugins.pm (+17 lines)
Lines 282-285 sub get_plugins_opac_cover_images { Link Here
282
    return join( "\n", @data );
282
    return join( "\n", @data );
283
}
283
}
284
284
285
=head3 feature_enabled
286
287
  [% KohaPlugins.feature_enabled('method_name') %]
288
289
This method returns true if the passed plugin hook method name is found to be installed and enabled as part of a plugin.
290
291
=cut
292
293
sub feature_enabled {
294
    my ( $self, $method ) = @_;
295
296
    my $p = Koha::Plugins->new;
297
    return 0 unless $p;
298
299
    return $p->feature_enabled($method);
300
}
301
285
1;
302
1;
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-2 / +33 lines)
Lines 25-31 use File::Temp qw( tempdir tempfile ); Link Here
25
use FindBin qw($Bin);
25
use FindBin qw($Bin);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Load::Conditional qw(can_load);
27
use Test::MockModule;
27
use Test::MockModule;
28
use Test::More tests => 61;
28
use Test::More tests => 62;
29
use Test::Warn;
29
use Test::Warn;
30
30
31
use C4::Context;
31
use C4::Context;
Lines 129-134 subtest 'more call() tests' => sub { Link Here
129
    $schema->storage->txn_rollback;
129
    $schema->storage->txn_rollback;
130
};
130
};
131
131
132
subtest 'feature_enabled tests' => sub {
133
    plan tests => 4;
134
135
    $schema->storage->txn_begin;
136
137
    # Temporarily remove any installed plugins data
138
    Koha::Plugins::Methods->delete;
139
    $schema->resultset('PluginData')->delete();
140
141
    t::lib::Mocks::mock_config( 'enable_plugins', 0 );
142
    my $enabled = Koha::Plugins->feature_enabled('check_password');
143
    ok( !$enabled, "check_password not available when plugins are disabled" );
144
145
    t::lib::Mocks::mock_config( 'enable_plugins', 1 );
146
    my $plugins = Koha::Plugins->new( { enable_plugins => 1 } );
147
148
    my @plugins;
149
    warning_is { @plugins = $plugins->InstallPlugins; } undef;
150
151
    $enabled = Koha::Plugins->feature_enabled('check_password');
152
    ok( !$enabled, "check_password not available when plugins are installed but not enabled" );
153
154
    foreach my $plugin (@plugins) {
155
        $plugin->enable();
156
    }
157
158
    $enabled = Koha::Plugins->feature_enabled('check_password');
159
    ok( $enabled, "check_password is available when at least one enabled plugin supports it" );
160
161
    $schema->storage->txn_rollback;
162
};
163
132
subtest 'GetPlugins() tests' => sub {
164
subtest 'GetPlugins() tests' => sub {
133
165
134
    plan tests => 3;
166
    plan tests => 3;
135
- 

Return to bug 31503