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

(-)a/Koha/Plugins.pm (-6 / +12 lines)
Lines 260-278 sub InstallPlugins { Link Here
260
    my $verbose = $params->{verbose} // $self->_verbose;
260
    my $verbose = $params->{verbose} // $self->_verbose;
261
261
262
    my @plugin_classes = $self->plugins();
262
    my @plugin_classes = $self->plugins();
263
    my (@plugins, @classes_filters);
263
    my ( @plugins, @classes_filters );
264
264
265
    my $has_filters = defined($params->{include}) || defined($params->{exclude});
265
    my $has_filters = defined( $params->{include} ) || defined( $params->{exclude} );
266
266
267
    # Warn user if the specified classes doesn't exist and return nothing
267
    # Warn user if the specified classes doesn't exist and return nothing
268
    if ($has_filters) {
268
    if ($has_filters) {
269
        @classes_filters = defined($params->{include}) ? @{$params->{include}} : @{$params->{exclude}};
269
        @classes_filters = defined( $params->{include} ) ? @{ $params->{include} } : @{ $params->{exclude} };
270
270
271
        foreach my $classes_filter (@classes_filters) {
271
        foreach my $classes_filter (@classes_filters) {
272
            my $is_found = 0;
272
            my $is_found = 0;
273
273
274
            foreach my $plugin_class (@plugin_classes) {
274
            foreach my $plugin_class (@plugin_classes) {
275
                $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$");
275
                $is_found = 1
276
                    if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$"
277
                    || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" );
276
            }
278
            }
277
            unless ($is_found) {
279
            unless ($is_found) {
278
                warn "$classes_filter have not been found, try a different name";
280
                warn "$classes_filter have not been found, try a different name";
Lines 289-297 sub InstallPlugins { Link Here
289
            if ($has_filters) {
291
            if ($has_filters) {
290
                my $is_found = 0;
292
                my $is_found = 0;
291
                foreach my $classes_filter (@classes_filters) {
293
                foreach my $classes_filter (@classes_filters) {
292
                    $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$");
294
                    $is_found = 1
295
                        if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$"
296
                        || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" );
293
                }
297
                }
294
                next if (defined($params->{include}) && !$is_found) || (defined($params->{exclude}) && $is_found);
298
                next
299
                    if ( defined( $params->{include} ) && !$is_found )
300
                    || ( defined( $params->{exclude} ) && $is_found );
295
            }
301
            }
296
302
297
            my $plugin;
303
            my $plugin;
(-)a/misc/devel/install_plugins.pl (-2 / +2 lines)
Lines 26-35 use Koha::Script; Link Here
26
use C4::Context;
26
use C4::Context;
27
use Koha::Plugins;
27
use Koha::Plugins;
28
28
29
my ($help, @include, @exclude);
29
my ( $help, @include, @exclude );
30
30
31
GetOptions(
31
GetOptions(
32
    'help|?' => \$help,
32
    'help|?'    => \$help,
33
    'include=s' => \@include,
33
    'include=s' => \@include,
34
    'exclude=s' => \@exclude,
34
    'exclude=s' => \@exclude,
35
) or die "Installation aborted\n";
35
) or die "Installation aborted\n";
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-20 / +19 lines)
Lines 24-30 use File::Temp qw( tempdir tempfile ); Link Here
24
use FindBin qw($Bin);
24
use FindBin qw($Bin);
25
use Module::Load::Conditional qw(can_load);
25
use Module::Load::Conditional qw(can_load);
26
use Test::MockModule;
26
use Test::MockModule;
27
use Test::More tests => 62;
27
use Test::More tests => 51;
28
use Test::Warn;
28
use Test::Warn;
29
29
30
use C4::Context;
30
use C4::Context;
Lines 196-218 subtest 'InstallPlugins() tests' => sub { Link Here
196
    Koha::Plugins::Methods->delete;
196
    Koha::Plugins::Methods->delete;
197
    $schema->resultset('PluginData')->delete;
197
    $schema->resultset('PluginData')->delete;
198
198
199
    # Tests for the exclude paramater
199
    # Tests for the exclude parameter
200
    # Test the returned plugins of the InstallPlugins subroutine
200
    # Test the returned plugins of the InstallPlugins subroutine
201
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
201
    my $plugins           = Koha::Plugins->new( { enable_plugins => 1 } );
202
    my @installed_plugins = $plugins->InstallPlugins({ exclude => ["Test", "Koha::Plugin::MarcFieldValues"] });
202
    my @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Test", "Koha::Plugin::MarcFieldValues" ] } );
203
    my $plugin_classes = join(" ", map{$_->{class}} @installed_plugins);
203
    my $plugin_classes    = join( " ", map { $_->{class} } @installed_plugins );
204
204
205
    my $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"]
205
    my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ]
206
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
206
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
207
    ok($result, "Excluded plugins are not returned");
207
    ok( $result, "Excluded plugins are not returned" );
208
208
209
    # Test the plugins in the database
209
    # Test the plugins in the database
210
    my @plugins = $plugins->GetPlugins({ all => 1, error => 1 });
210
    my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } );
211
    $plugin_classes = join(" ", map{$_->{class}} @plugins);
211
    $plugin_classes = join( " ", map { $_->{class} } @plugins );
212
212
213
    $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"]
213
    $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ]
214
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
214
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
215
    ok($result, "Excluded plugins are not installed");
215
    ok( $result, "Excluded plugins are not installed" );
216
216
217
    # Remove installed plugins data
217
    # Remove installed plugins data
218
    Koha::Plugins::Methods->delete;
218
    Koha::Plugins::Methods->delete;
Lines 220-241 subtest 'InstallPlugins() tests' => sub { Link Here
220
220
221
    # Tests for the include parameter
221
    # Tests for the include parameter
222
    # Test the returned plugins of the InstallPlugins subroutine
222
    # Test the returned plugins of the InstallPlugins subroutine
223
    @installed_plugins = $plugins->InstallPlugins({ include => ["Test", "Koha::Plugin::MarcFieldValues"]});
223
    @installed_plugins = $plugins->InstallPlugins( { include => [ "Test", "Koha::Plugin::MarcFieldValues" ] } );
224
224
225
    $result = 1;
225
    $result = 1;
226
    foreach my $plugin_class ( map{ $_->{class} } @installed_plugins ) {
226
    foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) {
227
        $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$");
227
        $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" );
228
    }
228
    }
229
    ok($result, "Only included plugins are returned");
229
    ok( $result, "Only included plugins are returned" );
230
230
231
    # Test the plugins in the database
231
    # Test the plugins in the database
232
    @plugins = $plugins->GetPlugins({ all => 1, error => 1});
232
    @plugins = $plugins->GetPlugins( { all => 1, error => 1 } );
233
233
234
    $result = 1;
234
    $result = 1;
235
    foreach my $plugin_class ( map{ $_->{class} } @plugins ) {
235
    foreach my $plugin_class ( map { $_->{class} } @plugins ) {
236
        $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$");
236
        $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" );
237
    }
237
    }
238
    ok($result, "Only included plugins are installed");
238
    ok( $result, "Only included plugins are installed" );
239
239
240
    $schema->storage->txn_rollback;
240
    $schema->storage->txn_rollback;
241
};
241
};
242
- 

Return to bug 34978