Bugzilla – Attachment 73805 Details for
Bug 20310
Article requests: Use details from the host record when submitting an article request on an analytic record without attached items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20310: Introduce Koha::Biblio->host_record
Bug-20310-Introduce-KohaBiblio-hostrecord.patch (text/plain), 4.99 KB, created by
Maksim Sen
on 2018-04-06 22:18:18 UTC
(
hide
)
Description:
Bug 20310: Introduce Koha::Biblio->host_record
Filename:
MIME Type:
Creator:
Maksim Sen
Created:
2018-04-06 22:18:18 UTC
Size:
4.99 KB
patch
obsolete
>From 961d7240a922e20e47bfc3c6a1458968c64f96ea Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 21 Mar 2018 16:52:10 +0100 >Subject: [PATCH] Bug 20310: Introduce Koha::Biblio->host_record > >This is a more generic method that allows you to get to the host record >as defined in MARC21 field 773$w. > >Test plan: >Run t/db_dependent/Koha/Biblio/host_record.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Maksim Sen <maksim.sen@inlibro.com> >--- > Koha/Biblio.pm | 32 ++++++++++++++ > t/db_dependent/Koha/Biblio/host_record.t | 75 ++++++++++++++++++++++++++++++++ > 2 files changed, 107 insertions(+) > create mode 100644 t/db_dependent/Koha/Biblio/host_record.t > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index d226304..f89caa3 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -355,6 +355,38 @@ sub has_items_waiting_or_intransit { > return 0; > } > >+=head3 host_record >+ >+ $host = $biblio->host_record; >+ ( $host, $relatedparts ) = $biblio->host_record; >+ >+ Returns host biblio record from MARC21 773 (undef if no 773 present). >+ Currently, looks only at the first 773 field. >+ The optional parameter no_items triggers a check if $biblio has items. >+ If there are, the sub returns undef. >+ Called in list context, it also returns 773$g (related parts). >+ >+=cut >+ >+sub host_record { >+ my ($self, $params) = @_; >+ my $no_items = $params->{no_items}; >+ >+ return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO >+ return if $params->{no_items} && $self->items->count > 0; >+ my $marc = C4::Biblio::GetMarcBiblio($self->biblionumber); >+ my $hostfld = $marc->field('773'); >+ return if !$hostfld; >+ >+ # Extract record control number >+ my $rcn; >+ if( $hostfld->subfield('w') =~ /\)\s*(\d+)/ ) { >+ $rcn= $1; >+ } >+ my $host = $rcn ? Koha::Biblios->find($rcn) : undef; >+ return wantarray ? ( $host, $hostfld->subfield('g') ) : $host; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Biblio/host_record.t b/t/db_dependent/Koha/Biblio/host_record.t >new file mode 100644 >index 0000000..ab21a03 >--- /dev/null >+++ b/t/db_dependent/Koha/Biblio/host_record.t >@@ -0,0 +1,75 @@ >+#!/usr/bin/perl >+ >+# 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>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Data::Dumper qw/Dumper/; >+use MARC::Field; >+use MARC::Record; >+use Test::MockModule; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+use Koha::Database; >+use Koha::Biblios; >+use C4::Biblio; >+ >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+our $builder = t::lib::TestBuilder->new; >+our $marc; >+ >+subtest 'host_record' => sub { >+ plan tests => 9; >+ >+ t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); >+ my $mod = Test::MockModule->new('C4::Biblio'); >+ $mod->mock( 'GetMarcBiblio', sub { return $marc; } ); >+ >+ my $bib1 = $builder->build_object({ class => 'Koha::Biblios' }); >+ my $bib2 = $builder->build_object({ class => 'Koha::Biblios' }); >+ $marc = MARC::Record->new; >+ >+ is( $bib1->host_record, undef, 'Empty MARC record' ); >+ $marc->append_fields( >+ MARC::Field->new( '773', '', '', g => 'relpart', w => 'xyz' ), >+ ); >+ is( $bib1->host_record, undef, 'No control number found' ); >+ $marc->field('773')->update( w => 'xyz)' . ($bib2->biblionumber + 1) ); >+ is( $bib1->host_record, undef, 'Control number does not exist' ); >+ # Make it work now >+ $marc->field('773')->update( w => 'xyz)' . $bib2->biblionumber ); >+ my $host = $bib1->host_record; >+ is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); >+ is( $host->biblionumber, $bib2->biblionumber, 'Check biblionumber' ); >+ # Add second 773 >+ $marc->append_fields( MARC::Field->new( '773', '', '', w => 'second' ) ); >+ $host = $bib1->host_record; >+ is( $host->biblionumber, $bib2->biblionumber, 'Two 773s, record still found' ); >+ # Test no_items flag >+ $host = $bib1->host_record({ no_items => 1 }); >+ is( $host->biblionumber, $bib2->biblionumber, 'Record found with no_items' ); >+ $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); >+ is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); >+ # Test list context >+ my @temp = $bib1->host_record; >+ is( $temp[1], 'relpart', 'Return $g in list context' ); >+}; >+ >+$schema->storage->txn_rollback(); >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20310
:
73142
|
73143
|
73805
|
73998
|
74000
|
74992
|
74993
|
74994
|
88887
|
88888
|
88889
|
109750
|
109751
|
109752
|
109753
|
111467
|
111468
|
111469
|
111470
|
118976
|
118977
|
118978
|
118979
|
119346
|
122469
|
122470
|
122471
|
122472
|
122473
|
122474
|
122475
|
122725
|
122726
|
122727
|
122728
|
122729
|
122730
|
122731
|
122732