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

(-)a/Koha/Plugins.pm (-2 / +92 lines)
Lines 21-37 use Modern::Perl; Link Here
21
21
22
use Class::Inspector;
22
use Class::Inspector;
23
use List::MoreUtils qw(any);
23
use List::MoreUtils qw(any);
24
use Module::Load::Conditional qw(can_load);
25
use Module::Load qw(load);
24
use Module::Load qw(load);
25
use Module::Load::Conditional qw(can_load);
26
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
26
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
27
use YAML qw(Load Dump);
27
28
28
use C4::Context;
29
use C4::Context;
29
use C4::Output;
30
use C4::Output;
30
use Koha::Plugins::Methods;
31
use Koha::Plugins::Methods;
32
use Koha::Plugins::Data;
33
34
our @pluginsdir;
31
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 @plugins;
135
    while ( my $plugin_class = $plugin_classes->next ) {
136
        my $plugin_metadata = Koha::Plugins::Data->find(
137
            {
138
                plugin_class => $plugin_class,
139
                plugin_key   => '__METADATA__',
140
            }
141
        );
142
143
        if ( $plugin_metadata ) {
144
            $plugin_metadata = YAML::Load( $plugin_metadata->plugin_value );
145
        }
146
        else {
147
            load $plugin_class;
148
            my $plugin = $plugin_class->new(
149
                {
150
                    enable_plugins => $self->{enable_plugins}
151
                }
152
            );
153
            $plugin_metadata = $plugin->get_metadata;
154
155
            Koha::Plugins::Datum->new(
156
                {
157
                    plugin_class => $plugin_class,
158
                    plugin_key   => '__METADATA__',
159
                    plugin_value => YAML::Dump( $plugin_metadata ),
160
                }
161
            )->store();
162
        }
163
164
        my $plugin_enabled = Koha::Plugins::Data->find(
165
            {
166
                plugin_class => $plugin_class,
167
                plugin_key   => '__ENABLED__',
168
            }
169
        );
170
        $plugin_metadata->{is_enabled} = $plugin_enabled->plugin_value;
171
172
        my @plugin_methods = Koha::Plugins::Methods->search(
173
            {
174
                plugin_class => $plugin_class,
175
            },
176
            {
177
                columns => 'plugin_method',
178
            }
179
        );
180
181
        $plugin_metadata->{can} = { map { $_->plugin_method => 1 } @plugin_methods };
182
183
        next
184
            if $plugin_metadata
185
            and %$req_metadata
186
            and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
187
188
        push @plugins, $plugin_metadata;
189
190
    }
191
192
    return @plugins;
193
}
194
115
=head2 InstallPlugins
195
=head2 InstallPlugins
116
196
117
Koha::Plugins::InstallPlugins()
197
Koha::Plugins::InstallPlugins()
Lines 137-142 sub InstallPlugins { Link Here
137
217
138
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
218
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
139
219
220
            # Force update plugin metadata in the database
221
            my $metadata = $plugin->get_metadata( { skip_database => 1 } );
222
            my $params = {
223
                plugin_class => $plugin_class,
224
                plugin_key   => '__METADATA__',
225
            };
226
            my $db_metadata = Koha::Plugins::Data->find( $params ) || Koha::Plugins::Datum->new( $params );
227
            $db_metadata->plugin_value( YAML::Dump($metadata) );
228
            $db_metadata->store();
229
140
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
230
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
141
231
142
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
232
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
(-)a/Koha/Plugins/Base.pm (-3 / +24 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 58-64 sub new { Link Here
58
            warn "Plugin $class failed during installation!";
59
            warn "Plugin $class failed during installation!";
59
        }
60
        }
60
    } elsif ( $self->can('upgrade') ) {
61
    } elsif ( $self->can('upgrade') ) {
61
        if ( _version_compare( $plugin_version, $database_version ) == 1 ) {
62
        if ( $self->_version_compare( $plugin_version, $database_version ) == 1 ) {
62
            if ( $self->upgrade() ) {
63
            if ( $self->upgrade() ) {
63
                $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
64
                $self->store_data({ '__INSTALLED_VERSION__' => $plugin_version });
64
            } else {
65
            } else {
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
199
    my $class = ref($self);
200
    $metadata->{class} = $class;
201
180
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
202
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
181
    my $metadata = $self->{metadata};
182
    $metadata->{$_} && utf8::decode($metadata->{$_}) for keys %$metadata;
203
    $metadata->{$_} && utf8::decode($metadata->{$_}) for keys %$metadata;
183
    return $metadata;
204
    return $metadata;
184
}
205
}
(-)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/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt (-24 / +24 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-178 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 ( metadata.is_enabled ) %]
121
                                            <span class="label label-primary">ENABLED</span>
121
                                            <span class="label label-primary">ENABLED</span>
122
                                        [% ELSE %]
122
                                        [% ELSE %]
123
                                            <span class="label label-default">DISABLED</span>
123
                                            <span class="label label-default">DISABLED</span>
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">
149
                                                <a class="btn btn-default btn-xs dropdown-toggle" id="pluginactions[% plugin.class | html %]" role="button" data-toggle="dropdown" href="#">
149
                                                <a class="btn btn-default btn-xs dropdown-toggle" id="pluginactions[% metadata.class | html %]" role="button" data-toggle="dropdown" href="#">
150
                                                   Actions <b class="caret"></b>
150
                                                   Actions <b class="caret"></b>
151
                                                </a>
151
                                                </a>
152
                                                <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="pluginactions[% plugin.class | html %]">
152
                                                <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="pluginactions[% metadata.class | html %]">
153
                                                    [% IF ( CAN_user_plugins_report ) %]
153
                                                    [% IF ( CAN_user_plugins_report ) %]
154
                                                        [% IF plugin.can('report') %]
154
                                                        [% IF metadata.can.report %]
155
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class | uri %]&method=report"><i class="fa fa-table fa-fw"></i> Run report</a></li>
155
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% metadata.class | uri %]&method=report"><i class="fa fa-table fa-fw"></i> Run report</a></li>
156
                                                        [% END %]
156
                                                        [% END %]
157
                                                    [% END %]
157
                                                    [% END %]
158
158
159
                                                    [% IF ( CAN_user_plugins_tool ) %]
159
                                                    [% IF ( CAN_user_plugins_tool ) %]
160
                                                        [% IF plugin.can('tool') %]
160
                                                        [% IF metadata.can.tool %]
161
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class | uri %]&method=tool"><i class="fa fa-wrench fa-fw"></i> Run tool</a></li>
161
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% metadata.class | uri %]&method=tool"><i class="fa fa-wrench fa-fw"></i> Run tool</a></li>
162
                                                        [% END %]
162
                                                        [% END %]
163
                                                    [% END %]
163
                                                    [% END %]
164
164
165
                                                    [% IF ( CAN_user_plugins_configure ) %]
165
                                                    [% IF ( CAN_user_plugins_configure ) %]
166
                                                        [% IF plugin.can('configure') %]
166
                                                        [% IF metadata.can.configure %]
167
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class | uri %]&method=configure"><i class="fa fa-cog fa-fw"></i> Configure</a></li>
167
                                                            <li><a href="/cgi-bin/koha/plugins/run.pl?class=[% metadata.class | uri %]&method=configure"><i class="fa fa-cog fa-fw"></i> Configure</a></li>
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=[% metadata.class | html %]"><i class="fa fa-trash fa-fw"></i> Uninstall</a></li>
172
                                                        [% IF ( plugin.is_enabled ) %]
172
                                                        [% IF ( metadata.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=[% metadata.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=[% metadata.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