Bugzilla – Attachment 156555 Details for
Bug 34978
Add --include and --exclude options to install_plugins.pl to choose the plugins to install
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34978: Add --include and --exclude options to install_plugins.pl
Bug-34978-Add---include-and---exclude-options-to-i.patch (text/plain), 8.75 KB, created by
Emily-Rose Francoeur
on 2023-10-04 20:05:01 UTC
(
hide
)
Description:
Bug 34978: Add --include and --exclude options to install_plugins.pl
Filename:
MIME Type:
Creator:
Emily-Rose Francoeur
Created:
2023-10-04 20:05:01 UTC
Size:
8.75 KB
patch
obsolete
>From 80a88444ddaa066ca5ddc55e0809243304c7f21f Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?=C3=89mily-Rose=20Francoeur?= > <emily-rose.francoeur@inLibro.com> >Date: Wed, 4 Oct 2023 15:59:56 -0400 >Subject: [PATCH] Bug 34978: Add --include and --exclude options to > install_plugins.pl > >I have added the options --include and --exclude to the install_plugins.pl script. When running the script, you can now specify which plugins you want to install (--include) and which ones you do not want to install (--exclude). > >--include installs only the plugins from the specified classes. >--exclude installs all plugins except those from the specified classes. >It's possible to specify the package to install a specific plugin. >--include and --exclude cannot be used simultaneously. > >Usage example: >./misc/devel/install_plugins --include <package::pluginClass> --include <anotherPluginClass>" > >TEST PLAN >1) Apply the patch >2) Add at least three plugins to the plugin directory ([Koha]/plugins/Koha/Plugin/) >3) Empty the "plugin_data" and "plugin_methods" tables (SQL command: "delete from plugin_data; delete from plugin_methods;") >4) In a terminal, execute this command "./misc/devel/install_plugins.pl --include <package::pluginClass> --include <anotherPluginClass>" (Replace <package::pluginClass> and <anotherPluginClass> with the class and package of your plugins) >5) In your Koha intranet, go to "Koha administration > Manage plugins" >6) Verify that only the specified plugins are installed >7) Repeat step 3 >8) In a terminal, execute this command from your Koha project"./misc/devel/install_plugins.pl --exclude <package::pluginClass> --exclude <anotherPluginClass>" >9) Verify that all plugins except the specified ones are installed >10) Run the tests from the Plugins.t file ([Koha]/t/db_dependent/Koha/Plugins/Plugins.t) >11) Ensure that all tests are successful >--- > Koha/Plugins.pm | 30 +++++++++++++- > misc/devel/install_plugins.pl | 28 ++++++++++++-- > t/db_dependent/Koha/Plugins/Plugins.t | 56 ++++++++++++++++++++++++++- > 3 files changed, 109 insertions(+), 5 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index a3c47006b5..2894dff676 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -230,12 +230,40 @@ sub InstallPlugins { > my ( $self, $params ) = @_; > > my @plugin_classes = $self->plugins(); >- my @plugins; >+ my (@plugins, @classes_filters); >+ >+ my $has_filters = defined($params->{include}) || defined($params->{exclude}); >+ >+ # Warn user if the specified classes doesn't exist and return nothing >+ if ($has_filters) { >+ @classes_filters = defined($params->{include}) ? @{$params->{include}} : @{$params->{exclude}}; >+ >+ foreach my $classes_filter (@classes_filters) { >+ my $is_found = 0; >+ >+ foreach my $plugin_class (@plugin_classes) { >+ $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$"); >+ } >+ unless ($is_found) { >+ warn "$classes_filter have not been found, try a different name"; >+ return; >+ } >+ } >+ } > > foreach my $plugin_class (@plugin_classes) { > if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { > next unless $plugin_class->isa('Koha::Plugins::Base'); > >+ # Apply the filters >+ if ($has_filters) { >+ my $is_found = 0; >+ foreach my $classes_filter (@classes_filters) { >+ $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$"); >+ } >+ next if (defined($params->{include}) && !$is_found) || (defined($params->{exclude}) && $is_found); >+ } >+ > my $plugin; > my $failed_instantiation; > >diff --git a/misc/devel/install_plugins.pl b/misc/devel/install_plugins.pl >index 8e2cee9ad9..f6978b5030 100755 >--- a/misc/devel/install_plugins.pl >+++ b/misc/devel/install_plugins.pl >@@ -26,11 +26,18 @@ use Koha::Script; > use C4::Context; > use Koha::Plugins; > >-my ($help); >-GetOptions( 'help|?' => \$help ); >+my ($help, @include, @exclude); >+ >+GetOptions( >+ 'help|?' => \$help, >+ 'include=s' => \@include, >+ 'exclude=s' => \@exclude, >+) or die "Installation aborted\n"; > > pod2usage(1) if $help; > >+die "Installation aborted : --include and --exclude can't be used simultaneously\n" if @include && @exclude; >+ > unless ( C4::Context->config("enable_plugins") ) { > print > "The plugin system must be enabled for one to be able to install plugins\n"; >@@ -51,7 +58,12 @@ for my $existing_plugin (@existing_plugins) { > } > } > >-my @installed_plugins = Koha::Plugins->new()->InstallPlugins(); >+my $params = {}; >+$params->{'include'} = \@include if @include; >+$params->{'exclude'} = \@exclude if @exclude; >+ >+my @installed_plugins = Koha::Plugins->new()->InstallPlugins($params); >+ > unless (@installed_plugins) { > my $plugins_dir = C4::Context->config("pluginsdir"); > if ( ref($plugins_dir) eq 'ARRAY' ) { >@@ -96,6 +108,8 @@ install_plugins.pl - install all plugins found in plugins_dir > > Options: > -?|--help brief help message >+ --include install only the plugins of the specified classes >+ --exclude install all the plugins except the specified ones > > =head1 OPTIONS > >@@ -105,6 +119,14 @@ Options: > > Print a brief help message and exits > >+=item B<--include> >+ >+Retrieve the list of plugin classes and install only those. It's possible to specify the package of a class to install a specific plugin (e.g. --include <package::pluginClass> --include <anotherPluginClass>). >+ >+=item B<--exclude> >+ >+Retrieve the list of plugin classes and install all plugins except those. It's possible to specify the package of a class to install a specific plugin (e.g. --exclude <package::pluginClass> --exclude <anotherPluginClass>). >+ > =back > > =head1 DESCRIPTION >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index db68b9d195..181615b6f7 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -25,7 +25,7 @@ use File::Temp qw( tempdir tempfile ); > use FindBin qw($Bin); > use Module::Load::Conditional qw(can_load); > use Test::MockModule; >-use Test::More tests => 61; >+use Test::More tests => 62; > use Test::Warn; > > use C4::Context; >@@ -153,6 +153,60 @@ subtest 'GetPlugins() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'InstallPlugins() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ # Temporarily remove any installed plugins data >+ Koha::Plugins::Methods->delete; >+ $schema->resultset('PluginData')->delete; >+ >+ # Tests for the exclude paramater >+ # Test the returned plugins of the InstallPlugins subroutine >+ my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); >+ my @installed_plugins = $plugins->InstallPlugins({ exclude => ["Test", "Koha::Plugin::MarcFieldValues"] }); >+ my $plugin_classes = join(" ", map{$_->{class}} @installed_plugins); >+ >+ my $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"] >+ && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; >+ ok($result, "Excluded plugins are not returned"); >+ >+ # Test the plugins in the database >+ my @plugins = $plugins->GetPlugins({ all => 1, error => 1 }); >+ $plugin_classes = join(" ", map{$_->{class}} @plugins); >+ >+ $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"] >+ && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$"; >+ ok($result, "Excluded plugins are not installed"); >+ >+ # Remove installed plugins data >+ Koha::Plugins::Methods->delete; >+ $schema->resultset('PluginData')->delete; >+ >+ # Tests for the include parameter >+ # Test the returned plugins of the InstallPlugins subroutine >+ @installed_plugins = $plugins->InstallPlugins({ include => ["Test", "Koha::Plugin::MarcFieldValues"]}); >+ >+ $result = 1; >+ foreach my $plugin_class ( map{ $_->{class} } @installed_plugins ) { >+ $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$"); >+ } >+ ok($result, "Only included plugins are returned"); >+ >+ # Test the plugins in the database >+ @plugins = $plugins->GetPlugins({ all => 1, error => 1}); >+ >+ $result = 1; >+ foreach my $plugin_class ( map{ $_->{class} } @plugins ) { >+ $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$"); >+ } >+ ok($result, "Only included plugins are installed"); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'Version upgrade tests' => sub { > > plan tests => 1; >-- >2.34.1
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 34978
:
156539
|
156555
|
156557
|
160210
|
160239
|
160240
|
163800
|
163801
|
166560
|
166561
|
166562
|
166576
|
166736
|
166738
|
166739
|
166740
|
166741
|
166742