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

(-)a/Koha/Plugins.pm (-20 / +36 lines)
Lines 25-35 use List::MoreUtils qw(any); Link Here
25
use Module::Load qw(load);
25
use Module::Load qw(load);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Load::Conditional qw(can_load);
27
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);
28
use YAML qw(Load Dump);
29
29
30
use C4::Context;
30
use C4::Context;
31
use C4::Output;
31
use C4::Output;
32
use Koha::Plugins::Methods;
32
use Koha::Plugins::Methods;
33
use Koha::Plugins::Data;
33
34
34
our @pluginsdir;
35
our @pluginsdir;
35
36
Lines 131-159 sub GetPluginsMetadata { Link Here
131
        }
132
        }
132
    )->_resultset->get_column('plugin_class');
133
    )->_resultset->get_column('plugin_class');
133
134
134
    my @metafiles = File::Find::Rule->file()->name('PLUGIN.yml')->in( @pluginsdir );
135
136
    my @plugins;
135
    my @plugins;
137
    while ( my $plugin_class = $plugin_classes->next ) {
136
    while ( my $plugin_class = $plugin_classes->next ) {
138
        my $plugin_path = $plugin_class;
137
        my $plugin_metadata = Koha::Plugins::Data->find(
139
        $plugin_path =~ s/::/\//g;  # Take class name, transform :: to / to get path
138
            {
140
        my $yaml_to_find = "$plugin_path/PLUGIN.yml";
139
                plugin_class => $plugin_class,
141
        $plugin_path =~ s/$/.pm/;   # Add .pm to the end
140
                plugin_key   => 'metadata',
142
141
            }
143
        # Find the full path to the file, it's somewhere in the list of metafiles we found when this module as loaded
142
        );
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
143
155
            # filter the plugin out by metadata
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
            );
156
            $plugin_metadata = $plugin->get_metadata;
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
            );
157
        }
163
        }
158
164
159
        next
165
        next
Lines 193-198 sub InstallPlugins { Link Here
193
199
194
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
200
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
195
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
196
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
212
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
197
213
198
            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 (-1 / +44 lines)
Line 0 Link Here
0
- 
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;

Return to bug 25316