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

(-)a/Koha/Plugins.pm (-2 / +58 lines)
Lines 20-37 package Koha::Plugins; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Class::Inspector;
22
use Class::Inspector;
23
use File::Find::Rule;
23
use List::MoreUtils qw(any);
24
use List::MoreUtils qw(any);
24
use Module::Load::Conditional qw(can_load);
25
use Module::Load qw(load);
25
use Module::Load qw(load);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
27
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
28
use YAML qw(LoadFile);
27
29
28
use C4::Context;
30
use C4::Context;
29
use C4::Output;
31
use C4::Output;
30
use Koha::Plugins::Methods;
32
use Koha::Plugins::Methods;
31
33
34
our @pluginsdir;
35
32
BEGIN {
36
BEGIN {
33
    my $pluginsdir = C4::Context->config("pluginsdir");
37
    my $pluginsdir = C4::Context->config("pluginsdir");
34
    my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir;
38
    @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir;
35
    push( @INC, @pluginsdir );
39
    push( @INC, @pluginsdir );
36
    pop @INC if $INC[-1] eq '.';
40
    pop @INC if $INC[-1] eq '.';
37
}
41
}
Lines 112-117 sub GetPlugins { Link Here
112
    return @plugins;
116
    return @plugins;
113
}
117
}
114
118
119
sub GetPluginsMetadata {
120
    my ( $self, $params ) = @_;
121
122
    my $method       = $params->{method};
123
    my $req_metadata = $params->{metadata} // {};
124
125
    my $filter = ( $method ) ? { plugin_method => $method } : undef;
126
127
    my $plugin_classes = Koha::Plugins::Methods->search(
128
        $filter,
129
        {   columns  => 'plugin_class',
130
            distinct => 1
131
        }
132
    )->_resultset->get_column('plugin_class');
133
134
    my @metafiles = File::Find::Rule->file()->name('PLUGIN.yml')->in( @pluginsdir );
135
136
    my @plugins;
137
    while ( my $plugin_class = $plugin_classes->next ) {
138
        my $plugin_path = $plugin_class;
139
        $plugin_path =~ s/::/\//g;  # Take class name, transform :: to / to get path
140
        my $yaml_to_find = "$plugin_path/PLUGIN.yml";
141
        $plugin_path =~ s/$/.pm/;   # Add .pm to the end
142
143
        # Find the full path to the file, it's somewhere in the list of metafiles we found when this module as loaded
144
        my ( $meta_yaml ) = grep { $yaml_to_find eq substr( $_, -length($yaml_to_find) ) } @metafiles;
145
146
        my $plugin_metadata;
147
        if ( -r $meta_yaml ) { # If the metafile exists and is readable, use it
148
           $plugin_metadata = YAML::LoadFile($meta_yaml);
149
        } else { # Fall back to loading the plugin to get the metadata if there is no PLUGIN.yml file to read
150
            load $plugin_class;
151
            my $plugin = $plugin_class->new({
152
                enable_plugins => $self->{'enable_plugins'}
153
            });
154
155
            # filter the plugin out by metadata
156
            $plugin_metadata = $plugin->get_metadata;
157
        }
158
159
        next
160
            if $plugin_metadata
161
            and %$req_metadata
162
            and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
163
164
        push @plugins, $plugin_metadata;
165
166
    }
167
168
    return @plugins;
169
}
170
115
=head2 InstallPlugins
171
=head2 InstallPlugins
116
172
117
Koha::Plugins::InstallPlugins()
173
Koha::Plugins::InstallPlugins()
(-)a/cpanfile (+1 lines)
Lines 39-44 requires 'Email::Date', '1.103'; Link Here
39
requires 'Email::MessageID', '1.406';
39
requires 'Email::MessageID', '1.406';
40
requires 'Email::Valid', '0.190';
40
requires 'Email::Valid', '0.190';
41
requires 'Exception::Class', '1.38';
41
requires 'Exception::Class', '1.38';
42
requires 'File::Find::Rule', '0.34';
42
requires 'File::Slurp', '9999.13';
43
requires 'File::Slurp', '9999.13';
43
requires 'Font::TTF', '0.45';
44
requires 'Font::TTF', '0.45';
44
requires 'GD', '2.39';
45
requires 'GD', '2.39';
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt (-14 / +14 lines)
Lines 80-86 Link Here
80
                        </table>
80
                        </table>
81
                    [% END %]
81
                    [% END %]
82
82
83
                    [% UNLESS ( plugins ) %]
83
                    [% UNLESS ( plugins_metadata ) %]
84
                        [% UNLESS ( method ) %]
84
                        [% UNLESS ( method ) %]
85
                            <div class="dialog message">No plugins installed</div>
85
                            <div class="dialog message">No plugins installed</div>
86
                        [% ELSE %]
86
                        [% ELSE %]
Lines 113-122 Link Here
113
                                [% END %]
113
                                [% END %]
114
                            </tr>
114
                            </tr>
115
115
116
                            [% FOREACH plugin IN plugins %]
116
                            [% FOREACH metadata IN plugins_metadata %]
117
                                <tr>
117
                                <tr>
118
                                    <td>
118
                                    <td>
119
                                        <strong>[% plugin.metadata.name | html %]</strong>
119
                                        <strong>[% metadata.name | html %]</strong>
