From 517e7aa4e74eea8fd0abad969408ef33b735a46b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 16 Jul 2021 13:49:32 +0100 Subject: [PATCH] Bug 20447: Fixes for bug 17600 --- Koha/Holding.pm | 21 +++++++++++++++-- Koha/Holdings.pm | 2 +- cataloguing/addholding.pl | 23 +++++++------------ .../marc21_field_008_holdings.pl | 5 ++-- .../value_builder/marc21_leader_holdings.pl | 4 ++-- t/db_dependent/Koha/Holding.t | 3 ++- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Koha/Holding.pm b/Koha/Holding.pm index a37012954e..7d60400d5f 100644 --- a/Koha/Holding.pm +++ b/Koha/Holding.pm @@ -22,9 +22,10 @@ use Modern::Perl; use Carp; -use C4::Charset; # SetUTF8Flag -use C4::Log; # logaction +use C4::Charset qw( SetUTF8Flag ); +use C4::Log qw( logaction ); +use Koha::Biblio; use Koha::Database; use Koha::DateUtils qw(dt_from_string); use Koha::Holdings::Metadatas; @@ -42,6 +43,22 @@ Koha::Holding - Koha Holding Object class =cut +=head3 biblio + + my $biblio = $holding->biblio(); + +Returns the holding biblio for this record. + +=cut + +sub biblio { + my ($self) = @_; + + my $biblio = $self->_result->biblionumber(); + return unless $biblio; + return Koha::Biblio->_new_from_dbic($biblio); +} + =head3 holding_branch my $branch = $hold->holding_branch(); diff --git a/Koha/Holdings.pm b/Koha/Holdings.pm index 5025b624a2..0c6eed8907 100644 --- a/Koha/Holdings.pm +++ b/Koha/Holdings.pm @@ -23,7 +23,7 @@ use Modern::Perl; use Carp; use C4::Biblio; -use C4::Charset; # For SetMarcUnicodeFlag +use C4::Charset qw( SetMarcUnicodeFlag ); use C4::Context; use Koha::Holding; diff --git a/cataloguing/addholding.pl b/cataloguing/addholding.pl index c2a0cff6a7..bd1f3114fd 100755 --- a/cataloguing/addholding.pl +++ b/cataloguing/addholding.pl @@ -20,26 +20,19 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -# TODO: refactor to avoid duplication from addbiblio +use Modern::Perl; -use strict; -#use warnings; FIXME - Bug 2505 use CGI q(-utf8); -use C4::Output; -use C4::Auth; -use C4::Search; -use C4::Biblio; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user haspermission ); +use C4::Biblio + qw( GetMarcFromKohaField GetMarcStructure GetUsedMarcStructure TransformHtmlToMarc ); use C4::Context; use MARC::Record; -use C4::Log; -use C4::Koha; -use C4::ClassSource; -use C4::ImportBatch; -use C4::Charset; +use C4::ClassSource qw( GetClassSources ); use Koha::Biblios; use Koha::BiblioFrameworks; -use Koha::DateUtils; -use C4::Matcher; +use Koha::DateUtils qw( dt_from_string ); use Koha::ItemTypes; use Koha::Libraries; @@ -47,7 +40,7 @@ use Koha::Libraries; use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; -use URI::Escape; +use URI::Escape qw( uri_escape_utf8 ); if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { MARC::File::XML->default_record_format('UNIMARC'); diff --git a/cataloguing/value_builder/marc21_field_008_holdings.pl b/cataloguing/value_builder/marc21_field_008_holdings.pl index 601f7ae076..8e28dd9d6e 100755 --- a/cataloguing/value_builder/marc21_field_008_holdings.pl +++ b/cataloguing/value_builder/marc21_field_008_holdings.pl @@ -19,10 +19,11 @@ # along with Koha; if not, see . use Modern::Perl; -use C4::Auth; +use C4::Auth qw( get_template_and_user ); use CGI qw ( -utf8 ); use C4::Context; -use C4::Output; + +use C4::Output qw( output_html_with_http_headers ); use XML::LibXML; use Koha::Util::FrameworkPlugin qw|date_entered|; diff --git a/cataloguing/value_builder/marc21_leader_holdings.pl b/cataloguing/value_builder/marc21_leader_holdings.pl index f8e5c69a76..959a163c72 100755 --- a/cataloguing/value_builder/marc21_leader_holdings.pl +++ b/cataloguing/value_builder/marc21_leader_holdings.pl @@ -21,9 +21,9 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Auth; +use C4::Auth qw( get_template_and_user ); use C4::Context; -use C4::Output; +use C4::Output qw( output_html_with_http_headers ); my $builder = sub { my ( $params ) = @_; diff --git a/t/db_dependent/Koha/Holding.t b/t/db_dependent/Koha/Holding.t index d69c197dc3..b8db707eca 100755 --- a/t/db_dependent/Koha/Holding.t +++ b/t/db_dependent/Koha/Holding.t @@ -38,7 +38,7 @@ my $schema = Koha::Database->new->schema; subtest 'Koha::Holding tests' => sub { - plan tests => 19; + plan tests => 20; $schema->storage->txn_begin; @@ -167,6 +167,7 @@ subtest 'Koha::Holding tests' => sub { is(ref $holding, 'Koha::Holding', 'Found a Koha::Holding object'); is($holding->frameworkcode(), $frameworkcode, 'Framework code correct in Koha::Holding object'); is($holding->holdingbranch(), 'ABC', 'Location correct in Koha::Holding object'); + is($holding->biblio()->biblionumber(), $biblionumber, 'Biblio correct in Koha::Holding object'); my $branch = $holding->holding_branch(); is(ref $branch, 'Koha::Library', 'holding_branch() returns a Koha::Library object'); -- 2.33.0