From cba52e3ffba4fa9a0ecc84eab02ea48e6e4802ce Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 21 Jan 2022 14:41:41 +0100 Subject: [PATCH] Bug 29697: Use flag embed_items Includes: Bug 29697: (follow-up) Use flag embed_items Signed-off-by: Marcel de Rooy --- C4/Biblio.pm | 164 +----------------- C4/ILSDI/Services.pm | 8 +- C4/OAI/Sets.pm | 12 +- C4/Record.pm | 14 +- Koha/Biblio/Metadata.pm | 105 ++++++++++- Koha/BiblioUtils.pm | 18 +- Koha/BiblioUtils/Iterator.pm | 12 +- Koha/OAI/Server/Repository.pm | 11 +- Koha/SearchEngine/Elasticsearch/Indexer.pm | 4 +- basket/downloadcart.pl | 11 +- basket/sendbasket.pl | 6 +- catalogue/ISBDdetail.pl | 24 ++- catalogue/MARCdetail.pl | 7 +- catalogue/detail.pl | 4 +- catalogue/export.pl | 7 +- misc/batchRebuildItemsTables.pl | 9 +- misc/cronjobs/build_browser_and_cloud.pl | 5 +- misc/migration_tools/build_oai_sets.pl | 12 +- misc/migration_tools/rebuild_zebra.pl | 5 +- opac/opac-MARCdetail.pl | 23 +-- opac/opac-downloadcart.pl | 27 ++- opac/opac-downloadshelf.pl | 25 ++- opac/opac-export.pl | 27 +-- opac/opac-sendbasket.pl | 15 +- opac/opac-sendshelf.pl | 15 +- opac/opac-tags.pl | 15 +- opac/opac-user.pl | 12 +- serials/subscription-add.pl | 7 +- t/Biblio.t | 17 +- t/db_dependent/Biblio.t | 17 +- t/db_dependent/Biblio/MarcOverlayRules.t | 8 +- t/db_dependent/Biblio/ModBiblioMarc.t | 5 +- t/db_dependent/Items.t | 125 +------------ t/db_dependent/Koha/Biblio/Metadata.t | 111 +++++++++++- .../Koha/Filter/EmbedItemsAvailability.t | 9 +- .../Koha/SearchEngine/Elasticsearch/Indexer.t | 3 +- t/db_dependent/OAI/AndSets.t | 10 +- t/db_dependent/OAI/Server.t | 23 +-- t/db_dependent/Record/marcrecord2csv.t | 4 +- t/db_dependent/Reserves.t | 6 +- tools/showdiffmarc.pl | 6 +- virtualshelves/downloadshelf.pl | 7 +- virtualshelves/sendshelf.pl | 7 +- 43 files changed, 431 insertions(+), 531 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index fbf61ceb469..9647071f7ce 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -29,7 +29,6 @@ BEGIN { @EXPORT_OK = qw( AddBiblio GetBiblioData - GetMarcBiblio GetISBDView GetMarcControlnumber GetMarcISBN @@ -1189,91 +1188,6 @@ sub GetMarcSubfieldStructureFromKohaField { return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; } -=head2 GetMarcBiblio - - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => $embeditems, - opac => $opac, - borcat => $patron_category }); - -Returns MARC::Record representing a biblio record, or C if the -biblionumber doesn't exist. - -Both embed_items and opac are optional. -If embed_items is passed and is 1, items are embedded. -If opac is passed and is 1, the record is filtered as needed. - -=over 4 - -=item C<$biblionumber> - -the biblionumber - -=item C<$embeditems> - -set to true to include item information. - -=item C<$opac> - -set to true to make the result suited for OPAC view. This causes things like -OpacHiddenItems to be applied. - -=item C<$borcat> - -If the OpacHiddenItemsExceptions system preference is set, this patron category -can be used to make visible OPAC items which would be normally hidden. -It only makes sense in combination both embed_items and opac values true. - -=back - -=cut - -sub GetMarcBiblio { - my ($params) = @_; - - if (not defined $params) { - carp 'GetMarcBiblio called without parameters'; - return; - } - - my $biblionumber = $params->{biblionumber}; - my $embeditems = $params->{embed_items} || 0; - my $opac = $params->{opac} || 0; - my $borcat = $params->{borcat} // q{}; - - if (not defined $biblionumber) { - carp 'GetMarcBiblio called with undefined biblionumber'; - return; - } - - my $marcxml = GetXmlBiblio( $biblionumber ); - $marcxml = StripNonXmlChars( $marcxml ); - MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') ); - my $record = MARC::Record->new(); - - if ($marcxml) { - $record = eval { - MARC::Record::new_from_xml( $marcxml, "UTF-8", - C4::Context->preference('marcflavour') ); - }; - if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; } - return unless $record; - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblionumber, - opac => $opac, - borcat => $borcat }) - if ($embeditems); - - return $record; - } - else { - return; - } -} - =head2 GetXmlBiblio my $marcxml = GetXmlBiblio($biblionumber); @@ -2485,82 +2399,6 @@ sub ModZebra { } } -=head2 EmbedItemsInMarcBiblio - - EmbedItemsInMarcBiblio({ - marc_record => $marc, - biblionumber => $biblionumber, - item_numbers => $itemnumbers, - opac => $opac }); - -Given a MARC::Record object containing a bib record, -modify it to include the items attached to it as 9XX -per the bib's MARC framework. -if $itemnumbers is defined, only specified itemnumbers are embedded. - -If $opac is true, then opac-relevant suppressions are included. - -If opac filtering will be done, borcat should be passed to properly -override if necessary. - -=cut - -sub EmbedItemsInMarcBiblio { - my ($params) = @_; - my ($marc, $biblionumber, $itemnumbers, $opac, $borcat); - $marc = $params->{marc_record}; - if ( !$marc ) { - carp 'EmbedItemsInMarcBiblio: No MARC record passed'; - return; - } - $biblionumber = $params->{biblionumber}; - $itemnumbers = $params->{item_numbers}; - $opac = $params->{opac}; - $borcat = $params->{borcat} // q{}; - - $itemnumbers = [] unless defined $itemnumbers; - - my $frameworkcode = GetFrameworkCode($biblionumber); - _strip_item_fields($marc, $frameworkcode); - - # ... and embed the current items - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); - $sth->execute($biblionumber); - my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); - - my @item_fields; # Array holding the actual MARC data for items to be included. - my @items; # Array holding items which are both in the list (sitenumbers) - # and on this biblionumber - - # Flag indicating if there is potential hiding. - my $opachiddenitems = $opac - && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); - - while ( my ($itemnumber) = $sth->fetchrow_array ) { - next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; - my $item; - if ( $opachiddenitems ) { - $item = Koha::Items->find($itemnumber); - $item = $item ? $item->unblessed : undef; - } - push @items, { itemnumber => $itemnumber, item => $item }; - } - items => \@items2pass, - borcat => $borcat }) - : (); - # Convert to a hash for quick searching - my %hiddenitems = map { $_ => 1 } @hiddenitems; - my @itemnumbers = Koha::Items->search( { itemnumber => $itemnumbers } ) - ->filter_by_visible_in_opac({ patron => })->get_column('itemnumber'); - foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { - next if $hiddenitems{$itemnumber}; - my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); - push @item_fields, $item_marc->field($itemtag); - } - $marc->append_fields(@item_fields); -} - =head1 INTERNAL FUNCTIONS =head2 _koha_marc_update_bib_ids @@ -3108,7 +2946,7 @@ sub UpdateTotalIssues { my $biblio = Koha::Biblios->find($biblionumber); unless ($biblio) { - carp "UpdateTotalIssues could not get datas of biblio"; + carp "UpdateTotalIssues could not get biblio"; return; } diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 61f8e345236..fea44ebfb32 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -24,8 +24,7 @@ use C4::Members; use C4::Items qw( get_hostitemnumbers_of ); use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal ); use C4::Accounts; -use C4::Biblio qw( GetMarcBiblio ); -use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved CanReserveBeCanceledFromOpac); +use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved ); use C4::Context; use C4::Auth; use CGI qw ( -utf8 ); @@ -218,10 +217,7 @@ sub GetRecords { my $biblioitem = $biblio->biblioitem->unblessed; - my $embed_items = 1; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => $embed_items }); + my $record = $biblio->metadata->record({ embed_items => 1 }); if ($record) { $biblioitem->{marcxml} = $record->as_xml_record(); } diff --git a/C4/OAI/Sets.pm b/C4/OAI/Sets.pm index ac9eb22dce7..fc876769f4f 100644 --- a/C4/OAI/Sets.pm +++ b/C4/OAI/Sets.pm @@ -31,6 +31,7 @@ OAI Set description can be found Lpreference('OAI-PMH:AutoUpdateSetsEmbedItemData')) { - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblionumber - }); + $record = Koha::Biblio::Metadata->record( + { + record => $record, + embed_items => 1, + biblionumber => $biblionumber, + } + ); } my $sets_biblios; diff --git a/C4/Record.pm b/C4/Record.pm index 537a09d76fe..3de35a27fca 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -26,7 +26,7 @@ use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding use Biblio::EndnoteStyle; use Unicode::Normalize qw( NFC ); # _entity_encode -use C4::Biblio qw( GetFrameworkCode GetMarcBiblio ); +use C4::Biblio qw( GetFrameworkCode ); use C4::Koha; #marc2csv use C4::XSLT; use YAML::XS; #marcrecords2csv @@ -454,18 +454,16 @@ C<$itemnumbers> a list of itemnumbers to export =cut sub marcrecord2csv { - my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_; + my ($biblionumber, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_; my $output; # Getting the record - my $record = GetMarcBiblio({ biblionumber => $biblio }); + my $biblio = Koha::Biblios->find($biblionumber); + return unless $biblio; + my $record = $biblio->metadata->record({ embed_items => 1, itemnumbers => $itemnumbers }); return unless $record; - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio, - item_numbers => $itemnumbers }); # Getting the framework - my $frameworkcode = GetFrameworkCode($biblio); + my $frameworkcode = $biblio->frameworkcode; # Getting information about the csv profile my $profile = Koha::CsvProfiles->find($id); diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm index f55b766a4b9..ad451797e51 100644 --- a/Koha/Biblio/Metadata.pm +++ b/Koha/Biblio/Metadata.pm @@ -17,9 +17,11 @@ package Koha::Biblio::Metadata; use Modern::Perl; -use MARC::Record; use MARC::File::XML; +use Scalar::Util qw( blessed ); +use C4::Biblio qw( GetMarcFromKohaField ); +use C4::Items qw( GetMarcItem ); use Koha::Database; use Koha::Exceptions::Metadata; @@ -48,6 +50,35 @@ corresponds to this table: | marcxml | MARC::Record | ------------------------------- + $record = $biblio->metadata->record({ + { + embed_items => 0|1 + itemnumbers => $itemnumbers, + opac => $opac + } + ); + + Koha::Biblio::Metadata::record( + { + record => $record, + embed_items => 1, + biblionumber => $biblionumber, + itemnumbers => $itemnumbers, + opac => $opac + } + ); + +Given a MARC::Record object containing a bib record, +modify it to include the items attached to it as 9XX +per the bib's MARC framework. +if $itemnumbers is defined, only specified itemnumbers are embedded. + +If $opac is true, then opac-relevant suppressions are included. + +If opac filtering will be done, patron should be passed to properly +override if necessary. + + =head4 Error handling =over @@ -62,12 +93,21 @@ corresponds to this table: sub record { - my ($self) = @_; + my ($self, $params) = @_; - my $record; + my $record = $params->{record}; + my $embed_items = $params->{embed_items}; + my $format = blessed($self) ? $self->format : $params->{format}; + $format ||= 'marcxml'; - if ( $self->format eq 'marcxml' ) { - $record = eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); }; + if ( !$record && !blessed($self) ) { + Koha::Exceptions::Metadata->throw( + 'Koha::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter' + ); + } + + if ( $format eq 'marcxml' ) { + $record ||= eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); }; my $marcxml_error = $@; chomp $marcxml_error; unless ($record) { @@ -82,7 +122,11 @@ sub record { } else { Koha::Exceptions::Metadata->throw( - 'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format ); + 'Koha::Biblio::Metadata->record called on unhandled format: ' . $format ); + } + + if ( $embed_items ) { + $self->_embed_items({ %$params, format => $format, record => $record }); } return $record; @@ -90,6 +134,55 @@ sub record { =head2 Internal methods +=head3 _embed_items + +=cut + +sub _embed_items { + my ( $self, $params ) = @_; + + my $record = $params->{record}; + my $format = $params->{format}; + my $biblionumber = $params->{biblionumber} || $self->biblionumber; + my $itemnumbers = $params->{itemnumbers} // []; + my $patron = $params->{patron}; + my $opac = $params->{opac}; + + if ( $format eq 'marcxml' ) { + + # First remove the existing items from the MARC record + my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" ); + foreach my $field ( $record->field($itemtag) ) { + $record->delete_field($field); + } + + my $biblio = Koha::Biblios->find($biblionumber); + + my $items = $biblio->items; + if ( @$itemnumbers ) { + $items = $items->search({ itemnumber => { -in => $itemnumbers } }); + } + if ( $opac ) { + $items = $items->filter_by_visible_in_opac({ patron => $patron }); + } + my @itemnumbers = $items->get_column('itemnumber'); + my @item_fields; + for my $itemnumber ( @itemnumbers ) { + my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); + push @item_fields, $item_marc->field($itemtag); + } + $record->append_fields(@item_fields); + + } + else { + Koha::Exceptions::Metadata->throw( + 'Koha::Biblio::Metadata->embed_item called on unhandled format: ' . $format ); + } + + return $record; +} + + =head3 _type =cut diff --git a/Koha/BiblioUtils.pm b/Koha/BiblioUtils.pm index 8301210de48..ebae899dc6e 100644 --- a/Koha/BiblioUtils.pm +++ b/Koha/BiblioUtils.pm @@ -27,12 +27,9 @@ Koha::BiblioUtils - contains fundamental biblio-related functions This contains functions for normal operations on biblio records. -Note: really, C4::Biblio does the main functions, but the Koha namespace is -the new thing that should be used. - =cut -use C4::Biblio; +use Koha::Biblios; use Koha::MetadataIterator; use Koha::Database; use Modern::Perl; @@ -140,8 +137,7 @@ sub get_all_biblios_iterator { my $database = Koha::Database->new(); my $schema = $database->schema(); - my $rs = - $schema->resultset('Biblio')->search( + my $rs = Koha::Biblios->search( $search_terms, $search_options ); my $next_func = sub { @@ -149,9 +145,7 @@ sub get_all_biblios_iterator { while (1) { my $row = $rs->next(); return if !$row; - my $marc = C4::Biblio::GetMarcBiblio({ - biblionumber => $row->biblionumber, - embed_items => 1 }); + my $marc = $row->metadata->record({ embed_items => 1 }); my $next = eval { $class->new($marc, $row->biblionumber); }; @@ -188,9 +182,9 @@ If set to true, item data is embedded in the record. Default is to not do this. sub get_marc_biblio { my ($class, $bibnum, %options) = @_; - return C4::Biblio::GetMarcBiblio({ - biblionumber => $bibnum, - embed_items => ($options{item_data} ? 1 : 0 ) }); + my $record = Koha::Biblios->find($bibnum) + ->metadata->record( { $options{item_data} ? ( embed_items => 1 ) : () } ); + return $record; } 1; diff --git a/Koha/BiblioUtils/Iterator.pm b/Koha/BiblioUtils/Iterator.pm index c75a3733e5c..e82f69fd735 100644 --- a/Koha/BiblioUtils/Iterator.pm +++ b/Koha/BiblioUtils/Iterator.pm @@ -44,6 +44,7 @@ Returns biblionumber and marc in list context. =cut use C4::Biblio; +use Koha::Biblio::Metadata; use Carp qw( confess ); use MARC::Record; @@ -107,10 +108,13 @@ sub next { confess "No biblionumber column returned in the request." if ( !defined($bibnum) ); - # TODO this should really be in Koha::BiblioUtils or something similar. - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $marc, - biblionumber => $bibnum }); + $marc = Koha::Biblio::Metadata->record( + { + record => $marc, + embed_items => 1, + biblionumber => $bibnum, + } + ); } if (wantarray) { diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm index d6e5c2ae596..f8e19b12c11 100644 --- a/Koha/OAI/Server/Repository.pm +++ b/Koha/OAI/Server/Repository.pm @@ -35,9 +35,9 @@ use XML::SAX::Writer; use YAML::XS; use CGI qw/:standard -oldstyle_urls/; use C4::Context; -use C4::Biblio qw( GetMarcBiblio ); use C4::XSLT qw( transformMARCXML4XSLT ); use Koha::XSLT::Base; +use Koha::Biblios; =head1 NAME @@ -176,13 +176,8 @@ sub get_biblio_marcxml { $expanded_avs = $conf->{format}->{$format}->{expanded_avs}; } - my $record = GetMarcBiblio( - { - biblionumber => $biblionumber, - embed_items => $with_items, - opac => 1 - } - ); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => $with_items, opac => 1 }); $record = transformMARCXML4XSLT( $biblionumber, $record ) if $expanded_avs; diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index ca0d19a442b..3fa9d477c14 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -28,8 +28,8 @@ use Koha::Exceptions::Elasticsearch; use Koha::SearchEngine::Zebra::Indexer; use Koha::BackgroundJob::UpdateElasticIndex; use C4::AuthoritiesMarc qw//; -use C4::Biblio; use C4::Context; +use Koha::Biblios; =head1 NAME @@ -338,7 +338,7 @@ sub index_records { sub _get_record { my ( $self, $record_id ) = @_; return $self->index eq $Koha::SearchEngine::BIBLIOS_INDEX - ? C4::Biblio::GetMarcBiblio({ biblionumber => $record_id, embed_items => 1 }) + ? Koha::Biblios->find($record_id)->metadata->record({ embed_items => 1 }) : C4::AuthoritiesMarc::GetAuthority($record_id); } diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl index f612099c6af..806ad4959fe 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -23,12 +23,12 @@ use CGI qw ( -utf8 ); use Encode qw( encode ); use C4::Auth qw( get_template_and_user ); -use C4::Biblio qw( GetMarcBiblio ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); use Koha::CsvProfiles; +use Koha::Biblios; use utf8; my $query = CGI->new; @@ -61,11 +61,10 @@ if ($bib_list && $format) { # Other formats } else { - foreach my $biblio (@bibs) { + foreach my $biblionumber (@bibs) { - my $record = GetMarcBiblio({ - biblionumber => $biblio, - embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => 1 }); next unless $record; if ($format eq 'iso2709') { @@ -77,7 +76,7 @@ if ($bib_list && $format) { $output .= marc2ris($record); } elsif ($format eq 'bibtex') { - $output .= marc2bibtex($record, $biblio); + $output .= marc2bibtex($record, $biblionumber); } } } diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl index 3c536050692..c5bf9822fb6 100755 --- a/basket/sendbasket.pl +++ b/basket/sendbasket.pl @@ -23,13 +23,13 @@ use Carp qw( carp ); use Try::Tiny qw( catch try ); use C4::Biblio qw( - GetMarcBiblio GetMarcSubjects ); use C4::Items qw( GetItemsInfo ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_and_exit output_html_with_http_headers ); use C4::Templates; +use Koha::Biblios; use Koha::Email; use Koha::Token; @@ -72,9 +72,7 @@ if ( $email_add ) { my $biblio = Koha::Biblios->find( $biblionumber ) or next; my $dat = $biblio->unblessed; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + my $record = $biblio->metadata->record({ embed_items => 1 }); my $marcauthorsarray = $biblio->get_marc_authors; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index d991d3e799a..69da0043616 100755 --- a/catalogue/ISBDdetail.pl +++ b/catalogue/ISBDdetail.pl @@ -40,7 +40,7 @@ use C4::Auth qw( get_template_and_user ); use C4::Context; use C4::Output qw( output_html_with_http_headers ); use CGI qw ( -utf8 ); -use C4::Biblio qw( GetBiblioData GetFrameworkCode GetISBDView GetMarcBiblio ); +use C4::Biblio qw( GetBiblioData GetISBDView ); use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscriptionsFromBiblionumber ); use C4::Search qw( z3950_search_args enabled_staff_search_views ); @@ -66,18 +66,17 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -if ( not defined $biblionumber ) { - # biblionumber invalid -> report and exit - $template->param( unknownbiblionumber => 1, - biblionumber => $biblionumber - ); - output_html_with_http_headers $query, $cookie, $template->output; - exit; +my $biblio = Koha::Biblios->find( $biblionumber ); +unless ( $biblionumber && $biblio ) { + # biblionumber invalid -> report and exit + $template->param( unknownbiblionumber => 1, + biblionumber => $biblionumber + ); + output_html_with_http_headers $query, $cookie, $template->output; + exit; } -my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); +my $record = $biblio->metadata->record({ embed_items => 1 }); if ( not defined $record ) { # biblionumber invalid -> report and exit @@ -88,8 +87,7 @@ if ( not defined $record ) { exit; } -my $biblio = Koha::Biblios->find( $biblionumber ); -my $framework = GetFrameworkCode( $biblionumber ); +my $framework = $biblio->frameworkcode; my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index 4ff6a03c548..2e30b04d84b 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -55,7 +55,6 @@ use C4::Biblio qw( GetAuthorisedValueDesc GetBiblioData GetFrameworkCode - GetMarcBiblio GetMarcFromKohaField GetMarcStructure ); @@ -90,9 +89,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); +my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio +my $record = $biblio_object->metadata->record({ embed_items => 1 }); if ( not defined $record ) { # biblionumber invalid -> report and exit @@ -103,7 +101,6 @@ if ( not defined $record ) { exit; } -my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio my $tagslib = &GetMarcStructure(1,$frameworkcode); my $biblio = GetBiblioData($biblionumber); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index e4d84aa0eac..2e5cc630c8e 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -32,7 +32,7 @@ use C4::Koha qw( ); use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); use C4::Output qw( output_html_with_http_headers ); -use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio ); +use C4::Biblio qw( GetBiblioData GetFrameworkCode ); use C4::Items qw( GetAnalyticsCount GetHostItemsInfo GetItemsInfo ); use C4::Circulation qw( GetTransfers ); use C4::Reserves; @@ -84,8 +84,8 @@ if ( C4::Context->config('enable_plugins') ) { my $biblionumber = $query->param('biblionumber'); $biblionumber = HTML::Entities::encode($biblionumber); -my $record = GetMarcBiblio({ biblionumber => $biblionumber }); my $biblio = Koha::Biblios->find( $biblionumber ); +my $record = $biblio->metadata->record; $template->param( 'biblio', $biblio ); if ( not defined $record ) { diff --git a/catalogue/export.pl b/catalogue/export.pl index 3785116581c..ff02cea67f0 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -4,7 +4,7 @@ use Modern::Perl; use C4::Record; use C4::Auth qw( get_template_and_user ); use C4::Output; -use C4::Biblio qw( GetMarcBiblio GetMarcControlnumber ); +use C4::Biblio qw( GetMarcControlnumber ); use CGI qw ( -utf8 ); use C4::Ris qw( marc2ris ); @@ -27,9 +27,8 @@ if ($op eq "export") { my $file_id = $biblionumber; my $file_pre = "bib-"; - my $marc = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $marc = $biblio->metadata->record({ embed_items => 1 }); if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour diff --git a/misc/batchRebuildItemsTables.pl b/misc/batchRebuildItemsTables.pl index 13f0c4117e4..220876a8b8f 100755 --- a/misc/batchRebuildItemsTables.pl +++ b/misc/batchRebuildItemsTables.pl @@ -10,8 +10,9 @@ use Time::HiRes qw( gettimeofday ); use Koha::Script; use C4::Context; -use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ); +use C4::Biblio qw( GetMarcFromKohaField ); use C4::Items qw( ModItemFromMarc ); +use Koha::Biblios; =head1 NAME @@ -72,9 +73,9 @@ $sth->execute(); while ( my ( $biblionumber, $biblioitemnumber, $frameworkcode ) = $sth->fetchrow ) { $count++; warn $count unless $count % 1000; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => 1 }); + unless ($record) { push @errors, "bad record biblionumber $biblionumber"; next; } unless ($test_parameter) { diff --git a/misc/cronjobs/build_browser_and_cloud.pl b/misc/cronjobs/build_browser_and_cloud.pl index 8cd733a785d..c8b12611fbe 100755 --- a/misc/cronjobs/build_browser_and_cloud.pl +++ b/misc/cronjobs/build_browser_and_cloud.pl @@ -7,13 +7,13 @@ use strict; use Koha::Script -cron; use C4::Koha; use C4::Context; -use C4::Biblio qw( GetMarcBiblio ); use Date::Calc; use Time::HiRes qw(gettimeofday); use ZOOM; use MARC::File::USMARC; use Getopt::Long; use C4::Log; +use Koha::Biblios; my ( $input_marc_file, $number) = ('',0); my ($version, $confirm,$field,$batch,$max_digits,$cloud_tag); @@ -85,8 +85,9 @@ while ((my ($biblionumber)= $sth->fetchrow)) { print "." unless $batch; #now, parse the record, extract the item fields, and store them in somewhere else. my $Koharecord; + my $biblio = Koha::Biblios->find($biblionumber); eval{ - $Koharecord = GetMarcBiblio({ biblionumber => $biblionumber }); + $Koharecord = $biblio->metadata->record }; if($@){ warn 'pb when getting biblio '.$i.' : '.$@; diff --git a/misc/migration_tools/build_oai_sets.pl b/misc/migration_tools/build_oai_sets.pl index 00f92c8fe7d..58a7498f811 100755 --- a/misc/migration_tools/build_oai_sets.pl +++ b/misc/migration_tools/build_oai_sets.pl @@ -45,7 +45,6 @@ use Getopt::Std qw( getopts ); use Koha::Script; use C4::Context; use C4::Charset qw( StripNonXmlChars ); -use C4::Biblio; use C4::OAI::Sets qw( AddOAISetsBiblios CalcOAISetsBiblio @@ -55,6 +54,7 @@ use C4::OAI::Sets qw( GetOAISetsMappings ModOAISetsBiblios ); +use Koha::Biblio::Metadata; my %opts; $Getopt::Std::STANDARD_HELP_VERSION = 1; @@ -141,9 +141,13 @@ foreach my $res (@$results) { next; } if($embed_items) { - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblionumber }); + $record = Koha::Biblio::Metadata->record( + { + marc_record => $record, + embed_items => 1, + biblionumber => $biblionumber, + } + ); } my @biblio_sets = CalcOAISetsBiblio($record, $mappings); diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 718c30533d7..fb16b8b360a 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -678,7 +678,10 @@ sub get_raw_marc_record { my $marc; if ($record_type eq 'biblio') { - eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1 }); }; + eval { + my $biblio = Koha::Biblios->find($record_number); + $marc = $biblio->metadata->record({ embed_items => 1 }); + }; if ($@ || !$marc) { # here we do warn since catching an exception # means that the bib was found but failed diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 0133784d396..4a77c37ee93 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -52,7 +52,6 @@ use CGI qw ( -utf8 ); use C4::Biblio qw( CountItemsIssued GetAuthorisedValueDesc - GetMarcBiblio GetMarcControlnumber GetMarcFromKohaField GetMarcISSN @@ -90,24 +89,20 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $patron = Koha::Patrons->find( $loggedinuser ); -my $borcat = q{}; -if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - # we need to fetch the borrower info here, so we can pass the category - $borcat = $patron ? $patron->categorycode : $borcat; -} - -my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); +my $patron = Koha::Patrons->find($loggedinuser); +my $biblio = Koha::Biblios->find($biblionumber); +my $record = $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } +); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } -my $biblio = Koha::Biblios->find( $biblionumber ); unless ( $patron and $patron->category->override_hidden_items ) { # only skip this check if there's a logged in user # and its category overrides OpacHiddenItems diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index f3a1769c0b0..1f4b20d1fb4 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -23,10 +23,11 @@ use CGI qw ( -utf8 ); use Encode qw( encode ); use C4::Auth qw( get_template_and_user ); -use C4::Biblio qw( GetFrameworkCode GetISBDView GetMarcBiblio ); +use C4::Biblio qw( GetFrameworkCode GetISBDView ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); +use Koha::Biblios; use Koha::CsvProfiles; use Koha::RecordProcessor; @@ -48,12 +49,7 @@ my $dbh = C4::Context->dbh; if ($bib_list && $format) { - my $borcat = q{}; - if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - # we need to fetch the borrower info here, so we can pass the category - my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } ); - $borcat = $borrower ? $borrower->categorycode : $borcat; - } + my $patron = Koha::Patrons->find($borrowernumber); my @bibs = split( /\//, $bib_list ); @@ -78,13 +74,16 @@ if ($bib_list && $format) { my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); - foreach my $biblio (@bibs) { - - my $record = GetMarcBiblio({ - biblionumber => $biblio, - embed_items => 1, - opac => 1, - borcat => $borcat }); + foreach my $biblionumber (@bibs) { + + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ); my $framework = &GetFrameworkCode( $biblio ); $record_processor->options({ interface => 'opac', diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index 5647f873b21..2414d1566a4 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -22,10 +22,11 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth qw( get_template_and_user ); -use C4::Biblio qw( GetFrameworkCode GetISBDView GetMarcBiblio ); +use C4::Biblio qw( GetFrameworkCode GetISBDView ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); +use Koha::Biblios; use Koha::CsvProfiles; use Koha::RecordProcessor; use Koha::Virtualshelves; @@ -48,12 +49,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( } ); -my $borcat = q{}; -if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - # we need to fetch the borrower info here, so we can pass the category - my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } ); - $borcat = $borrower ? $borrower->categorycode : $borcat; -} +my $patron = Koha::Patrons->find( $borrowernumber ); my $shelfnumber = $query->param('shelfnumber'); my $format = $query->param('format'); @@ -93,12 +89,15 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); - my $framework = &GetFrameworkCode( $biblionumber ); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record->( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ); + my $framework = $biblio->frameworkcode; $record_processor->options({ interface => 'opac', frameworkcode => $framework diff --git a/opac/opac-export.pl b/opac/opac-export.pl index d816ded995d..1b0fdad59ac 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -25,12 +25,12 @@ use C4::Output; use C4::Biblio qw( GetFrameworkCode GetISBDView - GetMarcBiblio GetMarcControlnumber ); use CGI qw ( -utf8 ); use C4::Auth; use C4::Ris qw( marc2ris ); +use Koha::Biblios; use Koha::RecordProcessor; my $query = CGI->new; @@ -43,23 +43,25 @@ my $error = q{}; # Determine logged in user's patron category. # Blank if not logged in. my $userenv = C4::Context->userenv; -my $borcat = q{}; +my $patron; if ($userenv) { my $borrowernumber = $userenv->{'number'}; if ($borrowernumber) { - my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } ); - $borcat = $borrower ? $borrower->categorycode : $borcat; + $patron = Koha::Patrons->find( $borrowernumber ); } } my $include_items = ($format =~ /bibtex/) ? 0 : 1; -my $marc = $biblionumber - ? GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => $include_items, - opac => 1, - borcat => $borcat }) - : undef; +my $biblio = Koha::Biblios->find($biblionumber); +my $marc = $biblio + ? $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ) + : undef; if(!$marc) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); @@ -77,8 +79,7 @@ if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ } } -# ASSERT: There is a biblionumber, because GetMarcBiblio returned something. -my $framework = GetFrameworkCode( $biblionumber ); +my $framework = $biblio->frameworkcode; my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index 75ddd3dc2c8..fcc49e0f7e6 100755 --- a/opac/opac-sendbasket.pl +++ b/opac/opac-sendbasket.pl @@ -25,13 +25,13 @@ use Carp qw( carp ); use Try::Tiny qw( catch try ); use C4::Biblio qw( - GetMarcBiblio GetMarcSubjects ); use C4::Items qw( GetItemsInfo ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Templates; +use Koha::Biblios; use Koha::Email; use Koha::Patrons; use Koha::Token; @@ -57,7 +57,6 @@ if ( $email_add ) { token => scalar $query->param('csrf_token'), }); my $patron = Koha::Patrons->find( $borrowernumber ); - my $borcat = $patron ? $patron->categorycode : q{}; my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress'); @@ -79,11 +78,13 @@ if ( $email_add ) { my $biblio = Koha::Biblios->find( $biblionumber ) or next; my $dat = $biblio->unblessed; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); + my $record = $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ); my $marcauthorsarray = $biblio->get_marc_authors; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index 4b33d8ef972..915428111af 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -27,12 +27,12 @@ use Try::Tiny qw( catch try ); use C4::Auth qw( get_template_and_user ); use C4::Biblio qw( GetFrameworkCode - GetMarcBiblio GetMarcISBN GetMarcSubjects ); use C4::Items qw( GetItemsInfo ); use C4::Output qw( output_html_with_http_headers ); +use Koha::Biblios; use Koha::Email; use Koha::Patrons; use Koha::Virtualshelves; @@ -73,7 +73,6 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { ); my $patron = Koha::Patrons->find( $borrowernumber ); - my $borcat = $patron ? $patron->categorycode : q{}; my $shelf = Koha::Virtualshelves->find( $shelfid ); my $contents = $shelf->get_contents; @@ -85,11 +84,13 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { my $biblionumber = $content->biblionumber; my $biblio = Koha::Biblios->find( $biblionumber ) or next; my $dat = $biblio->unblessed; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); + my $record = $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ); next unless $record; my $fw = GetFrameworkCode($biblionumber); diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index c8f5d15aab8..e75f86c5a3c 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -40,7 +40,6 @@ use C4::Auth qw( check_cookie_auth get_template_and_user ); use C4::Context; use C4::Output qw( output_with_http_headers is_ajax output_html_with_http_headers ); use C4::Scrubber; -use C4::Biblio qw( GetMarcBiblio ); use C4::Items qw( GetItemsInfo ); use C4::Tags qw( add_tag @@ -50,6 +49,7 @@ use C4::Tags qw( stratify_tags ); use C4::XSLT qw( XSLTParse4Display ); +use Koha::Biblios; use Koha::Logger; @@ -230,7 +230,6 @@ my $my_tags = []; if ($loggedinuser) { my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); - $borcat = $patron ? $patron->categorycode : $borcat; my $rules = C4::Context->yaml_preference('OpacHiddenItems'); my $should_hide = ( $rules ) ? 1 : 0; $my_tags = get_tag_rows({borrowernumber=>$loggedinuser}); @@ -252,11 +251,13 @@ if ($loggedinuser) { foreach my $tag (@$my_tags) { $tag->{visible} = 0; my $biblio = Koha::Biblios->find( $tag->{biblionumber} ); - my $record = &GetMarcBiblio({ - biblionumber => $tag->{biblionumber}, - embed_items => 1, - opac => 1, - borcat => $borcat }); + my $record = $biblio->metadata->record( + { + embed_items => 1, + opac => 1, + patron => $patron, + } + ); next unless $record; my @hidden_items; if ($should_hide) { diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 86960e0c841..147e7d9109b 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -32,7 +32,6 @@ use C4::External::BakerTaylor qw( image_url link_url ); use C4::Reserves qw( GetReserveStatus ); use C4::Members; use C4::Output qw( output_html_with_http_headers ); -use C4::Biblio qw( GetMarcBiblio ); use Koha::Account::Lines; use Koha::Biblios; use Koha::Libraries; @@ -98,8 +97,6 @@ if( $query->param('update_arc') && C4::Context->preference("AllowPatronToControl } my $borr = $patron->unblessed; -# unblessed is a hash vs. object/undef. Hence the use of curly braces here. -my $borcat = $borr ? $borr->{categorycode} : q{}; my ( $today_year, $today_month, $today_day) = Today(); my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'}; @@ -279,17 +276,14 @@ if ( $pending_checkouts->count ) { # Useless test $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; } - $issue->{biblio_object} = Koha::Biblios->find($issue->{biblionumber}); + my $biblio_object = Koha::Biblios->find($issue->{biblionumber}); + $issue->{biblio_object} = $biblio_object; push @issuedat, $issue; $count++; my $isbn = GetNormalizedISBN($issue->{'isbn'}); $issue->{normalized_isbn} = $isbn; - my $marcrecord = GetMarcBiblio({ - biblionumber => $issue->{'biblionumber'}, - embed_items => 1, - opac => 1, - borcat => $borcat }); + my $marcrecord = $biblio_object->metadata->record({ embed_items => 1, opac => 1, patron => $patron,}); $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') ); # My Summary HTML diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index c604e4042bb..c08142b8973 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -20,7 +20,6 @@ use Modern::Perl; use CGI qw ( -utf8 ); use Date::Calc qw( Add_Delta_Days Add_Delta_YM ); use C4::Koha qw( GetAuthorisedValues ); -use C4::Biblio qw( GetMarcBiblio ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_and_exit output_html_with_http_headers ); use C4::Context; @@ -365,7 +364,8 @@ sub redirect_add_subscription { } my @additional_fields; - my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => 1 }); my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' }); while ( my $field = $subscription_fields->next ) { my $value = $query->param('additional_field_' . $field->id); @@ -484,7 +484,8 @@ sub redirect_mod_subscription { ); my @additional_fields; - my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => 1 }); my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' }); while ( my $field = $subscription_fields->next ) { my $value = $query->param('additional_field_' . $field->id); diff --git a/t/Biblio.t b/t/Biblio.t index 40b22ed593f..c298349e18f 100755 --- a/t/Biblio.t +++ b/t/Biblio.t @@ -21,10 +21,10 @@ use Test::More; use Test::MockModule; use Test::Warn; -plan tests => 37; +plan tests => 34; -use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues )); +use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues )); my $db = Test::MockModule->new('Koha::Database'); $db->mock( _new_schema => sub { return Schema(); } ); @@ -130,19 +130,10 @@ warning_is { $ret = RemoveAllNsb() } ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec'); -warning_is { $ret = GetMarcBiblio() } - { carped => 'GetMarcBiblio called without parameters'}, - "GetMarcBiblio returns carped warning on no parameters"; - -warning_is { $ret = GetMarcBiblio({ biblionumber => undef }) } - { carped => 'GetMarcBiblio called with undefined biblionumber'}, - "GetMarcBiblio returns carped warning on undef biblionumber"; - -ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber'); warnings_like { $ret = UpdateTotalIssues() } - [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ }, - { carped => qr/UpdateTotalIssues could not get biblio record/ } ], + [ + { carped => qr/UpdateTotalIssues could not get biblio/ } ], "UpdateTotalIssues returns carped warnings if biblio record does not exist"; ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist'); diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index 7afa3e29f42..1e141960335 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -33,7 +33,7 @@ use Koha::MarcSubfieldStructures; use C4::Linker::Default qw( get_link ); BEGIN { - use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData GetMarcBiblio ModBiblio GetMarcISSN GetMarcControlnumber GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio )); + use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData ModBiblio GetMarcISSN GetMarcControlnumber GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio )); } my $schema = Koha::Database->new->schema; @@ -273,8 +273,10 @@ sub run_tests { is( $data->{ title }, undef, '(GetBiblioData) Title field is empty in fresh biblio.'); + my $biblio = Koha::Biblios->find($biblionumber); + my ( $isbn_field, $isbn_subfield ) = get_isbn_field(); - my $marc = GetMarcBiblio({ biblionumber => $biblionumber }); + my $marc = $biblio->metadata->record; is( $marc->subfield( $isbn_field, $isbn_subfield ), $isbn, ); # Add title @@ -285,7 +287,7 @@ sub run_tests { is( $data->{ title }, $title, 'ModBiblio correctly added the title field, and GetBiblioData.'); is( $data->{ isbn }, $isbn, '(ModBiblio) ISBN is still there after ModBiblio.'); - $marc = GetMarcBiblio({ biblionumber => $biblionumber }); + $marc = $biblio->metadata->record; my ( $title_field, $title_subfield ) = get_title_field(); is( $marc->subfield( $title_field, $title_subfield ), $title, ); @@ -422,9 +424,7 @@ sub run_tests { is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100, "GetMarcPrice returns the correct value"); - my $updatedrecord = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 0 }); + my $updatedrecord = $biblio->metadata->record; my $frameworkcode = GetFrameworkCode($biblionumber); my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber" ); die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag; @@ -706,7 +706,8 @@ subtest 'MarcFieldForCreatorAndModifier' => sub { my $record = MARC::Record->new(); my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); - $record = GetMarcBiblio({biblionumber => $biblionumber}); + my $biblio = Koha::Biblios->find($biblionumber); + $record = $biblio->metadata->record; is($record->subfield('998', 'a'), 123, '998$a = 123'); is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe'); is($record->subfield('998', 'c'), 123, '998$c = 123'); @@ -715,7 +716,7 @@ subtest 'MarcFieldForCreatorAndModifier' => sub { $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; }); C4::Biblio::ModBiblio($record, $biblionumber, ''); - $record = GetMarcBiblio({biblionumber => $biblionumber}); + $record = $biblio->metadata->record; is($record->subfield('998', 'a'), 123, '998$a = 123'); is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe'); is($record->subfield('998', 'c'), 321, '998$c = 321'); diff --git a/t/db_dependent/Biblio/MarcOverlayRules.t b/t/db_dependent/Biblio/MarcOverlayRules.t index 29aeeafa06c..dd3c7205997 100755 --- a/t/db_dependent/Biblio/MarcOverlayRules.t +++ b/t/db_dependent/Biblio/MarcOverlayRules.t @@ -22,8 +22,9 @@ use POSIX qw(floor); use MARC::Record; use C4::Context; -use C4::Biblio qw( AddBiblio ModBiblio DelBiblio GetMarcBiblio ); +use C4::Biblio qw( AddBiblio ModBiblio DelBiblio ); use Koha::Database; +use Koha::Biblios; use Test::More tests => 24; use Test::MockModule; @@ -755,7 +756,8 @@ subtest 'context option in ModBiblio is handled correctly' => sub { # Since marc merc rules are not run on save, only update # saved record should be identical to orig_record - my $saved_record = GetMarcBiblio({ biblionumber => $biblionumber }); + my $biblio = Koha::Biblios->find($biblionumber); + my $saved_record = $biblio->metadata->record; my @all_fields = $saved_record->fields(); # Koha also adds 999c field, therefore 4 not 3 @@ -783,7 +785,7 @@ subtest 'context option in ModBiblio is handled correctly' => sub { ModBiblio($saved_record, $biblionumber, '', { overlay_context => { 'source' => 'test' } }); - my $updated_record = GetMarcBiblio({ biblionumber => $biblionumber }); + my $updated_record = $biblio->metadata->record; $expected_record = build_record([ # "250" field has been appended diff --git a/t/db_dependent/Biblio/ModBiblioMarc.t b/t/db_dependent/Biblio/ModBiblioMarc.t index 8f7e28b49c2..ac56746d2d6 100755 --- a/t/db_dependent/Biblio/ModBiblioMarc.t +++ b/t/db_dependent/Biblio/ModBiblioMarc.t @@ -22,8 +22,9 @@ use t::lib::Mocks; use t::lib::TestBuilder; use MARC::Record; -use C4::Biblio qw( ModBiblio ModBiblioMarc GetMarcBiblio ); +use C4::Biblio qw( ModBiblio ModBiblioMarc ); use Koha::Database; +use Koha::Biblios; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -41,7 +42,7 @@ subtest "Check MARC field length calculation" => sub { is( $record->leader, ' 'x24, 'No leader lengths' ); C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber ); - my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); + my $savedrec = $biblio->metadata->record; like( substr($savedrec->leader,0,5), qr/^\d{5}$/, 'Record length found' ); like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' ); }; diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 20fe122d1cf..36593268305 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -20,7 +20,7 @@ use Data::Dumper; use MARC::Record; use C4::Items qw( ModItemTransfer GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); -use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio ); +use C4::Biblio qw( GetMarcFromKohaField AddBiblio ); use C4::Circulation qw( AddIssue ); use Koha::Items; use Koha::Database; @@ -34,7 +34,7 @@ use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 14; +use Test::More tests => 12; use Test::Warn; @@ -618,127 +618,6 @@ subtest 'Koha::Item(s) tests' => sub { $schema->storage->txn_rollback; }; -subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { - plan tests => 8; - - $schema->storage->txn_begin(); - - my $builder = t::lib::TestBuilder->new; - my $library1 = $builder->build({ - source => 'Branch', - }); - my $library2 = $builder->build({ - source => 'Branch', - }); - my $itemtype = $builder->build({ - source => 'Itemtype', - }); - - my $biblio = $builder->build_sample_biblio(); - my $item_infos = [ - { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, - { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, - { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, - { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, - { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, - { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, - { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, - { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, - ]; - my $number_of_items = scalar @$item_infos; - my $number_of_items_with_homebranch_is_CPL = - grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; - - my @itemnumbers; - for my $item_info (@$item_infos) { - my $itemnumber = $builder->build_sample_item( - { - biblionumber => $biblio->biblionumber, - homebranch => $item_info->{homebranch}, - holdingbranch => $item_info->{holdingbranch}, - itype => $itemtype->{itemtype} - } - )->itemnumber; - - push @itemnumbers, $itemnumber; - } - - # Emptied the OpacHiddenItems pref - t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); - - my ($itemfield) = - C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); - my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); - warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } - { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, - 'Should carp is no record passed.'; - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber }); - my @items = $record->field($itemfield); - is( scalar @items, $number_of_items, 'Should return all items' ); - - my $marc_with_items = C4::Biblio::GetMarcBiblio({ - biblionumber => $biblio->biblionumber, - embed_items => 1 }); - is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber, - item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); - @items = $record->field($itemfield); - is( scalar @items, 2, 'Should return all items present in the list' ); - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber, - opac => 1 }); - @items = $record->field($itemfield); - is( scalar @items, $number_of_items, 'Should return all items for opac' ); - - my $opachiddenitems = " - homebranch: ['$library1->{branchcode}']"; - t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber }); - @items = $record->field($itemfield); - is( scalar @items, - $number_of_items, - 'Even with OpacHiddenItems set, all items should have been embedded' ); - - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber, - opac => 1 }); - @items = $record->field($itemfield); - is( - scalar @items, - $number_of_items - $number_of_items_with_homebranch_is_CPL, -'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded' - ); - - $opachiddenitems = " - homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; - t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); - C4::Biblio::EmbedItemsInMarcBiblio({ - marc_record => $record, - biblionumber => $biblio->biblionumber, - opac => 1 }); - @items = $record->field($itemfield); - is( - scalar @items, - 0, -'For OPAC, If all items are hidden, no item should have been embedded' - ); - - $schema->storage->txn_rollback; -}; - - subtest 'get_hostitemnumbers_of' => sub { plan tests => 3; diff --git a/t/db_dependent/Koha/Biblio/Metadata.t b/t/db_dependent/Koha/Biblio/Metadata.t index 7bd22e269a0..6adc4e75d42 100755 --- a/t/db_dependent/Koha/Biblio/Metadata.t +++ b/t/db_dependent/Koha/Biblio/Metadata.t @@ -17,10 +17,11 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use t::lib::TestBuilder; +use t::lib::Mocks; use C4::Biblio qw( AddBiblio ); use Koha::Database; @@ -83,3 +84,111 @@ subtest 'record() tests' => sub { $schema->storage->txn_rollback; }; + +subtest '_embed_items' => sub { + plan tests => 8; + + $schema->storage->txn_begin(); + + my $builder = t::lib::TestBuilder->new; + my $library1 = $builder->build({ + source => 'Branch', + }); + my $library2 = $builder->build({ + source => 'Branch', + }); + my $itemtype = $builder->build({ + source => 'Itemtype', + }); + + my $biblio = $builder->build_sample_biblio(); + my $item_infos = [ + { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, + { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, + { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, + { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, + { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, + { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, + { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, + { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, + ]; + my $number_of_items = scalar @$item_infos; + my $number_of_items_with_homebranch_is_CPL = + grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; + + my @itemnumbers; + for my $item_info (@$item_infos) { + my $itemnumber = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + homebranch => $item_info->{homebranch}, + holdingbranch => $item_info->{holdingbranch}, + itype => $itemtype->{itemtype} + } + )->itemnumber; + + push @itemnumbers, $itemnumber; + } + + # Emptied the OpacHiddenItems pref + t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); + + throws_ok { Koha::Biblio::Metadata->record() } + 'Koha::Exceptions::Metadata', +'Koha::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter'; + + my ($itemfield) = + C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); + my $record = $biblio->metadata->record; + Koha::Biblio::Metadata->record( + { + record => $record, + embed_items => 1, + biblionumber => $biblio->biblionumber + } + ); + my @items = $record->field($itemfield); + is( scalar @items, $number_of_items, 'Should return all items' ); + + my $marc_with_items = $biblio->metadata->record({ embed_items => 1 }); + is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); + + $record = $biblio->metadata->record({ embed_items => 1, itemnumbers => [ $itemnumbers[1], $itemnumbers[3] ] }); + @items = $record->field($itemfield); + is( scalar @items, 2, 'Should return all items present in the list' ); + + $record = $biblio->metadata->record({ embed_items => 1, opac => 1 }); + @items = $record->field($itemfield); + is( scalar @items, $number_of_items, 'Should return all items for opac' ); + + my $opachiddenitems = " + homebranch: ['$library1->{branchcode}']"; + t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); + + $record = $biblio->metadata->record({ embed_items => 1 }); + @items = $record->field($itemfield); + is( scalar @items, + $number_of_items, + 'Even with OpacHiddenItems set, all items should have been embedded' ); + + $record = $biblio->metadata->record({ embed_items => 1, opac => 1 }); + @items = $record->field($itemfield); + is( + scalar @items, + $number_of_items - $number_of_items_with_homebranch_is_CPL, +'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded' + ); + + $opachiddenitems = " + homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; + t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); + $record = $biblio->metadata->record({ embed_items => 1, opac => 1 }); + @items = $record->field($itemfield); + is( + scalar @items, + 0, +'For OPAC, If all items are hidden, no item should have been embedded' + ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t b/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t index ca81af11886..ef1249eec64 100755 --- a/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t +++ b/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t @@ -25,7 +25,8 @@ use t::lib::TestBuilder; use MARC::Record; -use C4::Biblio qw( GetMarcFromKohaField AddBiblio GetMarcBiblio ); +use C4::Biblio qw( GetMarcFromKohaField AddBiblio ); +use Koha::Biblios; use Koha::Database; use Koha::RecordProcessor; @@ -84,7 +85,8 @@ subtest 'EmbedItemsAvailability tests' => sub { my $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } ); is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' ); - my $record = GetMarcBiblio({ biblionumber => $biblionumber }); + my $biblio_object = Koha::Biblios->find($biblionumber); + my $record = $biblio_object->metadata->record; ok( !defined $record->field('999')->subfield('x'), q{The record doesn't originally contain 999$x} ); # Apply filter $processor->process($record); @@ -123,7 +125,8 @@ subtest 'EmbedItemsAvailability tests' => sub { $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } ); is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' ); - $record = GetMarcBiblio({ biblionumber => $biblionumber }); + $biblio_object = Koha::Biblios->find($biblionumber); + $record = $biblio_object->metadata->record; ok( !defined $record->subfield('999', 'x'), q{The record doesn't originally contain 999$x} ); # Apply filter $processor->process($record); diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t index 2b84a24f39f..fa60948ec8c 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t @@ -28,6 +28,7 @@ use t::lib::TestBuilder; use MARC::Record; use Koha::Database; +use Koha::Biblios; my $schema = Koha::Database->schema(); @@ -113,7 +114,7 @@ subtest 'index_records() tests' => sub { "When passing record and ids to index_records they are correctly passed through to update_index"; $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }); - $marc_record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber, embed_items => 1 }); + $marc_record = $biblio->metadata->record({ embed_items => 1 }); warning_is { $indexer->index_records( [ $biblio->biblionumber ], 'specialUpdate', 'biblioserver' ); diff --git a/t/db_dependent/OAI/AndSets.t b/t/db_dependent/OAI/AndSets.t index 0d6bd9049fc..0489de6457b 100755 --- a/t/db_dependent/OAI/AndSets.t +++ b/t/db_dependent/OAI/AndSets.t @@ -25,8 +25,8 @@ use MARC::Record; use Data::Dumper; use Koha::Database; -use C4::Biblio qw( GetMarcBiblio ); use C4::OAI::Sets qw( AddOAISet ModOAISet ModOAISetMappings CalcOAISetsBiblio ); +use Koha::Biblios; use t::lib::TestBuilder; @@ -98,11 +98,11 @@ my $biblionumber1 = $biblio_1->biblionumber; my $biblionumber2 = $biblio_2->biblionumber; -my $record = GetMarcBiblio({ biblionumber => $biblionumber1 }); +my $record = $biblio_1->metadata->record; my @setsEq = CalcOAISetsBiblio($record); ok(!@setsEq, 'If only one condition is true, the record does not belong to the set'); -$record = GetMarcBiblio({ biblionumber => $biblionumber2 }); +$record = $biblio_2->metadata->record; @setsEq = CalcOAISetsBiblio($record); is_deeply(@setsEq, $set1_id, 'If all conditions are true, the record belongs to the set'); @@ -169,12 +169,12 @@ $biblio_2 = $builder->build_sample_biblio({ author => 'myAuthor', itemtype => 'm $biblionumber1 = $biblio_1->biblionumber; $biblionumber2 = $biblio_2->biblionumber; -$record = GetMarcBiblio({ biblionumber => $biblionumber1 }); +$record = $biblio_1->metadata->record; @setsEq = CalcOAISetsBiblio($record); is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with only the title belongs to the set'); -$record = GetMarcBiblio({ biblionumber => $biblionumber2 }); +$record = $biblio_2->metadata->record; @setsEq = CalcOAISetsBiblio($record); is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with author and itemtype belongs to the set'); diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index c9ae0ec9947..0b58f8aeafc 100755 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -33,10 +33,11 @@ use YAML::XS; use t::lib::Mocks; use t::lib::TestBuilder; -use C4::Biblio qw( AddBiblio GetMarcBiblio ModBiblio DelBiblio ); +use C4::Biblio qw( AddBiblio ModBiblio DelBiblio ); use C4::Context; use C4::OAI::Sets qw(AddOAISet); +use Koha::Biblios; use Koha::Biblio::Metadatas; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -104,7 +105,8 @@ foreach my $index ( 0 .. NUMBER_OF_MARC_RECORDS - 1 ) { $sth2->execute($timestamp,$biblionumber); $timestamp .= 'Z'; $timestamp =~ s/ /T/; - $record = GetMarcBiblio({ biblionumber => $biblionumber }); + my $biblio = Koha::Biblios->find($biblionumber); + $record = $biblio->metadata->record; my $record_transformed = $record->clone; $record_transformed->delete_fields( $record_transformed->field('952')); $record_transformed = XMLin($record_transformed->as_xml_record); @@ -391,7 +393,8 @@ subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me # Modify record to trigger auto update of timestamp (my $biblionumber = $marcxml[0]->{header}->{identifier}) =~ s/^.*:(.*)/$1/; - my $record = GetMarcBiblio({biblionumber => $biblionumber}); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record; $record->append_fields(MARC::Field->new(999, '', '', z => '_')); ModBiblio( $record, $biblionumber ); my $from_dt = dt_from_string( @@ -577,7 +580,7 @@ subtest 'Tests for timestamp handling' => sub { }, metadata => { record => XMLin( - GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record() + $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record() ) } } @@ -590,7 +593,7 @@ subtest 'Tests for timestamp handling' => sub { }, metadata => { record => XMLin( - GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 0, opac => 1 })->as_xml_record() + $biblio1->metadata->record({opac => 1})->as_xml_record() ) } } @@ -649,7 +652,7 @@ subtest 'Tests for timestamp handling' => sub { $expected->{record}{header}{datestamp} = $utc_timestamp; $expected->{record}{metadata}{record} = XMLin( - GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record() + $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record() ); test_query( @@ -715,7 +718,7 @@ subtest 'Tests for timestamp handling' => sub { $expected->{record}{header}{datestamp} = $utc_timestamp; $expected->{record}{metadata}{record} = XMLin( - GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record() + $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record() ); test_query( @@ -744,7 +747,7 @@ subtest 'Tests for timestamp handling' => sub { $sth_del_item->execute($timestamp, $item2->itemnumber); $expected->{record}{metadata}{record} = XMLin( - GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record() + $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record() ); test_query( @@ -827,7 +830,7 @@ subtest 'Tests for timestamp handling' => sub { }, metadata => { record => XMLin( - GetMarcBiblio({ biblionumber => $biblio2->biblionumber, embed_items => 1, opac => 1 })->as_xml_record() + $biblio2->metadata->record({ embed_items => 1, opac => 1})->as_xml_record() ) } } @@ -843,7 +846,7 @@ subtest 'Tests for timestamp handling' => sub { }, metadata => { record => XMLin( - GetMarcBiblio({ biblionumber => $biblio2->biblionumber, embed_items => 0, opac => 1 })->as_xml_record() + $biblio2->metadata->record->as_xml_record() ) } } diff --git a/t/db_dependent/Record/marcrecord2csv.t b/t/db_dependent/Record/marcrecord2csv.t index 53fa0bdb9f9..ab4d5e75a77 100755 --- a/t/db_dependent/Record/marcrecord2csv.t +++ b/t/db_dependent/Record/marcrecord2csv.t @@ -7,10 +7,11 @@ use MARC::Record; use MARC::Field; use Text::CSV::Encoded; -use C4::Biblio qw( AddBiblio GetMarcBiblio ); +use C4::Biblio qw( AddBiblio ); use C4::Context; use C4::Record qw( marcrecord2csv ); use Koha::Database; +use Koha::Biblios; use C4::Items qw( AddItemFromMarc ); @@ -26,7 +27,6 @@ my $module_biblio = Test::MockModule->new('C4::Biblio'); my $record = new_record(); my $frameworkcode = q||; my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, $frameworkcode ); -$module_biblio->mock( 'GetMarcBiblio', sub{ $record } ); my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a); my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content }); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 3636c1b082b..7042db18acb 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -29,10 +29,11 @@ use DateTime::Duration; use C4::Circulation qw( AddReturn AddIssue ); use C4::Items; -use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio ); +use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); use C4::Members; use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); use Koha::ActionLogs; +use Koha::Biblios; use Koha::Caches; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Holds; @@ -583,7 +584,8 @@ t::lib::Mocks::mock_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' ); #Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously. #Set the ageRestriction for the Biblio -my $record = GetMarcBiblio({ biblionumber => $bibnum }); +$biblio = Koha::Biblios->find($bibnum); +my $record = $biblio->metadata->record; my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" ); $record->append_fields( MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16') ); C4::Biblio::ModBiblio( $record, $bibnum, $frameworkcode ); diff --git a/tools/showdiffmarc.pl b/tools/showdiffmarc.pl index 6864d7219df..add909a39c2 100755 --- a/tools/showdiffmarc.pl +++ b/tools/showdiffmarc.pl @@ -28,7 +28,6 @@ use CGI qw(:standard -utf8); use C4::Context; use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); -use C4::Biblio qw( GetMarcBiblio ); use C4::Auth qw( get_template_and_user ); use C4::ImportBatch qw( GetRecordFromImportBiblio GetImportBiblios ); use C4::AuthoritiesMarc qw( GetAuthority ); @@ -61,11 +60,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); if ( $type eq 'biblio' ) { - $record = GetMarcBiblio({ - biblionumber => $recordid, - embed_items => 1, - }); my $biblio = Koha::Biblios->find( $recordid ); + $record = $biblio->metadata->record->({ embed_items => 1 }); $recordTitle = $biblio->title; } elsif ( $type eq 'auth' ) { diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl index e922e9b4e26..1138b530ce3 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -22,11 +22,11 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth qw( get_template_and_user ); -use C4::Biblio qw( GetMarcBiblio ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); +use Koha::Biblios; use Koha::CsvProfiles; use Koha::Virtualshelves; @@ -68,9 +68,8 @@ if ($shelfid && $format) { else { #Other formats while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); + my $record = $biblio->metadata->record({ embed_items => 1 }); if ($format eq 'iso2709') { $output .= $record->as_usmarc(); } diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index 504481b6cad..0bcb43cea1e 100755 --- a/virtualshelves/sendshelf.pl +++ b/virtualshelves/sendshelf.pl @@ -26,7 +26,6 @@ use Try::Tiny qw( catch try ); use C4::Auth qw( get_template_and_user ); use C4::Biblio qw( - GetMarcBiblio GetMarcISBN GetMarcSubjects ); @@ -35,6 +34,8 @@ use C4::Output qw( output_html_with_http_headers output_and_exit ); + +use Koha::Biblios; use Koha::Email; use Koha::Virtualshelves; @@ -78,9 +79,7 @@ if ($to_address) { my $biblionumber = $content->biblionumber; my $biblio = Koha::Biblios->find( $biblionumber ) or next; my $dat = $biblio->unblessed; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + my $record = $biblio->metadata->record({ embed_items => 1 }); my $marcauthorsarray = $biblio->get_marc_authors; my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); -- 2.25.1