Bugzilla – Attachment 88889 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: (follow-up) Allow repeatable $w even without org code
Bug-20310-follow-up-Allow-repeatable-w-even-withou.patch (text/plain), 5.45 KB, created by
Hugo Agud
on 2019-04-26 10:47:59 UTC
(
hide
)
Description:
Bug 20310: (follow-up) Allow repeatable $w even without org code
Filename:
MIME Type:
Creator:
Hugo Agud
Created:
2019-04-26 10:47:59 UTC
Size:
5.45 KB
patch
obsolete
>From 7c79fadd182c3844469bcf943610c8fda87725a1 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 11 Apr 2018 14:47:23 +0200 >Subject: [PATCH] Bug 20310: (follow-up) Allow repeatable $w even without org > code > >As mentioned in the BZ comments, we might expect people to add $w >subfields without a MARC organization code. And we should keep in >mind that 773 is repeatable, and both $g as well as $w is also >repeatable. > >Added these cases into sub host_record, including tests. > >Test plan: >Run t/db_dependent/Koha/Biblio/host_record.t again > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Hugo Agud <hagud@orex.es> >--- > Koha/Biblio.pm | 25 ++++++++++++++++++------- > t/db_dependent/Koha/Biblio/host_record.t | 28 +++++++++++++++++++--------- > 2 files changed, 37 insertions(+), 16 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 8783cdec80..22628f76ee 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -489,16 +489,27 @@ sub host_record { > return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO > return if $params->{no_items} && $self->items->count > 0; > my $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $self->biblionumber }); >- my $hostfld = $marc->field('773'); >- return if !$hostfld; >+ my @hostfld = $marc->field('773'); >+ return if !@hostfld; > > # Extract record control number >- my $rcn; >- if( $hostfld->subfield('w') =~ /\)\s*(\d+)/ ) { >- $rcn= $1; >+ # We pick the first $w with your MARCOrgCode or the first $w that has no >+ # code (between parentheses) at all. >+ # Since $g is repeatable too, we join them together. >+ my $orgcode = C4::Context->preference('MARCOrgCode') // q{}; >+ my $result = {}; >+ foreach my $f ( @hostfld ) { >+ push my @subfields, $f->subfield('w'); >+ my @rcn = map { /^\($orgcode\)\s*(\d+)/i ? $1 : (); } @subfields; >+ @rcn = map { /^\s*(\d+)/ ? $1 : (); } @subfields if !@rcn; >+ if( @rcn ) { >+ $result = { rcn => $rcn[0], subg => (join ';', $f->subfield('g')) }; >+ last; >+ } > } >- my $host = $rcn ? Koha::Biblios->find($rcn) : undef; >- return wantarray ? ( $host, $hostfld->subfield('g') ) : $host; >+ >+ my $host = $result->{rcn} ? Koha::Biblios->find($result->{rcn}) : undef; >+ return wantarray ? ( $host, $result->{subg} ) : $host; > } > > =head3 type >diff --git a/t/db_dependent/Koha/Biblio/host_record.t b/t/db_dependent/Koha/Biblio/host_record.t >index ab21a0327b..81551515df 100644 >--- a/t/db_dependent/Koha/Biblio/host_record.t >+++ b/t/db_dependent/Koha/Biblio/host_record.t >@@ -36,9 +36,10 @@ our $builder = t::lib::TestBuilder->new; > our $marc; > > subtest 'host_record' => sub { >- plan tests => 9; >+ plan tests => 10; > > t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); >+ t::lib::Mocks::mock_preference( 'MARCOrgCode', 'xyz' ); > my $mod = Test::MockModule->new('C4::Biblio'); > $mod->mock( 'GetMarcBiblio', sub { return $marc; } ); > >@@ -48,28 +49,37 @@ subtest 'host_record' => sub { > > is( $bib1->host_record, undef, 'Empty MARC record' ); > $marc->append_fields( >- MARC::Field->new( '773', '', '', g => 'relpart', w => 'xyz' ), >+ MARC::Field->new( '773', '', '', g => 'g1', g => 'g2', w => '(xyz)' ), > ); > is( $bib1->host_record, undef, 'No control number found' ); >- $marc->field('773')->update( w => 'xyz)' . ($bib2->biblionumber + 1) ); >+ $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 ); >+ >+ # Now replace by number without code >+ $marc->field('773')->update( w => $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' ) ); >+ # Replace first $w, add second 773 with code and wrong number >+ $marc->field('773')->update( w => '(zzz)123' ); >+ $marc->append_fields( MARC::Field->new( '773', '', '', w => '(xyz)'. ( $bib2->biblionumber + 1 ) ) ); >+ is( $bib1->host_record, undef, 'No control number found' ); >+ # Change second 773 to a correct number (adding another $w) >+ ($marc->field('773'))[1]->update( w => '(zzz)'.$bib2->biblionumber ); >+ ($marc->field('773'))[1]->add_subfields( w => '(xyz)'.$bib1->biblionumber ); > $host = $bib1->host_record; >- is( $host->biblionumber, $bib2->biblionumber, 'Two 773s, record still found' ); >+ is( $host->biblionumber, $bib1->biblionumber, 'Found last biblionumber' ); >+ $marc->delete_fields( ($marc->field('773'))[1] ); # remove second 773 >+ > # Test no_items flag >+ $marc->field('773')->update( w => '(xyz)'.$bib2->biblionumber ); > $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' ); >+ is( $temp[1], 'g1;g2', 'Return $g in list context' ); > }; > > $schema->storage->txn_rollback(); >-- >2.11.0
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