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

(-)a/Koha/Plugins.pm (-2 / +74 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(Load Dump);
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;
33
use Koha::Plugins::Data;
34
35
our @pluginsdir;
31
36
32
BEGIN {
37
BEGIN {
33
    my $pluginsdir = C4::Context->config("pluginsdir");
38
    my $pluginsdir = C4::Context->config("pluginsdir");
34
    my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir;
39
    @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir;
35
    push( @INC, @pluginsdir );
40
    push( @INC, @pluginsdir );
36
    pop @INC if $INC[-1] eq '.';
41
    pop @INC if $INC[-1] eq '.';
37
}
42
}
Lines 112-117 sub GetPlugins { Link Here
112
    return @plugins;
117
    return @plugins;
113
}
118
}
114
119
120
sub GetPluginsMetadata {
121
    my ( $self, $params ) = @_;
122
123
    my $method       = $params->{method};
124
    my $req_metadata = $params->{metadata} // {};
125
126
    my $filter = ( $method ) ? { plugin_method => $method } : undef;
127
128
    my $plugin_classes = Koha::Plugins::Methods->search(
129
        $filter,
130
        {   columns  => 'plugin_class',
131
            distinct => 1
132
        }
133
    )->_resultset->get_column('plugin_class');
134
135
    my @plugins;
136
    while ( my $plugin_class = $plugin_classes->next ) {
137
        my $plugin_metadata = Koha::Plugins::Data->find(
138
            {
139
                plugin_class => $plugin_class,
140
                plugin_key   => 'metadata',
141
            }
142
        );
143
144
        if ( $plugin_metadata ) {
145
            $plugin_metadata = YAML::Load( $plugin_metadata->plugin_value );
146
        }
147
        else {
148
            load $plugin_class;
149
            my $plugin = $plugin_class->new(
150
                {
151
                    enable_plugins => $self->{enable_plugins}
152
                }
153
            );
154
            $plugin_metadata = $plugin->get_metadata;
155
156
            Koha::Plugins::Datum->new(
157
                {
158
                    plugin_class => $plugin_class,
159
                    plugin_key   => 'metadata',
160
                    plugin_value => YAML::Dump( $plugin_metadata ),
161
                }
162
            );
163
        }
164
165
        next
166
            if $plugin_metadata
167
            and %$req_metadata
168
            and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
169
170
        push @plugins, $plugin_metadata;
171
172
    }
173
174
    return @plugins;
175
}
176
115
=head2 InstallPlugins
177
=head2 InstallPlugins
116
178
117
Koha::Plugins::InstallPlugins()
179
Koha::Plugins::InstallPlugins()
Lines 137-142 sub InstallPlugins { Link Here
137
199
138
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
200
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
139
201
202
            # Force update plugin metadata in the database
203
            my $metadata = $plugin->get_metadata( { skip_database => 1 } );
204
            my $params = {
205
                plugin_class => $plugin_class,
206
                plugin_key   => 'metadata',
207
            };
208
            my $db_metadata = Koha::Plugins::Data->find( $params ) || Koha::Plugins::Datum->new( $params );
209
            $db_metadata->plugin_value( YAML::Dump($metadata) );
210
            $db_metadata->store();
211
140
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
212
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
141
213
142
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
214
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
(-)a/Koha/Plugins/Base.pm (-2 / +20 lines)
Lines 19-27 package Koha::Plugins::Base; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Module::Pluggable require => 1;
23
use Cwd qw(abs_path);
22
use Cwd qw(abs_path);
24
use List::Util qw(max);
23
use List::Util qw(max);
24
use Module::Pluggable require => 1;
25
use YAML qw(Load LoadFile);
25
26
26
use base qw{Module::Bundled::Files};
27
use base qw{Module::Bundled::Files};
27
28
Lines 177-184 sub get_template { Link Here
177
sub get_metadata {
178
sub get_metadata {
178
    my ( $self, $args ) = @_;
179
    my ( $self, $args ) = @_;
179
180
181
    my $skip_database = $args->{skip_database};
182
183
    my $metadata = $self->{metadata}; # Check for old style metadata in blessed hash
184
    $metadata ||= $self::metadata; # Check for a global metadata var ( i.e. our $metadata )
185
186
    unless ( $metadata && !$skip_database ) { # Check the database next, unless this is a plugin upgrade
187
        $metadata = $self->retrieve_data('metadata');
188
        $metadata = YAML::Load( $metadata );
189
    }
190
191
    unless ( $metadata ) { # Check for metadata in PLUGIN.yml, if it exists
192
        my $bundle_path = $self->bundle_path;
193
        my $plugin_yml = "$bundle_path/PLUGIN.yml";
194
        if ( -r $plugin_yml ) {
195
            $metadata = YAML::LoadFile( $plugin_yml );
196
        }
197
    }
198
180
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
199
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
181
    my $metadata = $self->{metadata};
182
    $metadata->{$_} && utf8::decode($metadata->{$_}) for keys %$metadata;
200
    $metadata->{$_} && utf8::decode($metadata->{$_}) for keys %$metadata;
183
    return $metadata;
201
    return $metadata;
184
}
202
}
(-)a/Koha/Plugins/Data.pm (+54 lines)
Line 0 Link Here
1
package Koha::Plugins::Data;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Plugins::Datum;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Plugin::Data - Koha Plugins Data Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'PluginData';
44
}
45
46
=head3 object_class
47
48
=cut
49
50
sub object_class {
51
    return 'Koha::Plugins::Datum';
52
}
53
54
1;
(-)a/Koha/Plugins/Datum.pm (+44 lines)
Line 0 Link Here
1
package Koha::Plugins::Datum;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Plugin::Datum - Koha Plugin Data Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'PluginData';
42
}
43
44
1;
(-)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="btn-group dropup">
148
                                            <div class="btn-group dropup">
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