Bugzilla – Attachment 103722 Details for
Bug 24631
Plugin metadata should be outside the main class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24631: Plugin metadata should be outside the main class
Bug-24631-Plugin-metadata-should-be-outside-the-ma.patch (text/plain), 11.27 KB, created by
Victor Grousset/tuxayo
on 2020-04-26 03:44:24 UTC
(
hide
)
Description:
Bug 24631: Plugin metadata should be outside the main class
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2020-04-26 03:44:24 UTC
Size:
11.27 KB
patch
obsolete
>From 894d792f0641ebee1c0d175877832a74d004002d Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 16 Apr 2020 11:50:28 -0400 >Subject: [PATCH] Bug 24631: Plugin metadata should be outside the main class > >Currently, plugin metadata is stored within the main plugin class file but this means one has to load the class to read it. We should pull this data out into a manifest/metadata file in a standard format (JSON/YAML) to allow simpler external parsing. > >Test Plan: >1) Apply this patch >2) Install the latest Kitchen Sink plugin: https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.39/koha-plugin-kitchen-sink-v2.1.39.kpz >3) Browse to plugins home, note that nothing appears to have changed >4) Browse to your pluginsdir, find the PLUGIN.yml file for the Kitchen Sink plugin, edit some of the metadata >5) Reload the plugins home page, note your changes to PLUGIN.yml appear in the plugins table! > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > Koha/Plugins.pm | 60 ++++++++++++++++++- > cpanfile | 1 + > .../prog/en/modules/plugins/plugins-home.tt | 28 ++++----- > plugins/plugins-home.pl | 4 +- > 4 files changed, 75 insertions(+), 18 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 9dc42c5155..b7b674f071 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -20,18 +20,22 @@ package Koha::Plugins; > use Modern::Perl; > > use Class::Inspector; >+use File::Find::Rule; > use List::MoreUtils qw(any); >-use Module::Load::Conditional qw(can_load); > use Module::Load qw(load); >+use Module::Load::Conditional qw(can_load); > use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; >+use YAML qw(LoadFile); > > use C4::Context; > use C4::Output; > use Koha::Plugins::Methods; > >+our @pluginsdir; >+ > BEGIN { > my $pluginsdir = C4::Context->config("pluginsdir"); >- my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; >+ @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; > push( @INC, @pluginsdir ); > pop @INC if $INC[-1] eq '.'; > } >@@ -112,6 +116,58 @@ sub GetPlugins { > return @plugins; > } > >+sub GetPluginsMetadata { >+ my ( $self, $params ) = @_; >+ >+ my $method = $params->{method}; >+ my $req_metadata = $params->{metadata} // {}; >+ >+ my $filter = ( $method ) ? { plugin_method => $method } : undef; >+ >+ my $plugin_classes = Koha::Plugins::Methods->search( >+ $filter, >+ { columns => 'plugin_class', >+ distinct => 1 >+ } >+ )->_resultset->get_column('plugin_class'); >+ >+ my @metafiles = File::Find::Rule->file()->name('PLUGIN.yml')->in( @pluginsdir ); >+ >+ my @plugins; >+ while ( my $plugin_class = $plugin_classes->next ) { >+ my $plugin_path = $plugin_class; >+ $plugin_path =~ s/::/\//g; # Take class name, transform :: to / to get path >+ my $yaml_to_find = "$plugin_path/PLUGIN.yml"; >+ $plugin_path =~ s/$/.pm/; # Add .pm to the end >+ >+ # Find the full path to the file, it's somewhere in the list of metafiles we found when this module as loaded >+ my ( $meta_yaml ) = grep { $yaml_to_find eq substr( $_, -length($yaml_to_find) ) } @metafiles; >+ >+ my $plugin_metadata; >+ if ( -r $meta_yaml ) { # If the metafile exists and is readable, use it >+ $plugin_metadata = YAML::LoadFile($meta_yaml); >+ } else { # Fall back to loading the plugin to get the metadata if there is no PLUGIN.yml file to read >+ load $plugin_class; >+ my $plugin = $plugin_class->new({ >+ enable_plugins => $self->{'enable_plugins'} >+ }); >+ >+ # filter the plugin out by metadata >+ $plugin_metadata = $plugin->get_metadata; >+ } >+ >+ next >+ if $plugin_metadata >+ and %$req_metadata >+ and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; >+ >+ push @plugins, $plugin_metadata; >+ >+ } >+ >+ return @plugins; >+} >+ > =head2 InstallPlugins > > Koha::Plugins::InstallPlugins() >diff --git a/cpanfile b/cpanfile >index f7d69c3f84..048d8d9620 100644 >--- a/cpanfile >+++ b/cpanfile >@@ -39,6 +39,7 @@ requires 'Email::Date', '1.103'; > requires 'Email::MessageID', '1.406'; > requires 'Email::Valid', '0.190'; > requires 'Exception::Class', '1.38'; >+requires 'File::Find::Rule', '0.34'; > requires 'File::Slurp', '9999.13'; > requires 'Font::TTF', '0.45'; > requires 'GD', '2.39'; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >index 1c25a22718..df399f3d66 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >@@ -80,7 +80,7 @@ > </table> > [% END %] > >- [% UNLESS ( plugins ) %] >+ [% UNLESS ( plugins_metadata ) %] > [% UNLESS ( method ) %] > <div class="dialog message">No plugins installed</div> > [% ELSE %] >@@ -113,10 +113,10 @@ > [% END %] > </tr> > >- [% FOREACH plugin IN plugins %] >+ [% FOREACH metadata IN plugins_metadata %] > <tr> > <td> >- <strong>[% plugin.metadata.name | html %]</strong> >+ <strong>[% metadata.name | html %]</strong> > [% IF ( plugin.is_enabled ) %] > <span class="label label-primary">ENABLED</span> > [% ELSE %] >@@ -124,25 +124,25 @@ > [% END %] > </td> > <td> >- [% plugin.metadata.description | html %] >+ [% metadata.description | html %] > >- [% IF ( plugin.metadata.minimum_version && koha_version < plugin.metadata.minimum_version ) %] >+ [% IF ( metadata.minimum_version && koha_version < metadata.minimum_version ) %] > <div class="dialog alert"> > Warning: This report was written for a newer version of Koha. Run at your own risk. > </div> > [% END %] > >- [% IF ( plugin.metadata.maximum_version && koha_version > plugin.metadata.maximum_version ) %] >+ [% IF ( metadata.maximum_version && koha_version > metadata.maximum_version ) %] > <div class="dialog alert"> > Warning: This plugin was written for an older version of Koha. Run at your own risk. > </div> > [% END %] > </td> >- <td>[% plugin.metadata.author | html %]</td> >- <td>[% plugin.metadata.version | html %]</td> >- <td>[% plugin.metadata.minimum_version | html %]</td> >- <td>[% plugin.metadata.maximum_version | html %]</td> >- <td>[% plugin.metadata.date_updated | $KohaDates %]</td> >+ <td>[% metadata.author | html %]</td> >+ <td>[% metadata.version | html %]</td> >+ <td>[% metadata.minimum_version | html %]</td> >+ <td>[% metadata.maximum_version | html %]</td> >+ <td>[% metadata.date_updated | $KohaDates %]</td> > [% IF ( CAN_user_plugins_configure || CAN_user_plugins_manage || CAN_user_plugins_report || CAN_user_plugins_tool ) %] > <td class="actions"> > <div class="dropdown"> >@@ -168,11 +168,11 @@ > [% END %] > [% END %] > [% IF ( CAN_user_plugins_manage ) %] >- <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> >+ <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> > [% IF ( plugin.is_enabled ) %] >- <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> >+ <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> > [% ELSE %] >- <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> >+ <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> > [% END %] > [% END %] > </ul> >diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl >index f376e17d08..fc1bba970e 100755 >--- a/plugins/plugins-home.pl >+++ b/plugins/plugins-home.pl >@@ -53,12 +53,12 @@ if ($plugins_enabled) { > method => $method, > ); > >- my @plugins = Koha::Plugins->new()->GetPlugins({ >+ my @plugins = Koha::Plugins->new()->GetPluginsMetadata({ > method => $method, > all => 1, > }); > >- $template->param( plugins => \@plugins, ); >+ $template->param( plugins_metadata => \@plugins, ); > > my @results; > if ($plugin_search) { >-- >2.26.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24631
:
103092
|
103467
|
103468
|
103656
|
103722
|
103982
|
103983
|
104023
|
104024
|
104256
|
104266
|
104270