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

(-)a/Koha/Illrequest.pm (-12 / +76 lines)
Lines 396-401 sub status { Link Here
396
    }
396
    }
397
}
397
}
398
398
399
=head3 get_backend_plugin
400
401
    my $backend_plugin = $self->get_backend_plugin($backend_name);
402
403
Returns the installed I<Koha::Plugin> corresponding to the given backend_id
404
405
=cut
406
407
sub get_backend_plugin {
408
    my ( $self, $backend_id ) = @_;
409
410
    my @backend_plugins = Koha::Plugins->new()->GetPlugins(
411
        {
412
            method   => 'ill_backend',
413
            metadata => { name => $backend_id },
414
            all      => 1,
415
            errors   => 1
416
        }
417
    );
418
419
    return $backend_plugins[0];
420
}
421
399
=head3 load_backend
422
=head3 load_backend
400
423
401
Require "Base.pm" from the relevant ILL backend.
424
Require "Base.pm" from the relevant ILL backend.
Lines 405-412 Require "Base.pm" from the relevant ILL backend. Link Here
405
sub load_backend {
428
sub load_backend {
406
    my ( $self, $backend_id ) = @_;
429
    my ( $self, $backend_id ) = @_;
407
430
408
    my @raw = qw/Koha Illbackends/; # Base Path
409
410
    my $backend_name = $backend_id || $self->backend;
431
    my $backend_name = $backend_id || $self->backend;
411
432
412
    unless ( defined $backend_name && $backend_name ne '' ) {
433
    unless ( defined $backend_name && $backend_name ne '' ) {
Lines 414-426 sub load_backend { Link Here
414
            "An invalid backend ID was requested ('')");
435
            "An invalid backend ID was requested ('')");
415
    }
436
    }
416
437
417
    my $location = join "/", @raw, $backend_name, "Base.pm";    # File to load
438
    my $backend_plugin = $self->get_backend_plugin($backend_name);
418
    my $backend_class = join "::", @raw, $backend_name, "Base"; # Package name
439
    if ($backend_plugin) {
419
    require $location;
440
420
    $self->{_my_backend} = $backend_class->new({
441
        # New way of loading backends: Through plugins
421
        config => $self->_config,
442
        my $backend_plugin_class = $backend_plugin->{class};
422
        logger => Koha::Illrequest::Logger->new
443
423
    });
444
        $self->{_my_backend} = $backend_plugin_class->new_backend(
445
            {
446
                config => $self->_config,
447
                logger => Koha::Illrequest::Logger->new
448
            }
449
        );
450
    } elsif ($backend_name) {
451
452
        # Old way of loading backends: Through backend_dir config
453
        my @raw           = qw/Koha Illbackends/;                         # Base Path
454
        my $location      = join "/",  @raw, $backend_name, "Base.pm";    # File to load
455
        my $backend_class = join "::", @raw, $backend_name, "Base";       # Package name
456
        require $location;
457
        $self->{_my_backend} = $backend_class->new(
458
            {
459
                config => $self->_config,
460
                logger => Koha::Illrequest::Logger->new
461
            }
462
        );
463
    }
464
424
    return $self;
465
    return $self;
425
}
466
}
426
467
Lines 506-512 sub _config { Link Here
506
547
507
sub metadata {
548
sub metadata {
508
    my ( $self ) = @_;
549
    my ( $self ) = @_;
509
    return $self->_backend->metadata($self);
550
551
    if ( $self->_backend->can('metadata') ) {
552
553
        # Old way of loading backends: Previous expected method was 'metadata'
554
        return $self->_backend->metadata($self);
555
    } else {
556
557
        # New way of loading backends (as plugins): New expected method is 'backend_metadata'
558
        return $self->_backend->backend_metadata($self);
559
    }
510
}
560
}
511
561
512
=head3 _core_status_graph
562
=head3 _core_status_graph
Lines 1030-1037 sub expand_template { Link Here
1030
    my ( $self, $params ) = @_;
1080
    my ( $self, $params ) = @_;
1031
    my $backend = $self->_backend->name;
1081
    my $backend = $self->_backend->name;
1032
    # Generate path to file to load
1082
    # Generate path to file to load
1033
    my $backend_dir = $self->_config->backend_dir;
1083
    my $backend_dir;
1034
    my $backend_tmpl = join "/", $backend_dir, $backend;
1084
    my $backend_tmpl;
1085
1086
    my $backend_plugin = $self->get_backend_plugin( $self->_backend->name );
1087
    if ($backend_plugin) {
1088
1089
        # New way of loading backends: Through plugins
1090
        $backend_dir  = $backend_plugin->bundle_path;
1091
        $backend_tmpl = $backend_dir;
1092
    } else {
1093
1094
        # Old way of loading backends: Through backend_dir config
1095
        $backend_dir  = $self->_config->backend_dir;
1096
        $backend_tmpl = join "/", $backend_dir, $backend;
1097
    }
1098
1035
    my $intra_tmpl =  join "/", $backend_tmpl, "intra-includes",
1099
    my $intra_tmpl =  join "/", $backend_tmpl, "intra-includes",
1036
        ( $params->{method}//q{} ) . ".inc";
1100
        ( $params->{method}//q{} ) . ".inc";
1037
    my $opac_tmpl =  join "/", $backend_tmpl, "opac-includes",
1101
    my $opac_tmpl =  join "/", $backend_tmpl, "opac-includes",
(-)a/Koha/Illrequest/Config.pm (-2 / +36 lines)
Lines 23-28 use File::Basename qw( basename ); Link Here
23
23
24
use C4::Context;
24
use C4::Context;
25
25
26
use List::MoreUtils qw( uniq );
27
26
=head1 NAME
28
=head1 NAME
27
29
28
Koha::Illrequest::Config - Koha ILL Configuration Object
30
Koha::Illrequest::Config - Koha ILL Configuration Object
Lines 102-107 sub backend_dir { Link Here
102
    return $self->{configuration}->{backend_directory};
104
    return $self->{configuration}->{backend_directory};
103
}
105
}
104
106
107
=head3 get_installed_backend_plugins
108
109
    $backends = $config->get_installed_backend_plugins;
110
111
Returns a list of all installed ILL backend plugins
112
113
=cut
114
115
sub get_installed_backend_plugins {
116
    my ( $self, $reduce ) = @_;
117
118
    my @backend_plugins = Koha::Plugins->new()->GetPlugins(
119
        {
120
            method => 'ill_backend',
121
            all    => 1,
122
            errors => 1
123
        }
124
    );
125
126
    return map { $_->{metadata}->{name} } @backend_plugins;
127
}
128
105
=head3 available_backends
129
=head3 available_backends
106
130
107
  $backends = $config->available_backends;
131
  $backends = $config->available_backends;
Lines 114-125 will filter those backends down to only those present in the list. Link Here
114
138
115
sub available_backends {
139
sub available_backends {
116
    my ( $self, $reduce ) = @_;
140
    my ( $self, $reduce ) = @_;
141
142
    # New way of loading backends: Through plugins
143
    my @backend_plugins_names = $self->get_installed_backend_plugins;
144
145
    # Old way of loading backends: Through backend_dir config
117
    my $backend_dir = $self->backend_dir;
146
    my $backend_dir = $self->backend_dir;
118
    my @backends = ();
147
    my @backends = ();
119
    @backends = glob "$backend_dir/*" if ( $backend_dir );
148
    @backends = glob "$backend_dir/*" if ( $backend_dir );
120
    @backends = map { basename($_) } @backends;
149
    @backends = map { basename($_) } @backends;
121
    @backends = grep { $_ =~ /$reduce/ } @backends if $reduce;
150
    @backends = grep { $_ =~ /$reduce/ } @backends if $reduce;
122
    return \@backends;
151
152
    # Return unique list of backend names in the event that the same backend is
153
    # installed as a plugin AND as the old way through backend_dir
154
    my @all_backends = ( @backends, @backend_plugins_names );
155
    my @all_uniq_backends = uniq(@all_backends);
156
157
    return \@all_uniq_backends;
123
}
158
}
124
159
125
=head3 has_branch
160
=head3 has_branch
126
- 

Return to bug 19605