@EXPORT_OK = qw(
AddBiblio
GetBiblioData
- GetMarcBiblio
GetISBDView
GetMarcControlnumber
GetMarcISBN
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<undef> 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);
}
}
-=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
my $biblio = Koha::Biblios->find($biblionumber);
unless ($biblio) {
- carp "UpdateTotalIssues could not get datas of biblio";
+ carp "UpdateTotalIssues could not get biblio";
return;
}
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 );
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();
}
use Modern::Perl;
use C4::Context;
+use Koha::Biblio::Metadata;
use vars qw(@ISA @EXPORT);
return unless($biblionumber and $record);
if (C4::Context->preference('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;
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
=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);
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;
| 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
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) {
}
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;
=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
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;
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 {
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);
};
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;
=cut
use C4::Biblio;
+use Koha::Biblio::Metadata;
use Carp qw( confess );
use MARC::Record;
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) {
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
$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;
use Koha::SearchEngine::Zebra::Indexer;
use Koha::BackgroundJob::UpdateElasticIndex;
use C4::AuthoritiesMarc qw//;
-use C4::Biblio;
use C4::Context;
+use Koha::Biblios;
=head1 NAME
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);
}
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;
# 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') {
$output .= marc2ris($record);
}
elsif ($format eq 'bibtex') {
- $output .= marc2bibtex($record, $biblio);
+ $output .= marc2bibtex($record, $biblionumber);
}
}
}
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;
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 );
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 );
}
);
-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
exit;
}
-my $biblio = Koha::Biblios->find( $biblionumber );
-my $framework = GetFrameworkCode( $biblionumber );
+my $framework = $biblio->frameworkcode;
my $record_processor = Koha::RecordProcessor->new({
filters => 'ViewPolicy',
options => {
GetAuthorisedValueDesc
GetBiblioData
GetFrameworkCode
- GetMarcBiblio
GetMarcFromKohaField
GetMarcStructure
);
}
);
-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
exit;
}
-my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
my $tagslib = &GetMarcStructure(1,$frameworkcode);
my $biblio = GetBiblioData($biblionumber);
);
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;
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 ) {
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 );
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
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
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) {
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);
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.' : '.$@;
use Koha::Script;
use C4::Context;
use C4::Charset qw( StripNonXmlChars );
-use C4::Biblio;
use C4::OAI::Sets qw(
AddOAISetsBiblios
CalcOAISetsBiblio
GetOAISetsMappings
ModOAISetsBiblios
);
+use Koha::Biblio::Metadata;
my %opts;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
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);
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
use C4::Biblio qw(
CountItemsIssued
GetAuthorisedValueDesc
- GetMarcBiblio
GetMarcControlnumber
GetMarcFromKohaField
GetMarcISSN
}
);
-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
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;
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 );
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',
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;
}
);
-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');
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
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;
# 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");
}
}
-# 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 => {
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;
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');
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 );
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;
);
my $patron = Koha::Patrons->find( $borrowernumber );
- my $borcat = $patron ? $patron->categorycode : q{};
my $shelf = Koha::Virtualshelves->find( $shelfid );
my $contents = $shelf->get_contents;
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);
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
stratify_tags
);
use C4::XSLT qw( XSLTParse4Display );
+use Koha::Biblios;
use Koha::Logger;
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});
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) {
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;
}
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'};
$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
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;
}
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);
);
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);
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(); } );
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');
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;
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
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, );
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;
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');
$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');
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;
# 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
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
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;
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' );
};
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;
use t::lib::Mocks;
use t::lib::TestBuilder;
-use Test::More tests => 14;
+use Test::More tests => 12;
use Test::Warn;
$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;
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;
$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;
+};
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;
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);
$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);
use MARC::Record;
use Koha::Database;
+use Koha::Biblios;
my $schema = Koha::Database->schema();
"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' );
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;
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');
$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');
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 );
$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);
# 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(
},
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()
)
}
}
},
metadata => {
record => XMLin(
- GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 0, opac => 1 })->as_xml_record()
+ $biblio1->metadata->record({opac => 1})->as_xml_record()
)
}
}
$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(
$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(
$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(
},
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()
)
}
}
},
metadata => {
record => XMLin(
- GetMarcBiblio({ biblionumber => $biblio2->biblionumber, embed_items => 0, opac => 1 })->as_xml_record()
+ $biblio2->metadata->record->as_xml_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 );
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 });
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;
#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 );
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( GetImportBiblios );
use C4::AuthoritiesMarc qw( GetAuthority );
);
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' ) {
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;
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();
}
use C4::Auth qw( get_template_and_user );
use C4::Biblio qw(
- GetMarcBiblio
GetMarcISBN
GetMarcSubjects
);
output_html_with_http_headers
output_and_exit
);
+
+use Koha::Biblios;
use Koha::Email;
use Koha::Virtualshelves;
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 );