Bugzilla – Attachment 166738 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), 9.06 KB, created by
Hammat wele
on 2024-05-14 20:27:53 UTC
(
hide
)
Description:
Bug 34978: Add --include and --exclude options to install_plugins.pl
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2024-05-14 20:27:53 UTC
Size:
9.06 KB
patch
obsolete
>From 2a22515dd74264510325222b20eeaa62efb42a17 Mon Sep 17 00:00:00 2001 >From: Emily-Rose Francoeur <emily-rose.francoeur@inlibro.com> >Date: Wed, 4 Oct 2023 16:19:15 -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 > >Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Hammat Wele <hammat.wele@inlibro.com> >--- > 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 2b4c07956e..6669da3702 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -277,12 +277,40 @@ sub InstallPlugins { > my $verbose = $params->{verbose} // $self->_verbose; > > 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 }, verbose => $verbose, 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 2ccc68a15b..02c96474cf 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"; >@@ -46,7 +53,12 @@ for my $existing_plugin (@existing_plugins) { > $existing_plugins->{ $existing_plugin->{metadata}->{name} } = $existing_plugin->{metadata}->{version}; > } > >-my @installed_plugins = Koha::Plugins->new()->InstallPlugins( { verbose => 0 } ); >+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' ) { >@@ -91,6 +103,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 > >@@ -100,6 +114,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 1c8f96ab15..7fdebf55a1 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -24,7 +24,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 => 18; >+use Test::More tests => 30; > use Test::Warn; > > use C4::Context; >@@ -185,6 +185,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