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

(-)a/Koha/Plugins.pm (-6 / +12 lines)
Lines 277-295 sub InstallPlugins { Link Here
277
    my $verbose = $params->{verbose} // $self->_verbose;
277
    my $verbose = $params->{verbose} // $self->_verbose;
278
278
279
    my @plugin_classes = $self->plugins();
279
    my @plugin_classes = $self->plugins();
280
    my (@plugins, @classes_filters);
280
    my ( @plugins, @classes_filters );
281
281
282
    my $has_filters = defined($params->{include}) || defined($params->{exclude});
282
    my $has_filters = defined( $params->{include} ) || defined( $params->{exclude} );
283
283
284
    # Warn user if the specified classes doesn't exist and return nothing
284
    # Warn user if the specified classes doesn't exist and return nothing
285
    if ($has_filters) {
285
    if ($has_filters) {
286
        @classes_filters = defined($params->{include}) ? @{$params->{include}} : @{$params->{exclude}};
286
        @classes_filters = defined( $params->{include} ) ? @{ $params->{include} } : @{ $params->{exclude} };
287
287
288
        foreach my $classes_filter (@classes_filters) {
288
        foreach my $classes_filter (@classes_filters) {
289
            my $is_found = 0;
289
            my $is_found = 0;
290
290
291
            foreach my $plugin_class (@plugin_classes) {
291
            foreach my $plugin_class (@plugin_classes) {
292
                $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$");
292
                $is_found = 1
293
                    if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$"
294
                    || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" );
293
            }
295
            }
294
            unless ($is_found) {
296
            unless ($is_found) {
295
                warn "$classes_filter have not been found, try a different name";
297
                warn "$classes_filter have not been found, try a different name";
Lines 306-314 sub InstallPlugins { Link Here
306
            if ($has_filters) {
308
            if ($has_filters) {
307
                my $is_found = 0;
309
                my $is_found = 0;
308
                foreach my $classes_filter (@classes_filters) {
310
                foreach my $classes_filter (@classes_filters) {
309
                    $is_found = 1 if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$" || ($classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$");
311
                    $is_found = 1
312
                        if $plugin_class =~ ":$classes_filter\$|^$classes_filter\$"
313
                        || ( $classes_filter =~ "^::" && $plugin_class =~ "$classes_filter\$" );
310
                }
314
                }
311
                next if (defined($params->{include}) && !$is_found) || (defined($params->{exclude}) && $is_found);
315
                next
316
                    if ( defined( $params->{include} ) && !$is_found )
317
                    || ( defined( $params->{exclude} ) && $is_found );
312
            }
318
            }
313
319
314
            my $plugin;
320
            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 => 30;
27
use Test::More tests => 19;
28
use Test::Warn;
28
use Test::Warn;
29
29
30
use C4::Context;
30
use C4::Context;
Lines 195-217 subtest 'InstallPlugins() tests' => sub { Link Here
195
    Koha::Plugins::Methods->delete;
195
    Koha::Plugins::Methods->delete;
196
    $schema->resultset('PluginData')->delete;
196
    $schema->resultset('PluginData')->delete;
197
197
198
    # Tests for the exclude paramater
198
    # Tests for the exclude parameter
199
    # Test the returned plugins of the InstallPlugins subroutine
199
    # Test the returned plugins of the InstallPlugins subroutine
200
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
200
    my $plugins           = Koha::Plugins->new( { enable_plugins => 1 } );
201
    my @installed_plugins = $plugins->InstallPlugins({ exclude => ["Test", "Koha::Plugin::MarcFieldValues"] });
201
    my @installed_plugins = $plugins->InstallPlugins( { exclude => [ "Test", "Koha::Plugin::MarcFieldValues" ] } );
202
    my $plugin_classes = join(" ", map{$_->{class}} @installed_plugins);
202
    my $plugin_classes    = join( " ", map { $_->{class} } @installed_plugins );
203
203
204
    my $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"]
204
    my $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ]
205
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
205
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
206
    ok($result, "Excluded plugins are not returned");
206
    ok( $result, "Excluded plugins are not returned" );
207
207
208
    # Test the plugins in the database
208
    # Test the plugins in the database
209
    my @plugins = $plugins->GetPlugins({ all => 1, error => 1 });
209
    my @plugins = $plugins->GetPlugins( { all => 1, error => 1 } );
210
    $plugin_classes = join(" ", map{$_->{class}} @plugins);
210
    $plugin_classes = join( " ", map { $_->{class} } @plugins );
211
211
212
    $result = grep { $plugin_classes !~ $_ } [":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$"]
212
    $result = grep { $plugin_classes !~ $_ } [ ":Test |:Test\$", ":MarcFieldValues |:MarcFieldValues\$" ]
213
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
213
        && $plugin_classes =~ ":TestItemBarcodeTransform |:TestItemBarcodeTransform\$";
214
    ok($result, "Excluded plugins are not installed");
214
    ok( $result, "Excluded plugins are not installed" );
215
215
216
    # Remove installed plugins data
216
    # Remove installed plugins data
217
    Koha::Plugins::Methods->delete;
217
    Koha::Plugins::Methods->delete;
Lines 219-240 subtest 'InstallPlugins() tests' => sub { Link Here
219
219
220
    # Tests for the include parameter
220
    # Tests for the include parameter
221
    # Test the returned plugins of the InstallPlugins subroutine
221
    # Test the returned plugins of the InstallPlugins subroutine
222
    @installed_plugins = $plugins->InstallPlugins({ include => ["Test", "Koha::Plugin::MarcFieldValues"]});
222
    @installed_plugins = $plugins->InstallPlugins( { include => [ "Test", "Koha::Plugin::MarcFieldValues" ] } );
223
223
224
    $result = 1;
224
    $result = 1;
225
    foreach my $plugin_class ( map{ $_->{class} } @installed_plugins ) {
225
    foreach my $plugin_class ( map { $_->{class} } @installed_plugins ) {
226
        $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$");
226
        $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" );
227
    }
227
    }
228
    ok($result, "Only included plugins are returned");
228
    ok( $result, "Only included plugins are returned" );
229
229
230
    # Test the plugins in the database
230
    # Test the plugins in the database
231
    @plugins = $plugins->GetPlugins({ all => 1, error => 1});
231
    @plugins = $plugins->GetPlugins( { all => 1, error => 1 } );
232
232
233
    $result = 1;
233
    $result = 1;
234
    foreach my $plugin_class ( map{ $_->{class} } @plugins ) {
234
    foreach my $plugin_class ( map { $_->{class} } @plugins ) {
235
        $result = 0 unless("$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$");
235
        $result = 0 unless ( "$plugin_class" =~ ":Test\$" || "$plugin_class" =~ ":MarcFieldValues\$" );
236
    }
236
    }
237
    ok($result, "Only included plugins are installed");
237
    ok( $result, "Only included plugins are installed" );
238
238
239
    $schema->storage->txn_rollback;
239
    $schema->storage->txn_rollback;
240
};
240
};
241
- 

Return to bug 34978