Bugzilla – Attachment 127330 Details for
Bug 27266
Move C4::Biblio::GetMarcAuthors to Koha namespace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27266: Move GetMarcAuthors to Koha namespace
Bug-27266-Move-GetMarcAuthors-to-Koha-namespace.patch (text/plain), 18.14 KB, created by
Marcel de Rooy
on 2021-11-05 08:27:56 UTC
(
hide
)
Description:
Bug 27266: Move GetMarcAuthors to Koha namespace
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-11-05 08:27:56 UTC
Size:
18.14 KB
patch
obsolete
>From 9b4b8ee6433dee717e1d43d59e5a9f3af19d56ab Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Fri, 18 Dec 2020 13:51:26 +1300 >Subject: [PATCH] Bug 27266: Move GetMarcAuthors to Koha namespace >MIME-Version: 1.0 >Content-Type: text/plain; charset=utf-8 >Content-Transfer-Encoding: 8bit >Content-Type: text/plain; charset=utf-8 > >This patch moves C4::Biblio::GetMarcAuthors to >Koha::Biblio->get_authors_from_MARC. This is so the method can be >used in templates and notices. > >To test: >1. Find a record that has an author in the added entry field (700-720). >2. Add the record to the cart and a list. >3. View your cart and click 'more details'. Confirm authors show as >normal. >4. Click 'send' and confirm the email sent shows the authors as normal. >5. Go to the list you added the record to and click 'send list'. Confirm >the email sent shows the authors as normal. >xslt) >6. Log in to the OPAC. Find the record and add it to the cart and a list >7. View the cart and click 'more details'. Confirm authors show as >normal. >8. Click 'send' and confirm the email sent shows the authors as normal. >9. Go to the list you added the record to and click 'send list'. >Confirm the email sent shows the authors as normal. >10. Confirm tests pass: >- t/Biblio.t >- t/db_dependent/Koha/Biblio.t > >Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Biblio.pm | 100 ----------------------------------- > Koha/Biblio.pm | 97 +++++++++++++++++++++++++++++++++ > basket/basket.pl | 2 +- > basket/sendbasket.pl | 3 +- > opac/opac-basket.pl | 2 +- > opac/opac-detail.pl | 2 + > opac/opac-sendbasket.pl | 3 +- > opac/opac-sendshelf.pl | 3 +- > t/Biblio.t | 8 +-- > t/db_dependent/Koha/Biblio.t | 30 ++++++++++- > virtualshelves/sendshelf.pl | 3 +- > 11 files changed, 139 insertions(+), 114 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 863ce496ef..08b62d8436 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -35,7 +35,6 @@ BEGIN { > GetMarcISBN > GetMarcISSN > GetMarcSubjects >- GetMarcAuthors > GetMarcSeries > GetMarcUrls > GetUsedMarcStructure >@@ -1658,105 +1657,6 @@ sub GetMarcSubjects { > return \@marcsubjects; > } #end getMARCsubjects > >-=head2 GetMarcAuthors >- >- authors = GetMarcAuthors($record,$marcflavour); >- >-Get all authors from the MARC record and returns them in an array. >-The authors are stored in different fields depending on MARC flavour >- >-=cut >- >-sub GetMarcAuthors { >- my ( $record, $marcflavour ) = @_; >- if (!$record) { >- carp 'GetMarcAuthors called on undefined record'; >- return; >- } >- my ( $mintag, $maxtag, $fields_filter ); >- >- # tagslib useful only for UNIMARC author responsibilities >- my $tagslib; >- if ( $marcflavour eq "UNIMARC" ) { >- # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. >- $tagslib = GetMarcStructure( 1, '', { unsafe => 1 }); >- $mintag = "700"; >- $maxtag = "712"; >- $fields_filter = '7..'; >- } else { # marc21 >- $mintag = "700"; >- $maxtag = "720"; >- $fields_filter = '7..'; >- } >- >- my @marcauthors; >- my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); >- >- foreach my $field ( $record->field($fields_filter) ) { >- next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; >- my @subfields_loop; >- my @link_loop; >- my @subfields = $field->subfields(); >- my $count_auth = 0; >- >- # if there is an authority link, build the link with Koha-Auth-Number: subfield9 >- my $subfield9 = $field->subfield('9'); >- if ($subfield9) { >- my $linkvalue = $subfield9; >- $linkvalue =~ s/(\(|\))//g; >- @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } ); >- } >- >- # other subfields >- my $unimarc3; >- for my $authors_subfield (@subfields) { >- next if ( $authors_subfield->[0] eq '9' ); >- >- # unimarc3 contains the $3 of the author for UNIMARC. >- # For french academic libraries, it's the "ppn", and it's required for idref webservice >- $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/; >- >- # don't load unimarc subfields 3, 5 >- next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) ); >- >- my $code = $authors_subfield->[0]; >- my $value = $authors_subfield->[1]; >- my $linkvalue = $value; >- $linkvalue =~ s/(\(|\))//g; >- # UNIMARC author responsibility >- if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) { >- $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib ); >- $linkvalue = "($value)"; >- } >- # if no authority link, build a search query >- unless ($subfield9) { >- push @link_loop, { >- limit => 'au', >- 'link' => $linkvalue, >- operator => (scalar @link_loop) ? ' and ' : undef >- }; >- } >- my @this_link_loop = @link_loop; >- # do not display $0 >- unless ( $code eq '0') { >- push @subfields_loop, { >- tag => $field->tag(), >- code => $code, >- value => $value, >- link_loop => \@this_link_loop, >- separator => (scalar @subfields_loop) ? $AuthoritySeparator : '' >- }; >- } >- } >- push @marcauthors, { >- MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop, >- authoritylink => $subfield9, >- unimarc3 => $unimarc3 >- }; >- } >- return \@marcauthors; >-} >- > =head2 GetMarcUrls > > $marcurls = GetMarcUrls($record,$marcflavour); >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index c4c12128af..df741507f6 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -966,6 +966,103 @@ sub get_marc_notes { > return \@marcnotes; > } > >+=head3 get_authors_from_MARC >+ >+ my $authors = $biblio->get_authors_from_MARC; >+ >+Get all authors from the MARC record and returns them in an array. >+The authors are stored in different fields depending on MARC flavour >+ >+=cut >+ >+sub get_authors_from_MARC { >+ my ( $self, $params ) = @_; >+ >+ my ( $mintag, $maxtag, $fields_filter ); >+ my $marcflavour = C4::Context->preference('marcflavour'); >+ >+ # tagslib useful only for UNIMARC author responsibilities >+ my $tagslib; >+ if ( $marcflavour eq "UNIMARC" ) { >+ # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct. >+ $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 }); >+ $mintag = "700"; >+ $maxtag = "712"; >+ $fields_filter = '7..'; >+ } else { # marc21/normarc >+ $mintag = "700"; >+ $maxtag = "720"; >+ $fields_filter = '7..'; >+ } >+ >+ my @marcauthors; >+ my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); >+ >+ foreach my $field ( $self->metadata->record->field($fields_filter) ) { >+ next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; >+ my @subfields_loop; >+ my @link_loop; >+ my @subfields = $field->subfields(); >+ my $count_auth = 0; >+ >+ # if there is an authority link, build the link with Koha-Auth-Number: subfield9 >+ my $subfield9 = $field->subfield('9'); >+ if ($subfield9) { >+ my $linkvalue = $subfield9; >+ $linkvalue =~ s/(\(|\))//g; >+ @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } ); >+ } >+ >+ # other subfields >+ my $unimarc3; >+ for my $authors_subfield (@subfields) { >+ next if ( $authors_subfield->[0] eq '9' ); >+ >+ # unimarc3 contains the $3 of the author for UNIMARC. >+ # For french academic libraries, it's the "ppn", and it's required for idref webservice >+ $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/; >+ >+ # don't load unimarc subfields 3, 5 >+ next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) ); >+ >+ my $code = $authors_subfield->[0]; >+ my $value = $authors_subfield->[1]; >+ my $linkvalue = $value; >+ $linkvalue =~ s/(\(|\))//g; >+ # UNIMARC author responsibility >+ if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) { >+ $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib ); >+ $linkvalue = "($value)"; >+ } >+ # if no authority link, build a search query >+ unless ($subfield9) { >+ push @link_loop, { >+ limit => 'au', >+ 'link' => $linkvalue, >+ operator => (scalar @link_loop) ? ' and ' : undef >+ }; >+ } >+ my @this_link_loop = @link_loop; >+ # do not display $0 >+ unless ( $code eq '0') { >+ push @subfields_loop, { >+ tag => $field->tag(), >+ code => $code, >+ value => $value, >+ link_loop => \@this_link_loop, >+ separator => (scalar @subfields_loop) ? $AuthoritySeparator : '' >+ }; >+ } >+ } >+ push @marcauthors, { >+ MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop, >+ authoritylink => $subfield9, >+ unimarc3 => $unimarc3 >+ }; >+ } >+ return \@marcauthors; >+} >+ > =head3 to_api > > my $json = $biblio->to_api; >diff --git a/basket/basket.pl b/basket/basket.pl >index 30f73b8783..a5169531cc 100755 >--- a/basket/basket.pl >+++ b/basket/basket.pl >@@ -72,7 +72,7 @@ foreach my $biblionumber ( @bibs ) { > my $biblio = Koha::Biblios->find( $biblionumber ); > my $record = &GetMarcBiblio({ biblionumber => $biblionumber }); > my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > my $marcseriesarray = GetMarcSeries ($record,$marcflavour); > my $marcurlsarray = GetMarcUrls ($record,$marcflavour); >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index 1ea56fce6a..6110a601f0 100755 >--- a/basket/sendbasket.pl >+++ b/basket/sendbasket.pl >@@ -74,10 +74,11 @@ if ( $email_add ) { > > my $dat = GetBiblioData($biblionumber); > next unless $dat; >+ my $biblio = Koha::Biblios->find( $biblionumber ); > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, > embed_items => 1 }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > > my @items = GetItemsInfo( $biblionumber ); >diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl >index ef4a25700f..a3797132ba 100755 >--- a/opac/opac-basket.pl >+++ b/opac/opac-basket.pl >@@ -94,7 +94,7 @@ foreach my $biblionumber ( @bibs ) { > $record_processor->process($record); > next unless $record; > my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > my $marcseriesarray = GetMarcSeries ($record,$marcflavour); > my $marcurlsarray = GetMarcUrls ($record,$marcflavour); >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 69b791e1d5..30bb53b0fe 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -784,6 +784,7 @@ if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { > } > > my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 }); >+my $marcauthorsarray = $biblio->get_authors_from_MARC; > > if( C4::Context->preference('ArticleRequests') ) { > my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef; >@@ -799,6 +800,7 @@ if( C4::Context->preference('ArticleRequests') ) { > my $norequests = ! $biblio->items->filter_by_for_hold->count; > $template->param( > MARCNOTES => $marcnotesarray, >+ MARCAUTHORS => $marcauthorsarray, > norequests => $norequests, > RequestOnOpac => C4::Context->preference("RequestOnOpac"), > itemdata_ccode => $itemfields{ccode}, >diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl >index fdf8671ecb..cb43af3b28 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -81,12 +81,13 @@ if ( $email_add ) { > > my $dat = GetBiblioData($biblionumber); > next unless $dat; >+ my $biblio = Koha::Biblios->find( $biblionumber ); > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, > embed_items => 1, > opac => 1, > borcat => $borcat }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > > my @items = GetItemsInfo( $biblionumber ); >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index 825de8175e..c8f9ed496a 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -92,10 +92,11 @@ if ( $email ) { > opac => 1, > borcat => $borcat }); > next unless $record; >+ my $biblio = Koha::Biblios->find( $biblionumber ); > my $fw = GetFrameworkCode($biblionumber); > my $dat = GetBiblioData($biblionumber); > >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > > my @items = GetItemsInfo( $biblionumber ); >diff --git a/t/Biblio.t b/t/Biblio.t >index 91080bdf96..1b84ba8f8c 100755 >--- a/t/Biblio.t >+++ b/t/Biblio.t >@@ -21,7 +21,7 @@ use Test::More; > use Test::MockModule; > use Test::Warn; > >-plan tests => 39; >+plan tests => 37; > > > use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcAuthors GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues )); >@@ -94,12 +94,6 @@ warning_is { $ret = GetMarcSubjects() } > > ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec'); > >-warning_is { $ret = GetMarcAuthors() } >- { carped => 'GetMarcAuthors called on undefined record'}, >- "GetMarcAuthors returns carped warning on undef record"; >- >-ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec'); >- > warning_is { $ret = GetMarcUrls() } > { carped => 'GetMarcUrls called on undefined record'}, > "GetMarcUrls returns carped warning on undef record"; >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index 73dcb2ab13..a666be265b 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 19; >+use Test::More tests => 20; > use Test::Warn; > > use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc ); >@@ -859,6 +859,34 @@ subtest 'current_checkouts() and old_checkouts() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'get_authors_from_MARC() tests' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $record = $biblio->metadata->record; >+ >+ # add author information >+ my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas'); >+ $record->append_fields($field); >+ $field = MARC::Field->new('700','1','','d' => '1743-1826'); >+ $record->append_fields($field); >+ $field = MARC::Field->new('700','1','','e' => 'former owner.'); >+ $record->append_fields($field); >+ $field = MARC::Field->new('700','1','','5' => 'MH'); >+ $record->append_fields($field); >+ >+ # get record >+ C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); >+ $biblio = Koha::Biblios->find( $biblio->biblionumber ); >+ >+ is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > sub component_record1 { > my $marc = MARC::Record->new; > $marc->append_fields( >diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl >index bc47249744..58b4d144a2 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/sendshelf.pl >@@ -73,11 +73,12 @@ if ($to_address) { > > while ( my $content = $contents->next ) { > my $biblionumber = $content->biblionumber; >+ my $biblio = Koha::Biblios->find( $biblionumber ); > my $dat = GetBiblioData($biblionumber); > my $record = GetMarcBiblio({ > biblionumber => $biblionumber, > embed_items => 1 }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcauthorsarray = $biblio->get_authors_from_MARC; > my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); > > my @items = GetItemsInfo($biblionumber); >-- >2.20.1
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 27266
:
114503
|
114580
|
117239
|
118311
|
118312
|
123017
|
123018
|
123019
|
123026
|
123027
|
123028
|
123067
|
125440
|
125441
|
125442
|
125443
|
125444
|
125465
|
125466
|
125467
|
125468
|
125469
|
125719
|
125720
|
125721
|
125722
|
125723
|
126539
|
126540
|
126541
|
126542
|
126543
|
127330
|
127331
|
127332
|
127333
|
127334
|
127335
|
127336
|
127337
|
127340
|
127341
|
127342
|
127561
|
127562
|
127563
|
127564
|
127565
|
127566
|
127567
|
127568