120
                                        [% IF ( plugin.is_enabled ) %]
120
                                        [% IF ( plugin.is_enabled ) %]
121
                                            <span class="label label-primary">ENABLED</span>
121
                                            <span class="label label-primary">ENABLED</span>
122
                                        [% ELSE %]
122
                                        [% ELSE %]
Lines 124-148 Link Here
124
                                        [% END %]
124
                                        [% END %]
125
                                    </td>
125
                                    </td>
126
                                    <td>
126
                                    <td>
127
                                        [% plugin.metadata.description | html %]
127
                                        [% metadata.description | html %]
128
128
129
                                        [% IF ( plugin.metadata.minimum_version && koha_version < plugin.metadata.minimum_version ) %]
129
                                        [% IF ( metadata.minimum_version && koha_version < metadata.minimum_version ) %]
130
                                            <div class="dialog alert">
130
                                            <div class="dialog alert">
131
                                                Warning: This report was written for a newer version of Koha. Run at your own risk.
131
                                                Warning: This report was written for a newer version of Koha. Run at your own risk.
132
                                            </div>
132
                                            </div>
133
                                        [% END %]
133
                                        [% END %]
134
134
135
                                        [% IF ( plugin.metadata.maximum_version && koha_version > plugin.metadata.maximum_version ) %]
135
                                        [% IF ( metadata.maximum_version && koha_version > metadata.maximum_version ) %]
136
                                            <div class="dialog alert">
136
                                            <div class="dialog alert">
137
                                                Warning: This plugin was written for an older version of Koha. Run at your own risk.
137
                                                Warning: This plugin was written for an older version of Koha. Run at your own risk.
138
                                            </div>
138
                                            </div>
139
                                        [% END %]
139
                                        [% END %]
140
                                    </td>
140
                                    </td>
141
                                    <td>[% plugin.metadata.author | html %]</td>
141
                                    <td>[% metadata.author | html %]</td>
142
                                    <td>[% plugin.metadata.version | html %]</td>
142
                                    <td>[% metadata.version | html %]</td>
143
                                    <td>[% plugin.metadata.minimum_version | html %]</td>
143
                                    <td>[% metadata.minimum_version | html %]</td>
144
                                    <td>[% plugin.metadata.maximum_version | html %]</td>
144
                                    <td>[% metadata.maximum_version | html %]</td>
145
                                    <td>[% plugin.metadata.date_updated | $KohaDates %]</td>
145
                                    <td>[% metadata.date_updated | $KohaDates %]</td>
146
                                    [% IF ( CAN_user_plugins_configure || CAN_user_plugins_manage || CAN_user_plugins_report || CAN_user_plugins_tool ) %]
146
                                    [% IF ( CAN_user_plugins_configure || CAN_user_plugins_manage || CAN_user_plugins_report || CAN_user_plugins_tool ) %]
147
                                        <td class="actions">
147
                                        <td class="actions">
148
                                            <div class="dropdown">
148
                                            <div class="dropdown">
Lines 168-178 Link Here
168
                                                        [% END %]
168
                                                        [% END %]
169
                                                    [% END %]
169
                                                    [% END %]
170
                                                    [% IF ( CAN_user_plugins_manage ) %]
170
                                                    [% IF ( CAN_user_plugins_manage ) %]
171
                                                            <li><a class="uninstall_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class | html %]"><i class="fa fa-trash fa-fw"></i> Uninstall</a></li>
171
                                                            <li><a class="uninstall_plugin" data-plugin-name="[% metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class | html %]"><i class="fa fa-trash fa-fw"></i> Uninstall</a></li>
172
                                                        [% IF ( plugin.is_enabled ) %]
172
                                                        [% IF ( plugin.is_enabled ) %]
173
                                                                <li><a class="enable_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=disable"><i class="fa fa-pause fa-fw"></i> Disable</a></li>
173
                                                                <li><a class="enable_plugin" data-plugin-name="[% metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=disable"><i class="fa fa-pause fa-fw"></i> Disable</a></li>
174
                                                        [% ELSE %]
174
                                                        [% ELSE %]
175
                                                                <li><a class="enable_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=enable"><i class="fa fa-play fa-fw"></i> Enable</a></li>
175
                                                                <li><a class="enable_plugin" data-plugin-name="[% metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=enable"><i class="fa fa-play fa-fw"></i> Enable</a></li>
176
                                                        [% END %]
176
                                                        [% END %]
177
                                                    [% END %]
177
                                                    [% END %]
178
                                                </ul>
178
                                                </ul>
(-)a/plugins/plugins-home.pl (-3 / +2 lines)
Lines 53-64 if ($plugins_enabled) { Link Here
53
        method       => $method,
53
        method       => $method,
54
    );
54
    );
55
55
56
    my @plugins = Koha::Plugins->new()->GetPlugins({
56
    my @plugins = Koha::Plugins->new()->GetPluginsMetadata({
57
        method => $method,
57
        method => $method,
58
        all    => 1,
58
        all    => 1,
59
    });
59
    });
60
60
61
    $template->param( plugins => \@plugins, );
61
    $template->param( plugins_metadata => \@plugins, );
62
62
63
    my @results;
63
    my @results;
64
    if ($plugin_search) {
64
    if ($plugin_search) {
65
- 

Return to bug 24631