Bugzilla – Attachment 103092 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), 10.15 KB, created by
Kyle M Hall (khall)
on 2020-04-16 15:56:47 UTC
(
hide
)
Description:
Bug 24631: Plugin metadata should be outside the main class
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-04-16 15:56:47 UTC
Size:
10.15 KB
patch
obsolete
>From a1f93e85c592e7996580a8ad33a40a3c80fbbd8b 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.34/koha-plugin-kitchen-sink-v2.1.34.kpz >3) Browse to plugins home, note that nothing appears to have changed >4) Browse to your pluginsdir, find the META.yml file for the Kitchen Sink plugin, edit some of the metadata >5) Reload the plugins home page, note your changes to META.yml appear in the plugins table! >--- > Koha/Plugins.pm | 54 ++++++++++++++++++- > .../prog/en/modules/plugins/plugins-home.tt | 28 +++++----- > plugins/plugins-home.pl | 4 +- > 3 files changed, 69 insertions(+), 17 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 9dc42c5155..4fc8fb0c47 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -21,9 +21,10 @@ use Modern::Perl; > > use Class::Inspector; > 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; >@@ -112,6 +113,57 @@ 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 @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 >+ $plugin_path =~ s/$/.pm/; # Add .pm to the end >+ require $plugin_path; # Require the plugin to have it's path listed in INC >+ $plugin_path = >+ $INC{$plugin_path}; # Get the full true path to the plugin from INC >+ my $meta_yaml = "$plugin_path/META.yml"; >+ >+ my $plugin_metadata; >+ >+ if ( -r $meta_yaml ) { >+ $plugin_metadata = YAML::LoadFile($meta_yaml); >+ } else { >+ 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/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.24.2 (Apple Git-127)
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