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

(-)a/Koha/Plugins.pm (-11 / +24 lines)
Lines 45-62 sub new { Link Here
45
    return bless( $args, $class );
45
    return bless( $args, $class );
46
}
46
}
47
47
48
=head2 GetPlugins()
48
=head2 GetPlugins
49
49
50
This will return a list of all the available plugins of the passed type.
50
This will return a list of all available plugins, optionally limited by
51
method or metadata value.
51
52
52
Usage: my @plugins = C4::Plugins::GetPlugins( $method );
53
    my @plugins = C4::Plugins::GetPlugins({
54
        method => 'some_method',
55
        metadata => { some_key => 'some_value' },
56
    });
57
58
The method and metadata parameters are optional.
59
Available methods currently are: 'report', 'tool', 'to_marc', 'edifact'.
60
If you pass multiple keys in the metadata hash, all keys must match.
53
61
54
At the moment, the available types are 'report', 'tool' and 'to_marc'.
55
=cut
62
=cut
56
63
57
sub GetPlugins {
64
sub GetPlugins {
58
    my $self   = shift;
65
    my ( $self, $params ) = @_;
59
    my $method = shift;
66
    my $method = $params->{method};
67
    my $req_metadata = $params->{metadata} // {};
60
68
61
    my @plugin_classes = $self->plugins();
69
    my @plugin_classes = $self->plugins();
62
    my @plugins;
70
    my @plugins;
Lines 67-79 sub GetPlugins { Link Here
67
75
68
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
76
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
69
77
70
            if ($method) {
78
            # Limit results by method or metadata
71
                if ( $plugin->can($method) ) {
79
            my $ok = 1;
72
                    push( @plugins, $plugin );
80
            next if $method && !$plugin->can($method);
81
            my $plugin_metadata = $plugin->get_metadata;
82
            foreach my $key ( keys %$req_metadata ) {
83
                if( !$plugin_metadata->{$key} ||
84
                  $plugin_metadata->{$key} ne $req_metadata->{$key} ) {
85
                    $ok = 0;
86
                    last;
73
                }
87
                }
74
            } else {
75
                push( @plugins, $plugin );
76
            }
88
            }
89
            push( @plugins, $plugin ) if $ok;
77
        }
90
        }
78
    }
91
    }
79
    return @plugins;
92
    return @plugins;
(-)a/admin/edi_accounts.pl (-1 / +3 lines)
Lines 57-63 if ( $op eq 'acct_form' ) { Link Here
57
    $template->param( plugins_enabled => $plugins_enabled );
57
    $template->param( plugins_enabled => $plugins_enabled );
58
58
59
    if ( $plugins_enabled ) {
59
    if ( $plugins_enabled ) {
60
        my @plugins = Koha::Plugins->new()->GetPlugins('edifact');
60
        my @plugins = Koha::Plugins->new()->GetPlugins({
61
            method => 'edifact',
62
        });
61
        $template->param( plugins => \@plugins );
63
        $template->param( plugins => \@plugins );
62
    }
64
    }
63
}
65
}
(-)a/plugins/plugins-home.pl (-1 / +3 lines)
Lines 50-56 if ($plugins_enabled) { Link Here
50
        method       => $method,
50
        method       => $method,
51
    );
51
    );
52
52
53
    my @plugins = Koha::Plugins->new()->GetPlugins($method);
53
    my @plugins = Koha::Plugins->new()->GetPlugins({
54
        method => $method,
55
    });
54
56
55
    $template->param( plugins => \@plugins, );
57
    $template->param( plugins => \@plugins, );
56
58
(-)a/t/Koha/Plugin/Test.pm (-1 / +2 lines)
Lines 1-6 Link Here
1
package Koha::Plugin::Test;
1
package Koha::Plugin::Test;
2
2
3
## It's good practive to use Modern::Perl
3
## It's good practice to use Modern::Perl
4
use Modern::Perl;
4
use Modern::Perl;
5
5
6
## Required for all plugins
6
## Required for all plugins
Lines 16-21 our $metadata = { Link Here
16
    minimum_version => '3.11',
16
    minimum_version => '3.11',
17
    maximum_version => undef,
17
    maximum_version => undef,
18
    version         => $VERSION,
18
    version         => $VERSION,
19
    my_example_tag  => 'find_me',
19
};
20
};
20
21
21
## This is the minimum code required for a plugin's 'new' method
22
## This is the minimum code required for a plugin's 'new' method
(-)a/t/db_dependent/Plugins.t (-2 / +10 lines)
Lines 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
6
use Test::More tests => 22;
6
use Test::More tests => 23;
7
use File::Basename;
7
use File::Basename;
8
use FindBin qw($Bin);
8
use FindBin qw($Bin);
9
use Archive::Extract;
9
use Archive::Extract;
Lines 42-50 is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' ); Link Here
42
is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
42
is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
43
is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
43
is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
44
44
45
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins( 'report' );
45
# testing GetPlugins
46
my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
47
    method => 'report'
48
});
46
my @names = map { $_->get_metadata()->{'name'} } @plugins;
49
my @names = map { $_->get_metadata()->{'name'} } @plugins;
47
is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
50
is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" );
51
@plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({
52
    metadata => { my_example_tag  => 'find_me' },
53
});
54
@names = map { $_->get_metadata()->{'name'} } @plugins;
55
is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" );
48
56
49
SKIP: {
57
SKIP: {
50
    my $plugins_dir = C4::Context->config("pluginsdir");
58
    my $plugins_dir = C4::Context->config("pluginsdir");
(-)a/tools/stage-marc-import.pl (-2 / +3 lines)
Lines 208-214 if ($completedJobID) { Link Here
208
    if ( C4::Context->preference('UseKohaPlugins') &&
208
    if ( C4::Context->preference('UseKohaPlugins') &&
209
         C4::Context->config('enable_plugins') ) {
209
         C4::Context->config('enable_plugins') ) {
210
210
211
        my @plugins = Koha::Plugins->new()->GetPlugins('to_marc');
211
        my @plugins = Koha::Plugins->new()->GetPlugins({
212
            method => 'to_marc',
213
        });
212
        $template->param( plugins => \@plugins );
214
        $template->param( plugins => \@plugins );
213
    }
215
    }
214
}
216
}
215
- 

Return to bug 16586