Tomas Cohen Arazi
05705ab2ad
This patch makes Koha::Logger initialization happen in the ->new method for the Koha::ExternalContent-derived classes. In the case of RecordedBooks, it doesn't look like it is used at all. In the case of OverDrive, it will now use the Koha::ExternalContent exported logger accessor. I added tests for this addition to Koha::ExternalContent to the OverDrive tests. I also removed references to Test::DBIx::Class as it is not used at all. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha_ExternalContent_OverDrive.t => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
105 lines
2.3 KiB
Perl
105 lines
2.3 KiB
Perl
# Copyright 2014 Catalyst
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
package Koha::ExternalContent;
|
|
|
|
use Modern::Perl;
|
|
use Carp;
|
|
use base qw(Class::Accessor);
|
|
|
|
use Koha;
|
|
use Koha::Logger;
|
|
use Koha::Patrons;
|
|
use C4::Auth;
|
|
|
|
__PACKAGE__->mk_accessors(qw(client koha_session_id koha_patron logger));
|
|
|
|
=head1 NAME
|
|
|
|
Koha::ExternalContent
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use Koha::ExternalContent;
|
|
my $externalcontent = Koha::ExternalContent->new();
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Base class for interfacing with external content providers.
|
|
|
|
Subclasses provide clients for particular systems. This class provides
|
|
common methods for getting Koha patron.
|
|
|
|
=head1 METHODS
|
|
|
|
=cut
|
|
|
|
sub agent_string {
|
|
return 'Koha/'.Koha::version();
|
|
}
|
|
|
|
sub new {
|
|
my $class = shift;
|
|
my $params = shift || {};
|
|
|
|
$params->{logger} = Koha::Logger->get();
|
|
|
|
return bless $params, $class;
|
|
}
|
|
|
|
sub _koha_session {
|
|
my $self = shift;
|
|
my $session_id = $self->koha_session_id or return;
|
|
return C4::Auth::get_session($session_id);
|
|
}
|
|
|
|
sub get_from_koha_session {
|
|
my $self = shift;
|
|
my $key = shift or croak "No key";
|
|
my $session = $self->_koha_session or return;
|
|
return $session->param($key);
|
|
}
|
|
|
|
sub set_in_koha_session {
|
|
my $self = shift;
|
|
my $key = shift or croak "No key";
|
|
my $value = shift;
|
|
my $session = $self->_koha_session or croak "No Koha session";
|
|
return $session->param($key, $value);
|
|
}
|
|
|
|
sub koha_patron {
|
|
my $self = shift;
|
|
|
|
if (my $patron = $self->_koha_patron_accessor) {
|
|
return $patron;
|
|
}
|
|
|
|
my $id = $self->get_from_koha_session('number')
|
|
or return;
|
|
my $patron = Koha::Patrons->find($id)
|
|
or die "Invalid patron number in session";
|
|
return $self->_koha_patron_accessor($patron);
|
|
}
|
|
|
|
=head1 AUTHOR
|
|
|
|
CatalystIT
|
|
|
|
=cut
|
|
|
|
1;
|