Bugzilla – Attachment 145527 Details for
Bug 16522
Add 773 (Host item entry) to the cart and list displays and e-mails
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16522: (follow-up) If no 773$w, try to return host record
Bug-16522-follow-up-If-no-773w-try-to-return-host-.patch (text/plain), 5.99 KB, created by
Katrin Fischer
on 2023-01-20 15:38:20 UTC
(
hide
)
Description:
Bug 16522: (follow-up) If no 773$w, try to return host record
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-01-20 15:38:20 UTC
Size:
5.99 KB
patch
obsolete
>From 599c706d067bacde64e9c926aa020a79e6e4ad79 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Mon, 17 Oct 2022 22:38:44 +0000 >Subject: [PATCH] Bug 16522: (follow-up) If no 773$w, try to return host record > >Use host biblionumber or host itemnumber to return a host record if >EasyAnalyticalRecords is enabled, or return an undef record and a string >of host information when get_marc_host is called in list context. > >Confirm tests pass: >- t/db_dependent/Koha/Biblio/host_record.t > >Signed-off-by: Heather Hernandez <heather_hernandez@nps.gov> > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> >--- > Koha/Biblio.pm | 35 ++++++++++++++++++++---- > t/db_dependent/Koha/Biblio/host_record.t | 22 +++++++++++++-- > 2 files changed, 48 insertions(+), 9 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 4b0c14aec9..06d0e86c7f 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -1205,7 +1205,7 @@ sub to_api_mapping { > > $host = $biblio->get_marc_host; > # OR: >- ( $host, $relatedparts ) = $biblio->get_marc_host; >+ ( $host, $relatedparts, $hostinfo ) = $biblio->get_marc_host; > > Returns host biblio record from MARC21 773 (undef if no 773 present). > It looks at the first 773 field with MARCorgCode or only a control >@@ -1214,6 +1214,12 @@ sub to_api_mapping { > If there are, the sub returns undef. > Called in list context, it also returns 773$g (related parts). > >+ If there is no $w, we use $0 (host biblionumber) or $9 (host itemnumber) >+ to search for the host record. If there is also no $0 and no $9, we search >+ using author and title. Failing all of that, we return an undef host and >+ form a concatenation of strings with 773$agt for host information, >+ returned when called in list context. >+ > =cut > > sub get_marc_host { >@@ -1237,18 +1243,35 @@ sub get_marc_host { > last; > } > } >+ >+ my $engine = Koha::SearchEngine::Search->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ my $bibno; > if ( !$hostfld and $record->subfield('773','t') ) { >- # not linked using $w so just return plaintext >+ # not linked using $w > my $unlinkedf = $record->field('773'); >- my $host = join( ", ", $unlinkedf->subfield('a'), $unlinkedf->subfield('t'), $unlinkedf->subfield('g') ); >- return wantarray ? ( $host, $unlinkedf->subfield('g') ) : $host; >+ my $host; >+ if ( C4::Context->preference("EasyAnalyticalRecords") ) { >+ if ( $unlinkedf->subfield('0') ) { >+ # use 773$0 host biblionumber >+ $bibno = $unlinkedf->subfield('0'); >+ } elsif ( $unlinkedf->subfield('9') ) { >+ # use 773$9 host itemnumber >+ my $linkeditemnumber = $unlinkedf->subfield('9'); >+ $bibno = Koha::Items->find( $linkeditemnumber )->biblionumber; >+ } >+ } >+ if ( $bibno ) { >+ my $host = Koha::Biblios->find($bibno) or return; >+ return wantarray ? ( $host, $unlinkedf->subfield('g') ) : $host; >+ } >+ # just return plaintext and no host record >+ my $hostinfo = join( ", ", $unlinkedf->subfield('a'), $unlinkedf->subfield('t'), $unlinkedf->subfield('g') ); >+ return wantarray ? ( undef, $unlinkedf->subfield('g'), $hostinfo ) : undef; > } > return if !$hostfld; > my $rcn = $hostfld->subfield('w'); > > # Look for control number with/without orgcode >- my $engine = Koha::SearchEngine::Search->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >- my $bibno; > for my $try (1..2) { > my ( $error, $results, $total_hits ) = $engine->simple_search_compat( 'Control-number='.$rcn, 0,1 ); > if( !$error and $total_hits == 1 ) { >diff --git a/t/db_dependent/Koha/Biblio/host_record.t b/t/db_dependent/Koha/Biblio/host_record.t >index d348f963c3..4094a102cb 100755 >--- a/t/db_dependent/Koha/Biblio/host_record.t >+++ b/t/db_dependent/Koha/Biblio/host_record.t >@@ -36,13 +36,14 @@ $schema->storage->txn_begin; > our $builder = t::lib::TestBuilder->new; > > subtest 'get_marc_host' => sub { >- plan tests => 12; >+ plan tests => 15; > > t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); > t::lib::Mocks::mock_preference( 'MARCOrgCode', 'xyz' ); > > my $bib1 = $builder->build_object({ class => 'Koha::Biblios' }); > my $bib2 = $builder->build_object({ class => 'Koha::Biblios' }); >+ my $item1 = $builder->build_object({ class => 'Koha::Items', value => { biblionumber => $bib2->biblionumber } }); > my $marc = MARC::Record->new; > my $results = []; > >@@ -72,12 +73,27 @@ subtest 'get_marc_host' => sub { > $marc->field('773')->update( w => '(xyz) bad data' ); # causes no results > $host = $bib1->get_marc_host; > is( $bib1->get_marc_host, undef, 'No results for bad 773' ); >- # Test plaintext when no $w >+ >+ t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 ); >+ # no $w > $marc->field('773')->update( t => 'title' ); > $marc->field('773')->delete_subfield( code => 'w' ); >+ $marc->field('773')->update( '0' => $bib2->biblionumber ); >+ $host = $bib1->get_marc_host; >+ is( $host->biblionumber, $bib2->biblionumber, 'Found host biblio using 773$0 biblionumber' ); >+ >+ $marc->field('773')->delete_subfield( code => '0' ); >+ $marc->field('773')->update( '9' => $item1->itemnumber ); > $host = $bib1->get_marc_host; >- is( $host, "title, relpart", '773$atg returned when no $w' ); >+ is( $host->biblionumber, $bib2->biblionumber, 'Found host item using 773$9 itemnumber' ); >+ >+ $marc->field('773')->delete_subfield( code => '9' ); >+ my ( $relatedparts, $info ); >+ ( $host, $relatedparts, $info ) = $bib1->get_marc_host; >+ is( $host, undef, 'No Koha Biblio object returned with no $w' ); >+ is( $info, "title, relpart", '773$atg returned when no $w' ); > $marc->field('773')->delete_subfield( code => 't' ); # restore >+ > # Add second 773 > $marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) ); > $host = $bib1->get_marc_host; >-- >2.30.2
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 16522
:
114178
|
114429
|
120425
|
130250
|
133509
|
135416
|
137196
|
137197
|
139168
|
139169
|
139846
|
139847
|
139848
|
141058
|
141059
|
141060
|
141061
|
141062
|
141063
|
142036
|
142037
|
142038
|
142039
|
142040
|
142041
|
142042
|
142843
|
144455
|
144456
|
145047
|
145521
|
145522
|
145523
|
145524
|
145525
|
145526
| 145527 |
145528