View | Details | Raw Unified | Return to bug 29697
Collapse All | Expand All

(-)a/C4/Biblio.pm (-163 / +1 lines)
Lines 29-35 BEGIN { Link Here
29
    @EXPORT_OK = qw(
29
    @EXPORT_OK = qw(
30
        AddBiblio
30
        AddBiblio
31
        GetBiblioData
31
        GetBiblioData
32
        GetMarcBiblio
33
        GetISBDView
32
        GetISBDView
34
        GetMarcControlnumber
33
        GetMarcControlnumber
35
        GetMarcISBN
34
        GetMarcISBN
Lines 1186-1276 sub GetMarcSubfieldStructureFromKohaField { Link Here
1186
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1185
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1187
}
1186
}
1188
1187
1189
=head2 GetMarcBiblio
1190
1191
  my $record = GetMarcBiblio({
1192
      biblionumber => $biblionumber,
1193
      embed_items  => $embeditems,
1194
      opac         => $opac,
1195
      borcat       => $patron_category });
1196
1197
Returns MARC::Record representing a biblio record, or C<undef> if the
1198
biblionumber doesn't exist.
1199
1200
Both embed_items and opac are optional.
1201
If embed_items is passed and is 1, items are embedded.
1202
If opac is passed and is 1, the record is filtered as needed.
1203
1204
=over 4
1205
1206
=item C<$biblionumber>
1207
1208
the biblionumber
1209
1210
=item C<$embeditems>
1211
1212
set to true to include item information.
1213
1214
=item C<$opac>
1215
1216
set to true to make the result suited for OPAC view. This causes things like
1217
OpacHiddenItems to be applied.
1218
1219
=item C<$borcat>
1220
1221
If the OpacHiddenItemsExceptions system preference is set, this patron category
1222
can be used to make visible OPAC items which would be normally hidden.
1223
It only makes sense in combination both embed_items and opac values true.
1224
1225
=back
1226
1227
=cut
1228
1229
sub GetMarcBiblio {
1230
    my ($params) = @_;
1231
1232
    if (not defined $params) {
1233
        carp 'GetMarcBiblio called without parameters';
1234
        return;
1235
    }
1236
1237
    my $biblionumber = $params->{biblionumber};
1238
    my $embeditems   = $params->{embed_items} || 0;
1239
    my $opac         = $params->{opac} || 0;
1240
    my $borcat       = $params->{borcat} // q{};
1241
1242
    if (not defined $biblionumber) {
1243
        carp 'GetMarcBiblio called with undefined biblionumber';
1244
        return;
1245
    }
1246
1247
    my $marcxml = GetXmlBiblio( $biblionumber );
1248
    $marcxml = StripNonXmlChars( $marcxml );
1249
    MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') );
1250
    my $record = MARC::Record->new();
1251
1252
    if ($marcxml) {
1253
        $record = eval {
1254
            MARC::Record::new_from_xml( $marcxml, "UTF-8",
1255
                C4::Context->preference('marcflavour') );
1256
        };
1257
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1258
        return unless $record;
1259
1260
        C4::Biblio::EmbedItemsInMarcBiblio({
1261
            marc_record  => $record,
1262
            biblionumber => $biblionumber,
1263
            opac         => $opac,
1264
            borcat       => $borcat })
1265
          if ($embeditems);
1266
1267
        return $record;
1268
    }
1269
    else {
1270
        return;
1271
    }
1272
}
1273
1274
=head2 GetXmlBiblio
1188
=head2 GetXmlBiblio
1275
1189
1276
  my $marcxml = GetXmlBiblio($biblionumber);
1190
  my $marcxml = GetXmlBiblio($biblionumber);
Lines 2470-2551 sub ModZebra { Link Here
2470
    }
2384
    }
2471
}
2385
}
2472
2386
2473
=head2 EmbedItemsInMarcBiblio
2474
2475
    EmbedItemsInMarcBiblio({
2476
        marc_record  => $marc,
2477
        biblionumber => $biblionumber,
2478
        item_numbers => $itemnumbers,
2479
        opac         => $opac });
2480
2481
Given a MARC::Record object containing a bib record,
2482
modify it to include the items attached to it as 9XX
2483
per the bib's MARC framework.
2484
if $itemnumbers is defined, only specified itemnumbers are embedded.
2485
2486
If $opac is true, then opac-relevant suppressions are included.
2487
2488
If opac filtering will be done, borcat should be passed to properly
2489
override if necessary.
2490
2491
=cut
2492
2493
sub EmbedItemsInMarcBiblio {
2494
    my ($params) = @_;
2495
    my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
2496
    $marc = $params->{marc_record};
2497
    if ( !$marc ) {
2498
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2499
        return;
2500
    }
2501
    $biblionumber = $params->{biblionumber};
2502
    $itemnumbers = $params->{item_numbers};
2503
    $opac = $params->{opac};
2504
    $borcat = $params->{borcat} // q{};
2505
2506
    $itemnumbers = [] unless defined $itemnumbers;
2507
2508
    my $frameworkcode = GetFrameworkCode($biblionumber);
2509
    _strip_item_fields($marc, $frameworkcode);
2510
2511
    # ... and embed the current items
2512
    my $dbh = C4::Context->dbh;
2513
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2514
    $sth->execute($biblionumber);
2515
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
2516
2517
    my @item_fields; # Array holding the actual MARC data for items to be included.
2518
    my @items;       # Array holding items which are both in the list (sitenumbers)
2519
                     # and on this biblionumber
2520
2521
    # Flag indicating if there is potential hiding.
2522
    my $opachiddenitems = $opac
2523
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2524
2525
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2526
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2527
        my $item;
2528
        if ( $opachiddenitems ) {
2529
            $item = Koha::Items->find($itemnumber);
2530
            $item = $item ? $item->unblessed : undef;
2531
        }
2532
        push @items, { itemnumber => $itemnumber, item => $item };
2533
    }
2534
            items  => \@items2pass,
2535
            borcat => $borcat })
2536
      : ();
2537
    # Convert to a hash for quick searching
2538
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2539
    my @itemnumbers = Koha::Items->search( { itemnumber => $itemnumbers } )
2540
      ->filter_by_visible_in_opac({ patron => })->get_column('itemnumber');
2541
    foreach my $itemnumber ( map { $_->{itemnumber} } @items ) {
2542
        next if $hiddenitems{$itemnumber};
2543
        my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
2544
        push @item_fields, $item_marc->field($itemtag);
2545
    }
2546
    $marc->append_fields(@item_fields);
2547
}
2548
2549
=head1 INTERNAL FUNCTIONS
2387
=head1 INTERNAL FUNCTIONS
2550
2388
2551
=head2 _koha_marc_update_bib_ids
2389
=head2 _koha_marc_update_bib_ids
Lines 3093-3099 sub UpdateTotalIssues { Link Here
3093
2931
3094
    my $biblio = Koha::Biblios->find($biblionumber);
2932
    my $biblio = Koha::Biblios->find($biblionumber);
3095
    unless ($biblio) {
2933
    unless ($biblio) {
3096
        carp "UpdateTotalIssues could not get datas of biblio";
2934
        carp "UpdateTotalIssues could not get biblio";
3097
        return;
2935
        return;
3098
    }
2936
    }
3099
2937
(-)a/C4/ILSDI/Services.pm (-6 / +2 lines)
Lines 24-31 use C4::Members; Link Here
24
use C4::Items qw( get_hostitemnumbers_of );
24
use C4::Items qw( get_hostitemnumbers_of );
25
use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
25
use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
26
use C4::Accounts;
26
use C4::Accounts;
27
use C4::Biblio qw( GetMarcBiblio );
27
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
28
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved CanReserveBeCanceledFromOpac);
29
use C4::Context;
28
use C4::Context;
30
use C4::Auth;
29
use C4::Auth;
31
use CGI qw ( -utf8 );
30
use CGI qw ( -utf8 );
Lines 218-227 sub GetRecords { Link Here
218
217
219
        my $biblioitem = $biblio->biblioitem->unblessed;
218
        my $biblioitem = $biblio->biblioitem->unblessed;
220
219
221
        my $embed_items = 1;
220
        my $record = $biblio->metadata->record({ embed_items => 1 });
222
        my $record = GetMarcBiblio({
223
            biblionumber => $biblionumber,
224
            embed_items  => $embed_items });
225
        if ($record) {
221
        if ($record) {
226
            $biblioitem->{marcxml} = $record->as_xml_record();
222
            $biblioitem->{marcxml} = $record->as_xml_record();
227
        }
223
        }
(-)a/C4/OAI/Sets.pm (-4 / +8 lines)
Lines 31-36 OAI Set description can be found L<here|http://www.openarchives.org/OAI/openarch Link Here
31
31
32
use Modern::Perl;
32
use Modern::Perl;
33
use C4::Context;
33
use C4::Context;
34
use Koha::Biblio::Metadata;
34
35
35
use vars qw(@ISA @EXPORT);
36
use vars qw(@ISA @EXPORT);
36
37
Lines 610-619 sub UpdateOAISetsBiblio { Link Here
610
    return unless($biblionumber and $record);
611
    return unless($biblionumber and $record);
611
612
612
    if (C4::Context->preference('OAI-PMH:AutoUpdateSetsEmbedItemData')) {
613
    if (C4::Context->preference('OAI-PMH:AutoUpdateSetsEmbedItemData')) {
613
        C4::Biblio::EmbedItemsInMarcBiblio({
614
        $record = Koha::Biblio::Metadata->record(
614
            marc_record  => $record,
615
            {
615
            biblionumber => $biblionumber
616
                record       => $record,
616
        });
617
                embed_items  => 1,
618
                biblionumber => $biblionumber,
619
            }
620
        );
617
    }
621
    }
618
622
619
    my $sets_biblios;
623
    my $sets_biblios;
(-)a/C4/Record.pm (-8 / +6 lines)
Lines 26-32 use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding Link Here
26
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding
26
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding
27
use Biblio::EndnoteStyle;
27
use Biblio::EndnoteStyle;
28
use Unicode::Normalize qw( NFC ); # _entity_encode
28
use Unicode::Normalize qw( NFC ); # _entity_encode
29
use C4::Biblio qw( GetFrameworkCode GetMarcBiblio );
29
use C4::Biblio qw( GetFrameworkCode );
30
use C4::Koha; #marc2csv
30
use C4::Koha; #marc2csv
31
use C4::XSLT;
31
use C4::XSLT;
32
use YAML::XS; #marcrecords2csv
32
use YAML::XS; #marcrecords2csv
Lines 454-471 C<$itemnumbers> a list of itemnumbers to export Link Here
454
=cut
454
=cut
455
455
456
sub marcrecord2csv {
456
sub marcrecord2csv {
457
    my ($biblio, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
457
    my ($biblionumber, $id, $header, $csv, $fieldprocessing, $itemnumbers) = @_;
458
    my $output;
458
    my $output;
459
459
460
    # Getting the record
460
    # Getting the record
461
    my $record = GetMarcBiblio({ biblionumber => $biblio });
461
    my $biblio = Koha::Biblios->find($biblionumber);
462
    return unless $biblio;
463
    my $record = $biblio->metadata->record({ embed_items => 1, itemnumbers => $itemnumbers });
462
    return unless $record;
464
    return unless $record;
463
    C4::Biblio::EmbedItemsInMarcBiblio({
464
        marc_record  => $record,
465
        biblionumber => $biblio,
466
        item_numbers => $itemnumbers });
467
    # Getting the framework
465
    # Getting the framework
468
    my $frameworkcode = GetFrameworkCode($biblio);
466
    my $frameworkcode = $biblio->frameworkcode;
469
467
470
    # Getting information about the csv profile
468
    # Getting information about the csv profile
471
    my $profile = Koha::CsvProfiles->find($id);
469
    my $profile = Koha::CsvProfiles->find($id);
(-)a/Koha/Biblio/Metadata.pm (-6 / +99 lines)
Lines 17-25 package Koha::Biblio::Metadata; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use MARC::Record;
21
use MARC::File::XML;
20
use MARC::File::XML;
21
use Scalar::Util qw( blessed );
22
22
23
use C4::Biblio qw( GetMarcFromKohaField );
24
use C4::Items qw( GetMarcItem );
23
use Koha::Database;
25
use Koha::Database;
24
use Koha::Exceptions::Metadata;
26
use Koha::Exceptions::Metadata;
25
27
Lines 48-53 corresponds to this table: Link Here
48
    | marcxml    | MARC::Record   |
50
    | marcxml    | MARC::Record   |
49
    -------------------------------
51
    -------------------------------
50
52
53
    $record = $biblio->metadata->record({
54
        {
55
            embed_items => 0|1
56
            itemnumbers => $itemnumbers,
57
            opac        => $opac
58
        }
59
    );
60
61
    Koha::Biblio::Metadata::record(
62
        {
63
            record       => $record,
64
            embed_items  => 1,
65
            biblionumber => $biblionumber,
66
            itemnumbers  => $itemnumbers,
67
            opac         => $opac
68
        }
69
    );
70
71
Given a MARC::Record object containing a bib record,
72
modify it to include the items attached to it as 9XX
73
per the bib's MARC framework.
74
if $itemnumbers is defined, only specified itemnumbers are embedded.
75
76
If $opac is true, then opac-relevant suppressions are included.
77
78
If opac filtering will be done, patron should be passed to properly
79
override if necessary.
80
81
51
=head4 Error handling
82
=head4 Error handling
52
83
53
=over
84
=over
Lines 62-73 corresponds to this table: Link Here
62
93
63
sub record {
94
sub record {
64
95
65
    my ($self) = @_;
96
    my ($self, $params) = @_;
66
97
67
    my $record;
98
    my $record = $params->{record};
99
    my $embed_items = $params->{embed_items};
100
    my $format = blessed($self) ? $self->format : $params->{format};
101
    $format ||= 'marcxml';
68
102
69
    if ( $self->format eq 'marcxml' ) {
103
    if ( !$record && !blessed($self) ) {
70
        $record = eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); };
104
        Koha::Exceptions::Metadata->throw(
105
            'Koha::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter'
106
        );
107
    }
108
109
    if ( $format eq 'marcxml' ) {
110
        $record ||= eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); };
71
        my $marcxml_error = $@;
111
        my $marcxml_error = $@;
72
        chomp $marcxml_error;
112
        chomp $marcxml_error;
73
        unless ($record) {
113
        unless ($record) {
Lines 82-88 sub record { Link Here
82
    }
122
    }
83
    else {
123
    else {
84
        Koha::Exceptions::Metadata->throw(
124
        Koha::Exceptions::Metadata->throw(
85
            'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format );
125
            'Koha::Biblio::Metadata->record called on unhandled format: ' . $format );
126
    }
127
128
    if ( $embed_items ) {
129
        $self->_embed_items({ %$params, format => $format, record => $record });
86
    }
130
    }
87
131
88
    return $record;
132
    return $record;
Lines 90-95 sub record { Link Here
90
134
91
=head2 Internal methods
135
=head2 Internal methods
92
136
137
=head3 _embed_items
138
139
=cut
140
141
sub _embed_items {
142
    my ( $self, $params ) = @_;
143
144
    my $record       = $params->{record};
145
    my $format       = $params->{format};
146
    my $biblionumber = $params->{biblionumber} || $self->biblionumber;
147
    my $itemnumbers = $params->{itemnumbers} // [];
148
    my $patron      = $params->{patron};
149
    my $opac        = $params->{opac};
150
151
    if ( $format eq 'marcxml' ) {
152
153
        # First remove the existing items from the MARC record
154
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
155
        foreach my $field ( $record->field($itemtag) ) {
156
            $record->delete_field($field);
157
        }
158
159
        my $biblio = Koha::Biblios->find($biblionumber);
160
161
        my $items = $biblio->items;
162
        if ( @$itemnumbers ) {
163
            $items = $items->search({ itemnumber => { -in => $itemnumbers } });
164
        }
165
        if ( $opac ) {
166
            $items = $items->filter_by_visible_in_opac({ patron => $patron });
167
        }
168
        my @itemnumbers = $items->get_column('itemnumber');
169
        my @item_fields;
170
        for my $itemnumber ( @itemnumbers ) {
171
            my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
172
            push @item_fields, $item_marc->field($itemtag);
173
        }
174
        $record->append_fields(@item_fields);
175
176
    }
177
    else {
178
        Koha::Exceptions::Metadata->throw(
179
            'Koha::Biblio::Metadata->embed_item called on unhandled format: ' . $format );
180
    }
181
182
    return $record;
183
}
184
185
93
=head3 _type
186
=head3 _type
94
187
95
=cut
188
=cut
(-)a/Koha/BiblioUtils.pm (-12 / +6 lines)
Lines 27-38 Koha::BiblioUtils - contains fundamental biblio-related functions Link Here
27
27
28
This contains functions for normal operations on biblio records.
28
This contains functions for normal operations on biblio records.
29
29
30
Note: really, C4::Biblio does the main functions, but the Koha namespace is
31
the new thing that should be used.
32
33
=cut
30
=cut
34
31
35
use C4::Biblio;
32
use Koha::Biblios;
36
use Koha::MetadataIterator;
33
use Koha::MetadataIterator;
37
use Koha::Database;
34
use Koha::Database;
38
use Modern::Perl;
35
use Modern::Perl;
Lines 140-147 sub get_all_biblios_iterator { Link Here
140
137
141
    my $database = Koha::Database->new();
138
    my $database = Koha::Database->new();
142
    my $schema   = $database->schema();
139
    my $schema   = $database->schema();
143
    my $rs =
140
    my $rs = Koha::Biblios->search(
144
      $schema->resultset('Biblio')->search(
145
        $search_terms,
141
        $search_terms,
146
        $search_options );
142
        $search_options );
147
    my $next_func = sub {
143
    my $next_func = sub {
Lines 149-157 sub get_all_biblios_iterator { Link Here
149
        while (1) {
145
        while (1) {
150
            my $row = $rs->next();
146
            my $row = $rs->next();
151
            return if !$row;
147
            return if !$row;
152
            my $marc = C4::Biblio::GetMarcBiblio({
148
            my $marc = $row->metadata->record({ embed_items => 1 });
153
                biblionumber => $row->biblionumber,
154
                embed_items  => 1 });
155
            my $next = eval {
149
            my $next = eval {
156
                $class->new($marc, $row->biblionumber);
150
                $class->new($marc, $row->biblionumber);
157
            };
151
            };
Lines 188-196 If set to true, item data is embedded in the record. Default is to not do this. Link Here
188
sub get_marc_biblio {
182
sub get_marc_biblio {
189
    my ($class, $bibnum, %options) = @_;
183
    my ($class, $bibnum, %options) = @_;
190
184
191
    return C4::Biblio::GetMarcBiblio({
185
    my $record = Koha::Biblios->find($bibnum)
192
        biblionumber => $bibnum,
186
      ->metadata->record( { $options{item_data} ? ( embed_items => 1 ) : () } );
193
        embed_items  => ($options{item_data} ? 1 : 0 ) });
187
    return $record;
194
}
188
}
195
189
196
1;
190
1;
(-)a/Koha/BiblioUtils/Iterator.pm (-4 / +8 lines)
Lines 44-49 Returns biblionumber and marc in list context. Link Here
44
=cut
44
=cut
45
45
46
use C4::Biblio;
46
use C4::Biblio;
47
use Koha::Biblio::Metadata;
47
48
48
use Carp qw( confess );
49
use Carp qw( confess );
49
use MARC::Record;
50
use MARC::Record;
Lines 107-116 sub next { Link Here
107
        confess "No biblionumber column returned in the request."
108
        confess "No biblionumber column returned in the request."
108
          if ( !defined($bibnum) );
109
          if ( !defined($bibnum) );
109
110
110
        # TODO this should really be in Koha::BiblioUtils or something similar.
111
        $marc = Koha::Biblio::Metadata->record(
111
        C4::Biblio::EmbedItemsInMarcBiblio({
112
            {
112
            marc_record  => $marc,
113
                record       => $marc,
113
            biblionumber => $bibnum });
114
                embed_items  => 1,
115
                biblionumber => $bibnum,
116
            }
117
        );
114
    }
118
    }
115
119
116
    if (wantarray) {
120
    if (wantarray) {
(-)a/Koha/OAI/Server/Repository.pm (-8 / +3 lines)
Lines 35-43 use XML::SAX::Writer; Link Here
35
use YAML::XS;
35
use YAML::XS;
36
use CGI qw/:standard -oldstyle_urls/;
36
use CGI qw/:standard -oldstyle_urls/;
37
use C4::Context;
37
use C4::Context;
38
use C4::Biblio qw( GetMarcBiblio );
39
use C4::XSLT qw( transformMARCXML4XSLT );
38
use C4::XSLT qw( transformMARCXML4XSLT );
40
use Koha::XSLT::Base;
39
use Koha::XSLT::Base;
40
use Koha::Biblios;
41
41
42
=head1 NAME
42
=head1 NAME
43
43
Lines 176-188 sub get_biblio_marcxml { Link Here
176
        $expanded_avs = $conf->{format}->{$format}->{expanded_avs};
176
        $expanded_avs = $conf->{format}->{$format}->{expanded_avs};
177
    }
177
    }
178
178
179
    my $record = GetMarcBiblio(
179
    my $biblio = Koha::Biblios->find($biblionumber);
180
        {
180
    my $record = $biblio->metadata->record({ embed_items => $with_items, opac => 1 });
181
            biblionumber => $biblionumber,
182
            embed_items  => $with_items,
183
            opac         => 1
184
        }
185
    );
186
    $record = transformMARCXML4XSLT( $biblionumber, $record )
181
    $record = transformMARCXML4XSLT( $biblionumber, $record )
187
        if $expanded_avs;
182
        if $expanded_avs;
188
183
(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (-2 / +2 lines)
Lines 28-35 use Koha::Exceptions::Elasticsearch; Link Here
28
use Koha::SearchEngine::Zebra::Indexer;
28
use Koha::SearchEngine::Zebra::Indexer;
29
use Koha::BackgroundJob::UpdateElasticIndex;
29
use Koha::BackgroundJob::UpdateElasticIndex;
30
use C4::AuthoritiesMarc qw//;
30
use C4::AuthoritiesMarc qw//;
31
use C4::Biblio;
32
use C4::Context;
31
use C4::Context;
32
use Koha::Biblios;
33
33
34
=head1 NAME
34
=head1 NAME
35
35
Lines 337-343 sub index_records { Link Here
337
sub _get_record {
337
sub _get_record {
338
    my ( $self, $record_id ) = @_;
338
    my ( $self, $record_id ) = @_;
339
    return $self->index eq $Koha::SearchEngine::BIBLIOS_INDEX
339
    return $self->index eq $Koha::SearchEngine::BIBLIOS_INDEX
340
        ? C4::Biblio::GetMarcBiblio({ biblionumber => $record_id, embed_items  => 1 })
340
        ? Koha::Biblios->find($record_id)->metadata->record({ embed_items => 1 })
341
        : C4::AuthoritiesMarc::GetAuthority($record_id);
341
        : C4::AuthoritiesMarc::GetAuthority($record_id);
342
}
342
}
343
343
(-)a/basket/downloadcart.pl (-6 / +5 lines)
Lines 23-34 use CGI qw ( -utf8 ); Link Here
23
use Encode qw( encode );
23
use Encode qw( encode );
24
24
25
use C4::Auth qw( get_template_and_user );
25
use C4::Auth qw( get_template_and_user );
26
use C4::Biblio qw( GetMarcBiblio );
27
use C4::Output qw( output_html_with_http_headers );
26
use C4::Output qw( output_html_with_http_headers );
28
use C4::Record;
27
use C4::Record;
29
use C4::Ris qw( marc2ris );
28
use C4::Ris qw( marc2ris );
30
29
31
use Koha::CsvProfiles;
30
use Koha::CsvProfiles;
31
use Koha::Biblios;
32
32
33
use utf8;
33
use utf8;
34
my $query = CGI->new;
34
my $query = CGI->new;
Lines 61-71 if ($bib_list && $format) { Link Here
61
    # Other formats
61
    # Other formats
62
    } else {
62
    } else {
63
63
64
        foreach my $biblio (@bibs) {
64
        foreach my $biblionumber (@bibs) {
65
65
66
            my $record = GetMarcBiblio({
66
            my $biblio = Koha::Biblios->find($biblionumber);
67
                biblionumber => $biblio,
67
            my $record = $biblio->metadata->record({ embed_items => 1 });
68
                embed_items  => 1 });
69
            next unless $record;
68
            next unless $record;
70
69
71
            if ($format eq 'iso2709') {
70
            if ($format eq 'iso2709') {
Lines 77-83 if ($bib_list && $format) { Link Here
77
                $output .= marc2ris($record);
76
                $output .= marc2ris($record);
78
            }
77
            }
79
            elsif ($format eq 'bibtex') {
78
            elsif ($format eq 'bibtex') {
80
                $output .= marc2bibtex($record, $biblio);
79
                $output .= marc2bibtex($record, $biblionumber);
81
            }
80
            }
82
        }
81
        }
83
    }
82
    }
(-)a/basket/sendbasket.pl (-4 / +2 lines)
Lines 23-35 use Carp qw( carp ); Link Here
23
use Try::Tiny qw( catch try );
23
use Try::Tiny qw( catch try );
24
24
25
use C4::Biblio qw(
25
use C4::Biblio qw(
26
    GetMarcBiblio
27
    GetMarcSubjects
26
    GetMarcSubjects
28
);
27
);
29
use C4::Items qw( GetItemsInfo );
28
use C4::Items qw( GetItemsInfo );
30
use C4::Auth qw( get_template_and_user );
29
use C4::Auth qw( get_template_and_user );
31
use C4::Output qw( output_and_exit output_html_with_http_headers );
30
use C4::Output qw( output_and_exit output_html_with_http_headers );
32
use C4::Templates;
31
use C4::Templates;
32
use Koha::Biblios;
33
use Koha::Email;
33
use Koha::Email;
34
use Koha::Token;
34
use Koha::Token;
35
35
Lines 72-80 if ( $email_add ) { Link Here
72
72
73
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
73
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
74
        my $dat              = $biblio->unblessed;
74
        my $dat              = $biblio->unblessed;
75
        my $record           = GetMarcBiblio({
75
        my $record           = $biblio->metadata->record({ embed_items => 1 });
76
            biblionumber => $biblionumber,
77
            embed_items => 1 });
78
        my $marcauthorsarray = $biblio->get_marc_authors;
76
        my $marcauthorsarray = $biblio->get_marc_authors;
79
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
80
78
(-)a/catalogue/ISBDdetail.pl (-13 / +11 lines)
Lines 40-46 use C4::Auth qw( get_template_and_user ); Link Here
40
use C4::Context;
40
use C4::Context;
41
use C4::Output qw( output_html_with_http_headers );
41
use C4::Output qw( output_html_with_http_headers );
42
use CGI qw ( -utf8 );
42
use CGI qw ( -utf8 );
43
use C4::Biblio qw( GetBiblioData GetFrameworkCode GetISBDView GetMarcBiblio );
43
use C4::Biblio qw( GetBiblioData GetISBDView );
44
use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscriptionsFromBiblionumber );
44
use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscriptionsFromBiblionumber );
45
use C4::Search qw( z3950_search_args enabled_staff_search_views );
45
use C4::Search qw( z3950_search_args enabled_staff_search_views );
46
46
Lines 66-83 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
66
    }
66
    }
67
);
67
);
68
68
69
if ( not defined $biblionumber ) {
69
my $biblio = Koha::Biblios->find( $biblionumber );
70
       # biblionumber invalid -> report and exit
70
unless ( $biblionumber && $biblio ) {
71
       $template->param( unknownbiblionumber => 1,
71
   # biblionumber invalid -> report and exit
72
                                biblionumber => $biblionumber
72
   $template->param( unknownbiblionumber => 1,
73
       );
73
                            biblionumber => $biblionumber
74
       output_html_with_http_headers $query, $cookie, $template->output;
74
   );
75
       exit;
75
   output_html_with_http_headers $query, $cookie, $template->output;
76
   exit;
76
}
77
}
77
78
78
my $record = GetMarcBiblio({
79
my $record = $biblio->metadata->record({ embed_items => 1 });
79
    biblionumber => $biblionumber,
80
    embed_items  => 1 });
81
80
82
if ( not defined $record ) {
81
if ( not defined $record ) {
83
       # biblionumber invalid -> report and exit
82
       # biblionumber invalid -> report and exit
Lines 88-95 if ( not defined $record ) { Link Here
88
       exit;
87
       exit;
89
}
88
}
90
89
91
my $biblio = Koha::Biblios->find( $biblionumber );
90
my $framework = $biblio->frameworkcode;
92
my $framework = GetFrameworkCode( $biblionumber );
93
my $record_processor = Koha::RecordProcessor->new({
91
my $record_processor = Koha::RecordProcessor->new({
94
    filters => 'ViewPolicy',
92
    filters => 'ViewPolicy',
95
    options => {
93
    options => {
(-)a/catalogue/MARCdetail.pl (-5 / +2 lines)
Lines 55-61 use C4::Biblio qw( Link Here
55
    GetAuthorisedValueDesc
55
    GetAuthorisedValueDesc
56
    GetBiblioData
56
    GetBiblioData
57
    GetFrameworkCode
57
    GetFrameworkCode
58
    GetMarcBiblio
59
    GetMarcFromKohaField
58
    GetMarcFromKohaField
60
    GetMarcStructure
59
    GetMarcStructure
61
);
60
);
Lines 90-98 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
90
    }
89
    }
91
);
90
);
92
91
93
my $record = GetMarcBiblio({
92
my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
94
    biblionumber => $biblionumber,
93
my $record = $biblio_object->metadata->record({ embed_items => 1 });
95
    embed_items  => 1 });
96
94
97
if ( not defined $record ) {
95
if ( not defined $record ) {
98
    # biblionumber invalid -> report and exit
96
    # biblionumber invalid -> report and exit
Lines 103-109 if ( not defined $record ) { Link Here
103
    exit;
101
    exit;
104
}
102
}
105
103
106
my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
107
my $tagslib = &GetMarcStructure(1,$frameworkcode);
104
my $tagslib = &GetMarcStructure(1,$frameworkcode);
108
my $biblio = GetBiblioData($biblionumber);
105
my $biblio = GetBiblioData($biblionumber);
109
106
(-)a/catalogue/detail.pl (-2 / +2 lines)
Lines 32-38 use C4::Koha qw( Link Here
32
);
32
);
33
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
33
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
34
use C4::Output qw( output_html_with_http_headers );
34
use C4::Output qw( output_html_with_http_headers );
35
use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio );
35
use C4::Biblio qw( GetBiblioData GetFrameworkCode );
36
use C4::Items qw( GetAnalyticsCount GetHostItemsInfo GetItemsInfo );
36
use C4::Items qw( GetAnalyticsCount GetHostItemsInfo GetItemsInfo );
37
use C4::Circulation qw( GetTransfers );
37
use C4::Circulation qw( GetTransfers );
38
use C4::Reserves;
38
use C4::Reserves;
Lines 87-94 if ( C4::Context->config('enable_plugins') ) { Link Here
87
87
88
my $biblionumber = $query->param('biblionumber');
88
my $biblionumber = $query->param('biblionumber');
89
$biblionumber = HTML::Entities::encode($biblionumber);
89
$biblionumber = HTML::Entities::encode($biblionumber);
90
my $record       = GetMarcBiblio({ biblionumber => $biblionumber });
91
my $biblio = Koha::Biblios->find( $biblionumber );
90
my $biblio = Koha::Biblios->find( $biblionumber );
91
my $record = $biblio->metadata->record;
92
$template->param( 'biblio', $biblio );
92
$template->param( 'biblio', $biblio );
93
93
94
if ( not defined $record ) {
94
if ( not defined $record ) {
(-)a/catalogue/export.pl (-4 / +3 lines)
Lines 4-10 use Modern::Perl; Link Here
4
use C4::Record;
4
use C4::Record;
5
use C4::Auth qw( get_template_and_user );
5
use C4::Auth qw( get_template_and_user );
6
use C4::Output;
6
use C4::Output;
7
use C4::Biblio qw( GetMarcBiblio GetMarcControlnumber );
7
use C4::Biblio qw( GetMarcControlnumber );
8
use CGI qw ( -utf8 );
8
use CGI qw ( -utf8 );
9
use C4::Ris qw( marc2ris );
9
use C4::Ris qw( marc2ris );
10
10
Lines 27-35 if ($op eq "export") { Link Here
27
            my $file_id = $biblionumber;
27
            my $file_id = $biblionumber;
28
            my $file_pre = "bib-";
28
            my $file_pre = "bib-";
29
29
30
            my $marc = GetMarcBiblio({
30
            my $biblio = Koha::Biblios->find($biblionumber);
31
                biblionumber => $biblionumber,
31
            my $marc   = $biblio->metadata->record({ embed_items => 1 });
32
                embed_items  => 1 });
33
32
34
            if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){
33
            if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){
35
                my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour
34
                my $marcflavour = C4::Context->preference('marcflavour'); #FIXME This option is required but does not change control num behaviour
(-)a/misc/batchRebuildItemsTables.pl (-4 / +5 lines)
Lines 10-17 use Time::HiRes qw( gettimeofday ); Link Here
10
10
11
use Koha::Script;
11
use Koha::Script;
12
use C4::Context;
12
use C4::Context;
13
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField );
13
use C4::Biblio qw( GetMarcFromKohaField );
14
use C4::Items qw( ModItemFromMarc );
14
use C4::Items qw( ModItemFromMarc );
15
use Koha::Biblios;
15
16
16
=head1 NAME
17
=head1 NAME
17
18
Lines 72-80 $sth->execute(); Link Here
72
while ( my ( $biblionumber, $biblioitemnumber, $frameworkcode ) = $sth->fetchrow ) {
73
while ( my ( $biblionumber, $biblioitemnumber, $frameworkcode ) = $sth->fetchrow ) {
73
    $count++;
74
    $count++;
74
    warn $count unless $count % 1000;
75
    warn $count unless $count % 1000;
75
    my $record = GetMarcBiblio({
76
    my $biblio = Koha::Biblios->find($biblionumber);
76
        biblionumber => $biblionumber,
77
    my $record = $biblio->metadata->record({ embed_items => 1 });
77
        embed_items   => 1 });
78
78
    unless ($record) { push @errors, "bad record biblionumber $biblionumber"; next; }
79
    unless ($record) { push @errors, "bad record biblionumber $biblionumber"; next; }
79
80
80
    unless ($test_parameter) {
81
    unless ($test_parameter) {
(-)a/misc/cronjobs/build_browser_and_cloud.pl (-2 / +3 lines)
Lines 7-19 use strict; Link Here
7
use Koha::Script -cron;
7
use Koha::Script -cron;
8
use C4::Koha;
8
use C4::Koha;
9
use C4::Context;
9
use C4::Context;
10
use C4::Biblio qw( GetMarcBiblio );
11
use Date::Calc;
10
use Date::Calc;
12
use Time::HiRes qw(gettimeofday);
11
use Time::HiRes qw(gettimeofday);
13
use ZOOM;
12
use ZOOM;
14
use MARC::File::USMARC;
13
use MARC::File::USMARC;
15
use Getopt::Long;
14
use Getopt::Long;
16
use C4::Log;
15
use C4::Log;
16
use Koha::Biblios;
17
17
18
my ( $input_marc_file, $number) = ('',0);
18
my ( $input_marc_file, $number) = ('',0);
19
my ($version, $confirm,$field,$batch,$max_digits,$cloud_tag);
19
my ($version, $confirm,$field,$batch,$max_digits,$cloud_tag);
Lines 85-92 while ((my ($biblionumber)= $sth->fetchrow)) { Link Here
85
    print "." unless $batch;
85
    print "." unless $batch;
86
    #now, parse the record, extract the item fields, and store them in somewhere else.
86
    #now, parse the record, extract the item fields, and store them in somewhere else.
87
    my $Koharecord;
87
    my $Koharecord;
88
    my $biblio = Koha::Biblios->find($biblionumber);
88
    eval{
89
    eval{
89
        $Koharecord = GetMarcBiblio({ biblionumber => $biblionumber });
90
        $Koharecord = $biblio->metadata->record
90
    };
91
    };
91
    if($@){
92
    if($@){
92
	    warn 'pb when getting biblio '.$i.' : '.$@;
93
	    warn 'pb when getting biblio '.$i.' : '.$@;
(-)a/misc/migration_tools/build_oai_sets.pl (-4 / +8 lines)
Lines 45-51 use Getopt::Std qw( getopts ); Link Here
45
use Koha::Script;
45
use Koha::Script;
46
use C4::Context;
46
use C4::Context;
47
use C4::Charset qw( StripNonXmlChars );
47
use C4::Charset qw( StripNonXmlChars );
48
use C4::Biblio;
49
use C4::OAI::Sets qw(
48
use C4::OAI::Sets qw(
50
    AddOAISetsBiblios
49
    AddOAISetsBiblios
51
    CalcOAISetsBiblio
50
    CalcOAISetsBiblio
Lines 55-60 use C4::OAI::Sets qw( Link Here
55
    GetOAISetsMappings
54
    GetOAISetsMappings
56
    ModOAISetsBiblios
55
    ModOAISetsBiblios
57
);
56
);
57
use Koha::Biblio::Metadata;
58
58
59
my %opts;
59
my %opts;
60
$Getopt::Std::STANDARD_HELP_VERSION = 1;
60
$Getopt::Std::STANDARD_HELP_VERSION = 1;
Lines 141-149 foreach my $res (@$results) { Link Here
141
        next;
141
        next;
142
    }
142
    }
143
    if($embed_items) {
143
    if($embed_items) {
144
        C4::Biblio::EmbedItemsInMarcBiblio({
144
        $record = Koha::Biblio::Metadata->record(
145
            marc_record  => $record,
145
            {
146
            biblionumber => $biblionumber });
146
                marc_record  => $record,
147
                embed_items  => 1,
148
                biblionumber => $biblionumber,
149
            }
150
        );
147
    }
151
    }
148
152
149
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
153
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
(-)a/misc/migration_tools/rebuild_zebra.pl (-1 / +4 lines)
Lines 678-684 sub get_raw_marc_record { Link Here
678
678
679
    my $marc;
679
    my $marc;
680
    if ($record_type eq 'biblio') {
680
    if ($record_type eq 'biblio') {
681
        eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1 }); };
681
        eval {
682
            my $biblio = Koha::Biblios->find($record_number);
683
            $marc = $biblio->metadata->record({ embed_items => 1 });
684
        };
682
        if ($@ || !$marc) {
685
        if ($@ || !$marc) {
683
            # here we do warn since catching an exception
686
            # here we do warn since catching an exception
684
            # means that the bib was found but failed
687
            # means that the bib was found but failed
(-)a/opac/opac-MARCdetail.pl (-14 / +9 lines)
Lines 52-58 use CGI qw ( -utf8 ); Link Here
52
use C4::Biblio qw(
52
use C4::Biblio qw(
53
    CountItemsIssued
53
    CountItemsIssued
54
    GetAuthorisedValueDesc
54
    GetAuthorisedValueDesc
55
    GetMarcBiblio
56
    GetMarcControlnumber
55
    GetMarcControlnumber
57
    GetMarcFromKohaField
56
    GetMarcFromKohaField
58
    GetMarcISSN
57
    GetMarcISSN
Lines 90-113 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
90
    }
89
    }
91
);
90
);
92
91
93
my $patron = Koha::Patrons->find( $loggedinuser );
92
my $patron = Koha::Patrons->find($loggedinuser);
94
my $borcat = q{};
93
my $biblio = Koha::Biblios->find($biblionumber);
95
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
94
my $record = $biblio->metadata->record(
96
    # we need to fetch the borrower info here, so we can pass the category
95
    {
97
    $borcat = $patron ? $patron->categorycode : $borcat;
96
        embed_items => 1,
98
}
97
        opac        => 1,
99
98
        patron      => $patron,
100
my $record = GetMarcBiblio({
99
    }
101
    biblionumber => $biblionumber,
100
);
102
    embed_items  => 1,
103
    opac         => 1,
104
    borcat       => $borcat });
105
if ( ! $record ) {
101
if ( ! $record ) {
106
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
102
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
107
    exit;
103
    exit;
108
}
104
}
109
105
110
my $biblio = Koha::Biblios->find( $biblionumber );
111
unless ( $patron and $patron->category->override_hidden_items ) {
106
unless ( $patron and $patron->category->override_hidden_items ) {
112
    # only skip this check if there's a logged in user
107
    # only skip this check if there's a logged in user
113
    # and its category overrides OpacHiddenItems
108
    # and its category overrides OpacHiddenItems
(-)a/opac/opac-downloadcart.pl (-14 / +13 lines)
Lines 23-32 use CGI qw ( -utf8 ); Link Here
23
use Encode qw( encode );
23
use Encode qw( encode );
24
24
25
use C4::Auth qw( get_template_and_user );
25
use C4::Auth qw( get_template_and_user );
26
use C4::Biblio qw( GetFrameworkCode GetISBDView GetMarcBiblio );
26
use C4::Biblio qw( GetFrameworkCode GetISBDView );
27
use C4::Output qw( output_html_with_http_headers );
27
use C4::Output qw( output_html_with_http_headers );
28
use C4::Record;
28
use C4::Record;
29
use C4::Ris qw( marc2ris );
29
use C4::Ris qw( marc2ris );
30
use Koha::Biblios;
30
use Koha::CsvProfiles;
31
use Koha::CsvProfiles;
31
use Koha::RecordProcessor;
32
use Koha::RecordProcessor;
32
33
Lines 48-59 my $dbh = C4::Context->dbh; Link Here
48
49
49
if ($bib_list && $format) {
50
if ($bib_list && $format) {
50
51
51
    my $borcat = q{};
52
    my $patron = Koha::Patrons->find($borrowernumber);
52
    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
53
        # we need to fetch the borrower info here, so we can pass the category
54
        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
55
        $borcat = $borrower ? $borrower->categorycode : $borcat;
56
    }
57
53
58
    my @bibs = split( /\//, $bib_list );
54
    my @bibs = split( /\//, $bib_list );
59
55
Lines 78-90 if ($bib_list && $format) { Link Here
78
        my $record_processor = Koha::RecordProcessor->new({
74
        my $record_processor = Koha::RecordProcessor->new({
79
            filters => 'ViewPolicy'
75
            filters => 'ViewPolicy'
80
        });
76
        });
81
        foreach my $biblio (@bibs) {
77
        foreach my $biblionumber (@bibs) {
82
78
83
            my $record = GetMarcBiblio({
79
            my $biblio = Koha::Biblios->find($biblionumber);
84
                biblionumber => $biblio,
80
            my $record = $biblio->metadata->record(
85
                embed_items  => 1,
81
                {
86
                opac         => 1,
82
                    embed_items => 1,
87
                borcat       => $borcat });
83
                    opac        => 1,
84
                    patron      => $patron,
85
                }
86
            );
88
            my $framework = &GetFrameworkCode( $biblio );
87
            my $framework = &GetFrameworkCode( $biblio );
89
            $record_processor->options({
88
            $record_processor->options({
90
                interface => 'opac',
89
                interface => 'opac',
(-)a/opac/opac-downloadshelf.pl (-13 / +12 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Biblio qw( GetFrameworkCode GetISBDView GetMarcBiblio );
25
use C4::Biblio qw( GetFrameworkCode GetISBDView );
26
use C4::Output qw( output_html_with_http_headers );
26
use C4::Output qw( output_html_with_http_headers );
27
use C4::Record;
27
use C4::Record;
28
use C4::Ris qw( marc2ris );
28
use C4::Ris qw( marc2ris );
29
use Koha::Biblios;
29
use Koha::CsvProfiles;
30
use Koha::CsvProfiles;
30
use Koha::RecordProcessor;
31
use Koha::RecordProcessor;
31
use Koha::Virtualshelves;
32
use Koha::Virtualshelves;
Lines 48-59 my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( Link Here
48
    }
49
    }
49
);
50
);
50
51
51
my $borcat = q{};
52
my $patron = Koha::Patrons->find( $borrowernumber );
52
if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
53
    # we need to fetch the borrower info here, so we can pass the category
54
    my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
55
    $borcat = $borrower ? $borrower->categorycode : $borcat;
56
}
57
53
58
my $shelfnumber = $query->param('shelfnumber');
54
my $shelfnumber = $query->param('shelfnumber');
59
my $format  = $query->param('format');
55
my $format  = $query->param('format');
Lines 93-104 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
93
            while ( my $content = $contents->next ) {
89
            while ( my $content = $contents->next ) {
94
                my $biblionumber = $content->biblionumber;
90
                my $biblionumber = $content->biblionumber;
95
91
96
                my $record = GetMarcBiblio({
92
                my $biblio = Koha::Biblios->find($biblionumber);
97
                    biblionumber => $biblionumber,
93
                my $record = $biblio->metadata->record->(
98
                    embed_items  => 1,
94
                    {
99
                    opac         => 1,
95
                        embed_items => 1,
100
                    borcat       => $borcat });
96
                        opac        => 1,
101
                my $framework = &GetFrameworkCode( $biblionumber );
97
                        patron      => $patron,
98
                    }
99
                );
100
                my $framework = $biblio->frameworkcode;
102
                $record_processor->options({
101
                $record_processor->options({
103
                    interface => 'opac',
102
                    interface => 'opac',
104
                    frameworkcode => $framework
103
                    frameworkcode => $framework
(-)a/opac/opac-export.pl (-13 / +14 lines)
Lines 25-36 use C4::Output; Link Here
25
use C4::Biblio qw(
25
use C4::Biblio qw(
26
    GetFrameworkCode
26
    GetFrameworkCode
27
    GetISBDView
27
    GetISBDView
28
    GetMarcBiblio
29
    GetMarcControlnumber
28
    GetMarcControlnumber
30
);
29
);
31
use CGI qw ( -utf8 );
30
use CGI qw ( -utf8 );
32
use C4::Auth;
31
use C4::Auth;
33
use C4::Ris qw( marc2ris );
32
use C4::Ris qw( marc2ris );
33
use Koha::Biblios;
34
use Koha::RecordProcessor;
34
use Koha::RecordProcessor;
35
35
36
my $query = CGI->new;
36
my $query = CGI->new;
Lines 43-65 my $error = q{}; Link Here
43
# Determine logged in user's patron category.
43
# Determine logged in user's patron category.
44
# Blank if not logged in.
44
# Blank if not logged in.
45
my $userenv = C4::Context->userenv;
45
my $userenv = C4::Context->userenv;
46
my $borcat = q{};
46
my $patron;
47
if ($userenv) {
47
if ($userenv) {
48
    my $borrowernumber = $userenv->{'number'};
48
    my $borrowernumber = $userenv->{'number'};
49
    if ($borrowernumber) {
49
    if ($borrowernumber) {
50
        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
50
        $patron = Koha::Patrons->find( $borrowernumber );
51
        $borcat = $borrower ? $borrower->categorycode : $borcat;
52
    }
51
    }
53
}
52
}
54
53
55
my $include_items = ($format =~ /bibtex/) ? 0 : 1;
54
my $include_items = ($format =~ /bibtex/) ? 0 : 1;
56
my $marc = $biblionumber
55
my $biblio = Koha::Biblios->find($biblionumber);
57
    ? GetMarcBiblio({
56
my $marc = $biblio
58
        biblionumber => $biblionumber,
57
  ? $biblio->metadata->record(
59
        embed_items  => $include_items,
58
    {
60
        opac         => 1,
59
        embed_items => 1,
61
        borcat       => $borcat })
60
        opac        => 1,
62
    : undef;
61
        patron      => $patron,
62
    }
63
  )
64
  : undef;
63
65
64
if(!$marc) {
66
if(!$marc) {
65
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
67
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
Lines 77-84 if( C4::Context->preference('DefaultSaveRecordFileID') eq 'controlnumber' ){ Link Here
77
    }
79
    }
78
}
80
}
79
81
80
# ASSERT: There is a biblionumber, because GetMarcBiblio returned something.
82
my $framework = $biblio->frameworkcode;
81
my $framework = GetFrameworkCode( $biblionumber );
82
my $record_processor = Koha::RecordProcessor->new({
83
my $record_processor = Koha::RecordProcessor->new({
83
    filters => 'ViewPolicy',
84
    filters => 'ViewPolicy',
84
    options => {
85
    options => {
(-)a/opac/opac-sendbasket.pl (-7 / +8 lines)
Lines 25-37 use Carp qw( carp ); Link Here
25
use Try::Tiny qw( catch try );
25
use Try::Tiny qw( catch try );
26
26
27
use C4::Biblio qw(
27
use C4::Biblio qw(
28
    GetMarcBiblio
29
    GetMarcSubjects
28
    GetMarcSubjects
30
);
29
);
31
use C4::Items qw( GetItemsInfo );
30
use C4::Items qw( GetItemsInfo );
32
use C4::Auth qw( get_template_and_user );
31
use C4::Auth qw( get_template_and_user );
33
use C4::Output qw( output_html_with_http_headers );
32
use C4::Output qw( output_html_with_http_headers );
34
use C4::Templates;
33
use C4::Templates;
34
use Koha::Biblios;
35
use Koha::Email;
35
use Koha::Email;
36
use Koha::Patrons;
36
use Koha::Patrons;
37
use Koha::Token;
37
use Koha::Token;
Lines 57-63 if ( $email_add ) { Link Here
57
        token  => scalar $query->param('csrf_token'),
57
        token  => scalar $query->param('csrf_token'),
58
    });
58
    });
59
    my $patron = Koha::Patrons->find( $borrowernumber );
59
    my $patron = Koha::Patrons->find( $borrowernumber );
60
    my $borcat = $patron ? $patron->categorycode : q{};
61
    my $user_email = $patron->first_valid_email_address
60
    my $user_email = $patron->first_valid_email_address
62
    || C4::Context->preference('KohaAdminEmailAddress');
61
    || C4::Context->preference('KohaAdminEmailAddress');
63
62
Lines 79-89 if ( $email_add ) { Link Here
79
78
80
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
79
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
81
        my $dat              = $biblio->unblessed;
80
        my $dat              = $biblio->unblessed;
82
        my $record           = GetMarcBiblio({
81
        my $record = $biblio->metadata->record(
83
            biblionumber => $biblionumber,
82
            {
84
            embed_items  => 1,
83
                embed_items => 1,
85
            opac         => 1,
84
                opac        => 1,
86
            borcat       => $borcat });
85
                patron      => $patron,
86
            }
87
        );
87
        my $marcauthorsarray = $biblio->get_marc_authors;
88
        my $marcauthorsarray = $biblio->get_marc_authors;
88
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89
90
(-)a/opac/opac-sendshelf.pl (-7 / +8 lines)
Lines 27-38 use Try::Tiny qw( catch try ); Link Here
27
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
28
use C4::Biblio qw(
28
use C4::Biblio qw(
29
    GetFrameworkCode
29
    GetFrameworkCode
30
    GetMarcBiblio
31
    GetMarcISBN
30
    GetMarcISBN
32
    GetMarcSubjects
31
    GetMarcSubjects
33
);
32
);
34
use C4::Items qw( GetItemsInfo );
33
use C4::Items qw( GetItemsInfo );
35
use C4::Output qw( output_html_with_http_headers );
34
use C4::Output qw( output_html_with_http_headers );
35
use Koha::Biblios;
36
use Koha::Email;
36
use Koha::Email;
37
use Koha::Patrons;
37
use Koha::Patrons;
38
use Koha::Virtualshelves;
38
use Koha::Virtualshelves;
Lines 73-79 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
73
    );
73
    );
74
74
75
    my $patron = Koha::Patrons->find( $borrowernumber );
75
    my $patron = Koha::Patrons->find( $borrowernumber );
76
    my $borcat = $patron ? $patron->categorycode : q{};
77
76
78
    my $shelf = Koha::Virtualshelves->find( $shelfid );
77
    my $shelf = Koha::Virtualshelves->find( $shelfid );
79
    my $contents = $shelf->get_contents;
78
    my $contents = $shelf->get_contents;
Lines 85-95 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
85
        my $biblionumber = $content->biblionumber;
84
        my $biblionumber = $content->biblionumber;
86
        my $biblio       = Koha::Biblios->find( $biblionumber ) or next;
85
        my $biblio       = Koha::Biblios->find( $biblionumber ) or next;
87
        my $dat          = $biblio->unblessed;
86
        my $dat          = $biblio->unblessed;
88
        my $record           = GetMarcBiblio({
87
        my $record = $biblio->metadata->record(
89
            biblionumber => $biblionumber,
88
            {
90
            embed_items  => 1,
89
                embed_items => 1,
91
            opac         => 1,
90
                opac        => 1,
92
            borcat       => $borcat });
91
                patron      => $patron,
92
            }
93
        );
93
        next unless $record;
94
        next unless $record;
94
        my $fw               = GetFrameworkCode($biblionumber);
95
        my $fw               = GetFrameworkCode($biblionumber);
95
96
(-)a/opac/opac-tags.pl (-7 / +8 lines)
Lines 40-46 use C4::Auth qw( check_cookie_auth get_template_and_user ); Link Here
40
use C4::Context;
40
use C4::Context;
41
use C4::Output qw( output_with_http_headers is_ajax output_html_with_http_headers );
41
use C4::Output qw( output_with_http_headers is_ajax output_html_with_http_headers );
42
use C4::Scrubber;
42
use C4::Scrubber;
43
use C4::Biblio qw( GetMarcBiblio );
44
use C4::Items qw( GetItemsInfo );
43
use C4::Items qw( GetItemsInfo );
45
use C4::Tags qw(
44
use C4::Tags qw(
46
    add_tag
45
    add_tag
Lines 50-55 use C4::Tags qw( Link Here
50
    stratify_tags
49
    stratify_tags
51
);
50
);
52
use C4::XSLT qw( XSLTParse4Display );
51
use C4::XSLT qw( XSLTParse4Display );
52
use Koha::Biblios;
53
53
54
54
55
use Koha::Logger;
55
use Koha::Logger;
Lines 230-236 my $my_tags = []; Link Here
230
230
231
if ($loggedinuser) {
231
if ($loggedinuser) {
232
    my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
232
    my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
233
    $borcat = $patron ? $patron->categorycode : $borcat;
234
    my $rules = C4::Context->yaml_preference('OpacHiddenItems');
233
    my $rules = C4::Context->yaml_preference('OpacHiddenItems');
235
    my $should_hide = ( $rules ) ? 1 : 0;
234
    my $should_hide = ( $rules ) ? 1 : 0;
236
    $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
235
    $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
Lines 252-262 if ($loggedinuser) { Link Here
252
    foreach my $tag (@$my_tags) {
251
    foreach my $tag (@$my_tags) {
253
        $tag->{visible} = 0;
252
        $tag->{visible} = 0;
254
        my $biblio = Koha::Biblios->find( $tag->{biblionumber} );
253
        my $biblio = Koha::Biblios->find( $tag->{biblionumber} );
255
        my $record = &GetMarcBiblio({
254
        my $record = $biblio->metadata->record(
256
            biblionumber => $tag->{biblionumber},
255
            {
257
            embed_items  => 1,
256
                embed_items => 1,
258
            opac         => 1,
257
                opac        => 1,
259
            borcat       => $borcat });
258
                patron      => $patron,
259
            }
260
        );
260
        next unless $record;
261
        next unless $record;
261
        my @hidden_items;
262
        my @hidden_items;
262
        if ($should_hide) {
263
        if ($should_hide) {
(-)a/opac/opac-user.pl (-9 / +3 lines)
Lines 32-38 use C4::External::BakerTaylor qw( image_url link_url ); Link Here
32
use C4::Reserves qw( GetReserveStatus );
32
use C4::Reserves qw( GetReserveStatus );
33
use C4::Members;
33
use C4::Members;
34
use C4::Output qw( output_html_with_http_headers );
34
use C4::Output qw( output_html_with_http_headers );
35
use C4::Biblio qw( GetMarcBiblio );
36
use Koha::Account::Lines;
35
use Koha::Account::Lines;
37
use Koha::Biblios;
36
use Koha::Biblios;
38
use Koha::Libraries;
37
use Koha::Libraries;
Lines 98-105 if( $query->param('update_arc') && C4::Context->preference("AllowPatronToControl Link Here
98
}
97
}
99
98
100
my $borr = $patron->unblessed;
99
my $borr = $patron->unblessed;
101
# unblessed is a hash vs. object/undef. Hence the use of curly braces here.
102
my $borcat = $borr ? $borr->{categorycode} : q{};
103
100
104
my (  $today_year,   $today_month,   $today_day) = Today();
101
my (  $today_year,   $today_month,   $today_day) = Today();
105
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
102
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
Lines 279-295 if ( $pending_checkouts->count ) { # Useless test Link Here
279
            $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
276
            $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
280
        }
277
        }
281
278
282
        $issue->{biblio_object} = Koha::Biblios->find($issue->{biblionumber});
279
        my $biblio_object = Koha::Biblios->find($issue->{biblionumber});
280
        $issue->{biblio_object} = $biblio_object;
283
        push @issuedat, $issue;
281
        push @issuedat, $issue;
284
        $count++;
282
        $count++;
285
283
286
        my $isbn = GetNormalizedISBN($issue->{'isbn'});
284
        my $isbn = GetNormalizedISBN($issue->{'isbn'});
287
        $issue->{normalized_isbn} = $isbn;
285
        $issue->{normalized_isbn} = $isbn;
288
        my $marcrecord = GetMarcBiblio({
286
        my $marcrecord = $biblio_object->metadata->record({ embed_items => 1, opac => 1, patron => $patron,});
289
            biblionumber => $issue->{'biblionumber'},
290
            embed_items  => 1,
291
            opac         => 1,
292
            borcat       => $borcat });
293
        $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
287
        $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
294
288
295
                # My Summary HTML
289
                # My Summary HTML
(-)a/serials/subscription-add.pl (-3 / +4 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use Date::Calc qw( Add_Delta_Days Add_Delta_YM );
21
use Date::Calc qw( Add_Delta_Days Add_Delta_YM );
22
use C4::Koha qw( GetAuthorisedValues );
22
use C4::Koha qw( GetAuthorisedValues );
23
use C4::Biblio qw( GetMarcBiblio );
24
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
25
use C4::Output qw( output_and_exit output_html_with_http_headers );
24
use C4::Output qw( output_and_exit output_html_with_http_headers );
26
use C4::Context;
25
use C4::Context;
Lines 365-371 sub redirect_add_subscription { Link Here
365
    }
364
    }
366
365
367
    my @additional_fields;
366
    my @additional_fields;
368
    my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 });
367
    my $biblio = Koha::Biblios->find($biblionumber);
368
    my $record = $biblio->metadata->record({ embed_items => 1 });
369
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
369
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
370
    while ( my $field = $subscription_fields->next ) {
370
    while ( my $field = $subscription_fields->next ) {
371
        my $value = $query->param('additional_field_' . $field->id);
371
        my $value = $query->param('additional_field_' . $field->id);
Lines 484-490 sub redirect_mod_subscription { Link Here
484
    );
484
    );
485
485
486
    my @additional_fields;
486
    my @additional_fields;
487
    my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 });
487
    my $biblio = Koha::Biblios->find($biblionumber);
488
    my $record = $biblio->metadata->record({ embed_items => 1 });
488
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
489
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
489
    while ( my $field = $subscription_fields->next ) {
490
    while ( my $field = $subscription_fields->next ) {
490
        my $value = $query->param('additional_field_' . $field->id);
491
        my $value = $query->param('additional_field_' . $field->id);
(-)a/t/Biblio.t (-13 / +4 lines)
Lines 21-30 use Test::More; Link Here
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
plan tests => 37;
24
plan tests => 34;
25
25
26
26
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues ));
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues ));
28
28
29
my $db = Test::MockModule->new('Koha::Database');
29
my $db = Test::MockModule->new('Koha::Database');
30
$db->mock( _new_schema => sub { return Schema(); } );
30
$db->mock( _new_schema => sub { return Schema(); } );
Lines 130-148 warning_is { $ret = RemoveAllNsb() } Link Here
130
130
131
ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
131
ok( !defined $ret, 'RemoveAllNsb returns undef if not passed rec');
132
132
133
warning_is { $ret = GetMarcBiblio() }
134
           { carped => 'GetMarcBiblio called without parameters'},
135
           "GetMarcBiblio returns carped warning on no parameters";
136
137
warning_is { $ret = GetMarcBiblio({ biblionumber => undef }) }
138
           { carped => 'GetMarcBiblio called with undefined biblionumber'},
139
           "GetMarcBiblio returns carped warning on undef biblionumber";
140
141
ok( !defined $ret, 'GetMarcBiblio returns undef if not passed a biblionumber');
142
133
143
warnings_like { $ret = UpdateTotalIssues() }
134
warnings_like { $ret = UpdateTotalIssues() }
144
              [ { carped => qr/GetMarcBiblio called with undefined biblionumber/ },
135
              [
145
                { carped => qr/UpdateTotalIssues could not get biblio record/ } ],
136
                { carped => qr/UpdateTotalIssues could not get biblio/ } ],
146
    "UpdateTotalIssues returns carped warnings if biblio record does not exist";
137
    "UpdateTotalIssues returns carped warnings if biblio record does not exist";
147
138
148
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
139
ok( !defined $ret, 'UpdateTotalIssues returns carped warning if biblio record does not exist');
(-)a/t/db_dependent/Biblio.t (-8 / +9 lines)
Lines 33-39 use Koha::MarcSubfieldStructures; Link Here
33
use C4::Linker::Default qw( get_link );
33
use C4::Linker::Default qw( get_link );
34
34
35
BEGIN {
35
BEGIN {
36
    use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData GetMarcBiblio ModBiblio GetMarcISSN GetMarcControlnumber GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio ));
36
    use_ok('C4::Biblio', qw( AddBiblio GetMarcFromKohaField BiblioAutoLink GetMarcSubfieldStructure GetMarcSubfieldStructureFromKohaField LinkBibHeadingsToAuthorities GetBiblioData ModBiblio GetMarcISSN GetMarcControlnumber GetMarcISBN GetMarcPrice GetFrameworkCode GetMarcUrls IsMarcStructureInternal GetMarcStructure GetXmlBiblio DelBiblio ));
37
}
37
}
38
38
39
my $schema = Koha::Database->new->schema;
39
my $schema = Koha::Database->new->schema;
Lines 273-280 sub run_tests { Link Here
273
    is( $data->{ title }, undef,
273
    is( $data->{ title }, undef,
274
        '(GetBiblioData) Title field is empty in fresh biblio.');
274
        '(GetBiblioData) Title field is empty in fresh biblio.');
275
275
276
    my $biblio = Koha::Biblios->find($biblionumber);
277
276
    my ( $isbn_field, $isbn_subfield ) = get_isbn_field();
278
    my ( $isbn_field, $isbn_subfield ) = get_isbn_field();
277
    my $marc = GetMarcBiblio({ biblionumber => $biblionumber });
279
    my $marc = $biblio->metadata->record;
278
    is( $marc->subfield( $isbn_field, $isbn_subfield ), $isbn, );
280
    is( $marc->subfield( $isbn_field, $isbn_subfield ), $isbn, );
279
281
280
    # Add title
282
    # Add title
Lines 285-291 sub run_tests { Link Here
285
    is( $data->{ title }, $title,
287
    is( $data->{ title }, $title,
286
        'ModBiblio correctly added the title field, and GetBiblioData.');
288
        'ModBiblio correctly added the title field, and GetBiblioData.');
287
    is( $data->{ isbn }, $isbn, '(ModBiblio) ISBN is still there after ModBiblio.');
289
    is( $data->{ isbn }, $isbn, '(ModBiblio) ISBN is still there after ModBiblio.');
288
    $marc = GetMarcBiblio({ biblionumber => $biblionumber });
290
    $marc = $biblio->metadata->record;
289
    my ( $title_field, $title_subfield ) = get_title_field();
291
    my ( $title_field, $title_subfield ) = get_title_field();
290
    is( $marc->subfield( $title_field, $title_subfield ), $title, );
292
    is( $marc->subfield( $title_field, $title_subfield ), $title, );
291
293
Lines 422-430 sub run_tests { Link Here
422
424
423
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
425
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
424
        "GetMarcPrice returns the correct value");
426
        "GetMarcPrice returns the correct value");
425
    my $updatedrecord = GetMarcBiblio({
427
    my $updatedrecord = $biblio->metadata->record;
426
        biblionumber => $biblionumber,
427
        embed_items  => 0 });
428
    my $frameworkcode = GetFrameworkCode($biblionumber);
428
    my $frameworkcode = GetFrameworkCode($biblionumber);
429
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
429
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
430
    die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag;
430
    die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag;
Lines 706-712 subtest 'MarcFieldForCreatorAndModifier' => sub { Link Here
706
    my $record = MARC::Record->new();
706
    my $record = MARC::Record->new();
707
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
707
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
708
708
709
    $record = GetMarcBiblio({biblionumber => $biblionumber});
709
    my $biblio = Koha::Biblios->find($biblionumber);
710
    $record = $biblio->metadata->record;
710
    is($record->subfield('998', 'a'), 123, '998$a = 123');
711
    is($record->subfield('998', 'a'), 123, '998$a = 123');
711
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
712
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
712
    is($record->subfield('998', 'c'), 123, '998$c = 123');
713
    is($record->subfield('998', 'c'), 123, '998$c = 123');
Lines 715-721 subtest 'MarcFieldForCreatorAndModifier' => sub { Link Here
715
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
716
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
716
    C4::Biblio::ModBiblio($record, $biblionumber, '');
717
    C4::Biblio::ModBiblio($record, $biblionumber, '');
717
718
718
    $record = GetMarcBiblio({biblionumber => $biblionumber});
719
    $record = $biblio->metadata->record;
719
    is($record->subfield('998', 'a'), 123, '998$a = 123');
720
    is($record->subfield('998', 'a'), 123, '998$a = 123');
720
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
721
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
721
    is($record->subfield('998', 'c'), 321, '998$c = 321');
722
    is($record->subfield('998', 'c'), 321, '998$c = 321');
(-)a/t/db_dependent/Biblio/MarcOverlayRules.t (-3 / +5 lines)
Lines 22-29 use POSIX qw(floor); Link Here
22
use MARC::Record;
22
use MARC::Record;
23
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Biblio qw( AddBiblio ModBiblio DelBiblio GetMarcBiblio );
25
use C4::Biblio qw( AddBiblio ModBiblio DelBiblio );
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Biblios;
27
28
28
use Test::More tests => 24;
29
use Test::More tests => 24;
29
use Test::MockModule;
30
use Test::MockModule;
Lines 755-761 subtest 'context option in ModBiblio is handled correctly' => sub { Link Here
755
756
756
    # Since marc merc rules are not run on save, only update
757
    # Since marc merc rules are not run on save, only update
757
    # saved record should be identical to orig_record
758
    # saved record should be identical to orig_record
758
    my $saved_record = GetMarcBiblio({ biblionumber => $biblionumber });
759
    my $biblio = Koha::Biblios->find($biblionumber);
760
    my $saved_record = $biblio->metadata->record;
759
761
760
    my @all_fields = $saved_record->fields();
762
    my @all_fields = $saved_record->fields();
761
    # Koha also adds 999c field, therefore 4 not 3
763
    # Koha also adds 999c field, therefore 4 not 3
Lines 783-789 subtest 'context option in ModBiblio is handled correctly' => sub { Link Here
783
785
784
    ModBiblio($saved_record, $biblionumber, '', { overlay_context => { 'source' => 'test' } });
786
    ModBiblio($saved_record, $biblionumber, '', { overlay_context => { 'source' => 'test' } });
785
787
786
    my $updated_record = GetMarcBiblio({ biblionumber => $biblionumber });
788
    my $updated_record = $biblio->metadata->record;
787
789
788
    $expected_record = build_record([
790
    $expected_record = build_record([
789
            # "250" field has been appended
791
            # "250" field has been appended
(-)a/t/db_dependent/Biblio/ModBiblioMarc.t (-2 / +3 lines)
Lines 22-29 use t::lib::Mocks; Link Here
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use MARC::Record;
23
use MARC::Record;
24
24
25
use C4::Biblio qw( ModBiblio ModBiblioMarc GetMarcBiblio );
25
use C4::Biblio qw( ModBiblio ModBiblioMarc );
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Biblios;
27
28
28
my $schema  = Koha::Database->new->schema;
29
my $schema  = Koha::Database->new->schema;
29
$schema->storage->txn_begin;
30
$schema->storage->txn_begin;
Lines 41-47 subtest "Check MARC field length calculation" => sub { Link Here
41
42
42
    is( $record->leader, ' 'x24, 'No leader lengths' );
43
    is( $record->leader, ' 'x24, 'No leader lengths' );
43
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
44
    C4::Biblio::ModBiblioMarc( $record, $biblio->biblionumber );
44
    my $savedrec = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
45
    my $savedrec = $biblio->metadata->record;
45
    like( substr($savedrec->leader,0,5), qr/^\d{5}$/, 'Record length found' );
46
    like( substr($savedrec->leader,0,5), qr/^\d{5}$/, 'Record length found' );
46
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
47
    like( substr($savedrec->leader,12,5), qr/^\d{5}$/, 'Base address found' );
47
};
48
};
(-)a/t/db_dependent/Items.t (-123 / +2 lines)
Lines 20-26 use Data::Dumper; Link Here
20
20
21
use MARC::Record;
21
use MARC::Record;
22
use C4::Items qw( ModItemTransfer GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc );
22
use C4::Items qw( ModItemTransfer GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc );
23
use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio );
23
use C4::Biblio qw( GetMarcFromKohaField AddBiblio );
24
use C4::Circulation qw( AddIssue );
24
use C4::Circulation qw( AddIssue );
25
use Koha::Items;
25
use Koha::Items;
26
use Koha::Database;
26
use Koha::Database;
Lines 34-40 use Koha::AuthorisedValues; Link Here
34
use t::lib::Mocks;
34
use t::lib::Mocks;
35
use t::lib::TestBuilder;
35
use t::lib::TestBuilder;
36
36
37
use Test::More tests => 14;
37
use Test::More tests => 12;
38
38
39
use Test::Warn;
39
use Test::Warn;
40
40
Lines 618-744 subtest 'Koha::Item(s) tests' => sub { Link Here
618
    $schema->storage->txn_rollback;
618
    $schema->storage->txn_rollback;
619
};
619
};
620
620
621
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub {
622
    plan tests => 8;
623
624
    $schema->storage->txn_begin();
625
626
    my $builder = t::lib::TestBuilder->new;
627
    my $library1 = $builder->build({
628
        source => 'Branch',
629
    });
630
    my $library2 = $builder->build({
631
        source => 'Branch',
632
    });
633
    my $itemtype = $builder->build({
634
        source => 'Itemtype',
635
    });
636
637
    my $biblio = $builder->build_sample_biblio();
638
    my $item_infos = [
639
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
640
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
641
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
642
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
643
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
644
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
645
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
646
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
647
    ];
648
    my $number_of_items = scalar @$item_infos;
649
    my $number_of_items_with_homebranch_is_CPL =
650
      grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos;
651
652
    my @itemnumbers;
653
    for my $item_info (@$item_infos) {
654
        my $itemnumber = $builder->build_sample_item(
655
            {
656
                biblionumber  => $biblio->biblionumber,
657
                homebranch    => $item_info->{homebranch},
658
                holdingbranch => $item_info->{holdingbranch},
659
                itype         => $itemtype->{itemtype}
660
            }
661
        )->itemnumber;
662
663
        push @itemnumbers, $itemnumber;
664
    }
665
666
    # Emptied the OpacHiddenItems pref
667
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' );
668
669
    my ($itemfield) =
670
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' );
671
    my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber });
672
    warning_is { C4::Biblio::EmbedItemsInMarcBiblio() }
673
    { carped => 'EmbedItemsInMarcBiblio: No MARC record passed' },
674
      'Should carp is no record passed.';
675
676
    C4::Biblio::EmbedItemsInMarcBiblio({
677
        marc_record  => $record,
678
        biblionumber => $biblio->biblionumber });
679
    my @items = $record->field($itemfield);
680
    is( scalar @items, $number_of_items, 'Should return all items' );
681
682
    my $marc_with_items = C4::Biblio::GetMarcBiblio({
683
        biblionumber => $biblio->biblionumber,
684
        embed_items  => 1 });
685
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
686
687
    C4::Biblio::EmbedItemsInMarcBiblio({
688
        marc_record  => $record,
689
        biblionumber => $biblio->biblionumber,
690
        item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] });
691
    @items = $record->field($itemfield);
692
    is( scalar @items, 2, 'Should return all items present in the list' );
693
694
    C4::Biblio::EmbedItemsInMarcBiblio({
695
        marc_record  => $record,
696
        biblionumber => $biblio->biblionumber,
697
        opac         => 1 });
698
    @items = $record->field($itemfield);
699
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
700
701
    my $opachiddenitems = "
702
        homebranch: ['$library1->{branchcode}']";
703
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
704
705
    C4::Biblio::EmbedItemsInMarcBiblio({
706
        marc_record  => $record,
707
        biblionumber => $biblio->biblionumber });
708
    @items = $record->field($itemfield);
709
    is( scalar @items,
710
        $number_of_items,
711
        'Even with OpacHiddenItems set, all items should have been embedded' );
712
713
    C4::Biblio::EmbedItemsInMarcBiblio({
714
        marc_record  => $record,
715
        biblionumber => $biblio->biblionumber,
716
        opac         => 1 });
717
    @items = $record->field($itemfield);
718
    is(
719
        scalar @items,
720
        $number_of_items - $number_of_items_with_homebranch_is_CPL,
721
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded'
722
    );
723
724
    $opachiddenitems = "
725
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
726
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
727
    C4::Biblio::EmbedItemsInMarcBiblio({
728
        marc_record  => $record,
729
        biblionumber => $biblio->biblionumber,
730
        opac         => 1 });
731
    @items = $record->field($itemfield);
732
    is(
733
        scalar @items,
734
        0,
735
'For OPAC, If all items are hidden, no item should have been embedded'
736
    );
737
738
    $schema->storage->txn_rollback;
739
};
740
741
742
subtest 'get_hostitemnumbers_of' => sub {
621
subtest 'get_hostitemnumbers_of' => sub {
743
    plan tests => 3;
622
    plan tests => 3;
744
623
(-)a/t/db_dependent/Koha/Biblio/Metadata.t (-1 / +110 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
25
25
use C4::Biblio qw( AddBiblio );
26
use C4::Biblio qw( AddBiblio );
26
use Koha::Database;
27
use Koha::Database;
Lines 83-85 subtest 'record() tests' => sub { Link Here
83
84
84
    $schema->storage->txn_rollback;
85
    $schema->storage->txn_rollback;
85
};
86
};
87
88
subtest '_embed_items' => sub {
89
    plan tests => 8;
90
91
    $schema->storage->txn_begin();
92
93
    my $builder = t::lib::TestBuilder->new;
94
    my $library1 = $builder->build({
95
        source => 'Branch',
96
    });
97
    my $library2 = $builder->build({
98
        source => 'Branch',
99
    });
100
    my $itemtype = $builder->build({
101
        source => 'Itemtype',
102
    });
103
104
    my $biblio = $builder->build_sample_biblio();
105
    my $item_infos = [
106
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
107
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
108
        { homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} },
109
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
110
        { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} },
111
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
112
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
113
        { homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} },
114
    ];
115
    my $number_of_items = scalar @$item_infos;
116
    my $number_of_items_with_homebranch_is_CPL =
117
      grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos;
118
119
    my @itemnumbers;
120
    for my $item_info (@$item_infos) {
121
        my $itemnumber = $builder->build_sample_item(
122
            {
123
                biblionumber  => $biblio->biblionumber,
124
                homebranch    => $item_info->{homebranch},
125
                holdingbranch => $item_info->{holdingbranch},
126
                itype         => $itemtype->{itemtype}
127
            }
128
        )->itemnumber;
129
130
        push @itemnumbers, $itemnumber;
131
    }
132
133
    # Emptied the OpacHiddenItems pref
134
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' );
135
136
    throws_ok { Koha::Biblio::Metadata->record() }
137
    'Koha::Exceptions::Metadata',
138
'Koha::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter';
139
140
    my ($itemfield) =
141
      C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' );
142
    my $record = $biblio->metadata->record;
143
    Koha::Biblio::Metadata->record(
144
        {
145
            record       => $record,
146
            embed_items  => 1,
147
            biblionumber => $biblio->biblionumber
148
        }
149
    );
150
    my @items = $record->field($itemfield);
151
    is( scalar @items, $number_of_items, 'Should return all items' );
152
153
    my $marc_with_items = $biblio->metadata->record({ embed_items => 1 });
154
    is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches');
155
156
    $record = $biblio->metadata->record({ embed_items => 1, itemnumbers => [ $itemnumbers[1], $itemnumbers[3] ] });
157
    @items = $record->field($itemfield);
158
    is( scalar @items, 2, 'Should return all items present in the list' );
159
160
    $record = $biblio->metadata->record({ embed_items => 1, opac => 1 });
161
    @items = $record->field($itemfield);
162
    is( scalar @items, $number_of_items, 'Should return all items for opac' );
163
164
    my $opachiddenitems = "
165
        homebranch: ['$library1->{branchcode}']";
166
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
167
168
    $record = $biblio->metadata->record({ embed_items => 1 });
169
    @items = $record->field($itemfield);
170
    is( scalar @items,
171
        $number_of_items,
172
        'Even with OpacHiddenItems set, all items should have been embedded' );
173
174
    $record = $biblio->metadata->record({ embed_items => 1, opac => 1 });
175
    @items = $record->field($itemfield);
176
    is(
177
        scalar @items,
178
        $number_of_items - $number_of_items_with_homebranch_is_CPL,
179
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded'
180
    );
181
182
    $opachiddenitems = "
183
        homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']";
184
    t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems );
185
    $record = $biblio->metadata->record({ embed_items => 1, opac => 1 });
186
    @items = $record->field($itemfield);
187
    is(
188
        scalar @items,
189
        0,
190
'For OPAC, If all items are hidden, no item should have been embedded'
191
    );
192
193
    $schema->storage->txn_rollback;
194
};
(-)a/t/db_dependent/Koha/Filter/EmbedItemsAvailability.t (-3 / +6 lines)
Lines 25-31 use t::lib::TestBuilder; Link Here
25
25
26
use MARC::Record;
26
use MARC::Record;
27
27
28
use C4::Biblio qw( GetMarcFromKohaField AddBiblio GetMarcBiblio );
28
use C4::Biblio qw( GetMarcFromKohaField AddBiblio );
29
use Koha::Biblios;
29
use Koha::Database;
30
use Koha::Database;
30
use Koha::RecordProcessor;
31
use Koha::RecordProcessor;
31
32
Lines 84-90 subtest 'EmbedItemsAvailability tests' => sub { Link Here
84
    my $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
85
    my $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
85
    is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
86
    is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
86
87
87
    my $record = GetMarcBiblio({ biblionumber => $biblionumber });
88
    my $biblio_object = Koha::Biblios->find($biblionumber);
89
    my $record = $biblio_object->metadata->record;
88
    ok( !defined $record->field('999')->subfield('x'), q{The record doesn't originally contain 999$x} );
90
    ok( !defined $record->field('999')->subfield('x'), q{The record doesn't originally contain 999$x} );
89
    # Apply filter
91
    # Apply filter
90
    $processor->process($record);
92
    $processor->process($record);
Lines 123-129 subtest 'EmbedItemsAvailability tests' => sub { Link Here
123
    $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
125
    $processor = Koha::RecordProcessor->new( { filters => ('EmbedItemsAvailability') } );
124
    is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
126
    is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' );
125
127
126
    $record = GetMarcBiblio({ biblionumber => $biblionumber });
128
    $biblio_object = Koha::Biblios->find($biblionumber);
129
    $record = $biblio_object->metadata->record;
127
    ok( !defined $record->subfield('999', 'x'), q{The record doesn't originally contain 999$x} );
130
    ok( !defined $record->subfield('999', 'x'), q{The record doesn't originally contain 999$x} );
128
    # Apply filter
131
    # Apply filter
129
    $processor->process($record);
132
    $processor->process($record);
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t (-1 / +2 lines)
Lines 28-33 use t::lib::TestBuilder; Link Here
28
use MARC::Record;
28
use MARC::Record;
29
29
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::Biblios;
31
32
32
my $schema = Koha::Database->schema();
33
my $schema = Koha::Database->schema();
33
34
Lines 113-119 subtest 'index_records() tests' => sub { Link Here
113
    "When passing record and ids to index_records they are correctly passed through to update_index";
114
    "When passing record and ids to index_records they are correctly passed through to update_index";
114
115
115
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
116
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
116
    $marc_record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber, embed_items  => 1 });
117
    $marc_record = $biblio->metadata->record({ embed_items => 1 });
117
    warning_is {
118
    warning_is {
118
        $indexer->index_records( [ $biblio->biblionumber ],
119
        $indexer->index_records( [ $biblio->biblionumber ],
119
            'specialUpdate', 'biblioserver' );
120
            'specialUpdate', 'biblioserver' );
(-)a/t/db_dependent/OAI/AndSets.t (-5 / +5 lines)
Lines 25-32 use MARC::Record; Link Here
25
use Data::Dumper;
25
use Data::Dumper;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use C4::Biblio qw( GetMarcBiblio );
29
use C4::OAI::Sets qw( AddOAISet ModOAISet ModOAISetMappings CalcOAISetsBiblio );
28
use C4::OAI::Sets qw( AddOAISet ModOAISet ModOAISetMappings CalcOAISetsBiblio );
29
use Koha::Biblios;
30
30
31
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
32
32
Lines 98-108 my $biblionumber1 = $biblio_1->biblionumber; Link Here
98
my $biblionumber2 = $biblio_2->biblionumber;
98
my $biblionumber2 = $biblio_2->biblionumber;
99
99
100
100
101
my $record = GetMarcBiblio({ biblionumber => $biblionumber1 });
101
my $record = $biblio_1->metadata->record;
102
my @setsEq = CalcOAISetsBiblio($record);
102
my @setsEq = CalcOAISetsBiblio($record);
103
ok(!@setsEq, 'If only one condition is true, the record does not belong to the set');
103
ok(!@setsEq, 'If only one condition is true, the record does not belong to the set');
104
104
105
$record = GetMarcBiblio({ biblionumber => $biblionumber2 });
105
$record = $biblio_2->metadata->record;
106
@setsEq = CalcOAISetsBiblio($record);
106
@setsEq = CalcOAISetsBiblio($record);
107
is_deeply(@setsEq, $set1_id, 'If all conditions are true, the record belongs to the set');
107
is_deeply(@setsEq, $set1_id, 'If all conditions are true, the record belongs to the set');
108
108
Lines 169-180 $biblio_2 = $builder->build_sample_biblio({ author => 'myAuthor', itemtype => 'm Link Here
169
$biblionumber1 = $biblio_1->biblionumber;
169
$biblionumber1 = $biblio_1->biblionumber;
170
$biblionumber2 = $biblio_2->biblionumber;
170
$biblionumber2 = $biblio_2->biblionumber;
171
171
172
$record = GetMarcBiblio({ biblionumber => $biblionumber1 });
172
$record = $biblio_1->metadata->record;
173
@setsEq = CalcOAISetsBiblio($record);
173
@setsEq = CalcOAISetsBiblio($record);
174
174
175
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with only the title belongs to the set');
175
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with only the title belongs to the set');
176
176
177
$record = GetMarcBiblio({ biblionumber => $biblionumber2 });
177
$record = $biblio_2->metadata->record;
178
@setsEq = CalcOAISetsBiblio($record);
178
@setsEq = CalcOAISetsBiblio($record);
179
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with author and itemtype belongs to the set');
179
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with author and itemtype belongs to the set');
180
180
(-)a/t/db_dependent/OAI/Server.t (-10 / +13 lines)
Lines 33-42 use YAML::XS; Link Here
33
use t::lib::Mocks;
33
use t::lib::Mocks;
34
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
35
35
36
use C4::Biblio qw( AddBiblio GetMarcBiblio ModBiblio DelBiblio );
36
use C4::Biblio qw( AddBiblio ModBiblio DelBiblio );
37
use C4::Context;
37
use C4::Context;
38
use C4::OAI::Sets qw(AddOAISet);
38
use C4::OAI::Sets qw(AddOAISet);
39
39
40
use Koha::Biblios;
40
use Koha::Biblio::Metadatas;
41
use Koha::Biblio::Metadatas;
41
use Koha::Database;
42
use Koha::Database;
42
use Koha::DateUtils qw( dt_from_string );
43
use Koha::DateUtils qw( dt_from_string );
Lines 104-110 foreach my $index ( 0 .. NUMBER_OF_MARC_RECORDS - 1 ) { Link Here
104
    $sth2->execute($timestamp,$biblionumber);
105
    $sth2->execute($timestamp,$biblionumber);
105
    $timestamp .= 'Z';
106
    $timestamp .= 'Z';
106
    $timestamp =~ s/ /T/;
107
    $timestamp =~ s/ /T/;
107
    $record = GetMarcBiblio({ biblionumber => $biblionumber });
108
    my $biblio = Koha::Biblios->find($biblionumber);
109
    $record = $biblio->metadata->record;
108
    my $record_transformed = $record->clone;
110
    my $record_transformed = $record->clone;
109
    $record_transformed->delete_fields( $record_transformed->field('952'));
111
    $record_transformed->delete_fields( $record_transformed->field('952'));
110
    $record_transformed = XMLin($record_transformed->as_xml_record);
112
    $record_transformed = XMLin($record_transformed->as_xml_record);
Lines 391-397 subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me Link Here
391
393
392
    # Modify record to trigger auto update of timestamp
394
    # Modify record to trigger auto update of timestamp
393
    (my $biblionumber = $marcxml[0]->{header}->{identifier}) =~ s/^.*:(.*)/$1/;
395
    (my $biblionumber = $marcxml[0]->{header}->{identifier}) =~ s/^.*:(.*)/$1/;
394
    my $record = GetMarcBiblio({biblionumber => $biblionumber});
396
    my $biblio = Koha::Biblios->find($biblionumber);
397
    my $record = $biblio->metadata->record;
395
    $record->append_fields(MARC::Field->new(999, '', '', z => '_'));
398
    $record->append_fields(MARC::Field->new(999, '', '', z => '_'));
396
    ModBiblio( $record, $biblionumber );
399
    ModBiblio( $record, $biblionumber );
397
    my $from_dt = dt_from_string(
400
    my $from_dt = dt_from_string(
Lines 577-583 subtest 'Tests for timestamp handling' => sub { Link Here
577
            },
580
            },
578
            metadata => {
581
            metadata => {
579
                record => XMLin(
582
                record => XMLin(
580
                    GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record()
583
                    $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record()
581
                )
584
                )
582
            }
585
            }
583
        }
586
        }
Lines 590-596 subtest 'Tests for timestamp handling' => sub { Link Here
590
            },
593
            },
591
            metadata => {
594
            metadata => {
592
                record => XMLin(
595
                record => XMLin(
593
                    GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 0, opac => 1 })->as_xml_record()
596
                    $biblio1->metadata->record({opac => 1})->as_xml_record()
594
                )
597
                )
595
            }
598
            }
596
        }
599
        }
Lines 649-655 subtest 'Tests for timestamp handling' => sub { Link Here
649
652
650
    $expected->{record}{header}{datestamp} = $utc_timestamp;
653
    $expected->{record}{header}{datestamp} = $utc_timestamp;
651
    $expected->{record}{metadata}{record} = XMLin(
654
    $expected->{record}{metadata}{record} = XMLin(
652
        GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record()
655
        $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record()
653
    );
656
    );
654
657
655
    test_query(
658
    test_query(
Lines 715-721 subtest 'Tests for timestamp handling' => sub { Link Here
715
718
716
    $expected->{record}{header}{datestamp} = $utc_timestamp;
719
    $expected->{record}{header}{datestamp} = $utc_timestamp;
717
    $expected->{record}{metadata}{record} = XMLin(
720
    $expected->{record}{metadata}{record} = XMLin(
718
        GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record()
721
        $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record()
719
    );
722
    );
720
723
721
    test_query(
724
    test_query(
Lines 744-750 subtest 'Tests for timestamp handling' => sub { Link Here
744
    $sth_del_item->execute($timestamp, $item2->itemnumber);
747
    $sth_del_item->execute($timestamp, $item2->itemnumber);
745
748
746
    $expected->{record}{metadata}{record} = XMLin(
749
    $expected->{record}{metadata}{record} = XMLin(
747
        GetMarcBiblio({ biblionumber => $biblio1->biblionumber, embed_items => 1, opac => 1 })->as_xml_record()
750
        $biblio1->metadata->record({ embed_items => 1, opac => 1})->as_xml_record()
748
    );
751
    );
749
752
750
    test_query(
753
    test_query(
Lines 827-833 subtest 'Tests for timestamp handling' => sub { Link Here
827
                },
830
                },
828
                metadata => {
831
                metadata => {
829
                    record => XMLin(
832
                    record => XMLin(
830
                        GetMarcBiblio({ biblionumber => $biblio2->biblionumber, embed_items => 1, opac => 1 })->as_xml_record()
833
                        $biblio2->metadata->record({ embed_items => 1, opac => 1})->as_xml_record()
831
                    )
834
                    )
832
                }
835
                }
833
            }
836
            }
Lines 843-849 subtest 'Tests for timestamp handling' => sub { Link Here
843
                },
846
                },
844
                metadata => {
847
                metadata => {
845
                    record => XMLin(
848
                    record => XMLin(
846
                        GetMarcBiblio({ biblionumber => $biblio2->biblionumber, embed_items => 0, opac => 1 })->as_xml_record()
849
                        $biblio2->metadata->record->as_xml_record()
847
                    )
850
                    )
848
                }
851
                }
849
            }
852
            }
(-)a/t/db_dependent/Record/marcrecord2csv.t (-2 / +2 lines)
Lines 7-16 use MARC::Record; Link Here
7
use MARC::Field;
7
use MARC::Field;
8
use Text::CSV::Encoded;
8
use Text::CSV::Encoded;
9
9
10
use C4::Biblio qw( AddBiblio GetMarcBiblio );
10
use C4::Biblio qw( AddBiblio );
11
use C4::Context;
11
use C4::Context;
12
use C4::Record qw( marcrecord2csv );
12
use C4::Record qw( marcrecord2csv );
13
use Koha::Database;
13
use Koha::Database;
14
use Koha::Biblios;
14
15
15
use C4::Items qw( AddItemFromMarc );
16
use C4::Items qw( AddItemFromMarc );
16
17
Lines 26-32 my $module_biblio = Test::MockModule->new('C4::Biblio'); Link Here
26
my $record = new_record();
27
my $record = new_record();
27
my $frameworkcode = q||;
28
my $frameworkcode = q||;
28
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, $frameworkcode );
29
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, $frameworkcode );
29
$module_biblio->mock( 'GetMarcBiblio', sub{ $record } );
30
30
31
my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a);
31
my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a);
32
my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content });
32
my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content });
(-)a/t/db_dependent/Reserves.t (-2 / +4 lines)
Lines 29-38 use DateTime::Duration; Link Here
29
29
30
use C4::Circulation qw( AddReturn AddIssue );
30
use C4::Circulation qw( AddReturn AddIssue );
31
use C4::Items;
31
use C4::Items;
32
use C4::Biblio qw( GetMarcBiblio GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
33
use C4::Members;
33
use C4::Members;
34
use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
34
use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
35
use Koha::ActionLogs;
35
use Koha::ActionLogs;
36
use Koha::Biblios;
36
use Koha::Caches;
37
use Koha::Caches;
37
use Koha::DateUtils qw( dt_from_string output_pref );
38
use Koha::DateUtils qw( dt_from_string output_pref );
38
use Koha::Holds;
39
use Koha::Holds;
Lines 643-649 t::lib::Mocks::mock_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' ); Link Here
643
#Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
644
#Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
644
645
645
#Set the ageRestriction for the Biblio
646
#Set the ageRestriction for the Biblio
646
my $record = GetMarcBiblio({ biblionumber =>  $bibnum });
647
$biblio = Koha::Biblios->find($bibnum);
648
my $record = $biblio->metadata->record;
647
my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
649
my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
648
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
650
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
649
C4::Biblio::ModBiblio( $record, $bibnum, $frameworkcode );
651
C4::Biblio::ModBiblio( $record, $bibnum, $frameworkcode );
(-)a/tools/showdiffmarc.pl (-5 / +1 lines)
Lines 28-34 use CGI qw(:standard -utf8); Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Output qw( output_html_with_http_headers );
29
use C4::Output qw( output_html_with_http_headers );
30
use C4::Auth qw( get_template_and_user );
30
use C4::Auth qw( get_template_and_user );
31
use C4::Biblio qw( GetMarcBiblio );
32
use C4::Auth qw( get_template_and_user );
31
use C4::Auth qw( get_template_and_user );
33
use C4::ImportBatch qw( GetImportBiblios );
32
use C4::ImportBatch qw( GetImportBiblios );
34
use C4::AuthoritiesMarc qw( GetAuthority );
33
use C4::AuthoritiesMarc qw( GetAuthority );
Lines 62-72 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
62
);
61
);
63
62
64
if ( $type eq 'biblio' ) {
63
if ( $type eq 'biblio' ) {
65
    $record = GetMarcBiblio({
66
        biblionumber => $recordid,
67
        embed_items  => 1,
68
    });
69
    my $biblio = Koha::Biblios->find( $recordid );
64
    my $biblio = Koha::Biblios->find( $recordid );
65
    $record = $biblio->metadata->record->({ embed_items => 1 });
70
    $recordTitle = $biblio->title;
66
    $recordTitle = $biblio->title;
71
}
67
}
72
elsif ( $type eq 'auth' ) {
68
elsif ( $type eq 'auth' ) {
(-)a/virtualshelves/downloadshelf.pl (-4 / +3 lines)
Lines 22-32 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
23
24
use C4::Auth qw( get_template_and_user );
24
use C4::Auth qw( get_template_and_user );
25
use C4::Biblio qw( GetMarcBiblio );
26
use C4::Output qw( output_html_with_http_headers );
25
use C4::Output qw( output_html_with_http_headers );
27
use C4::Record;
26
use C4::Record;
28
use C4::Ris qw( marc2ris );
27
use C4::Ris qw( marc2ris );
29
28
29
use Koha::Biblios;
30
use Koha::CsvProfiles;
30
use Koha::CsvProfiles;
31
use Koha::Virtualshelves;
31
use Koha::Virtualshelves;
32
32
Lines 68-76 if ($shelfid && $format) { Link Here
68
            else { #Other formats
68
            else { #Other formats
69
                while ( my $content = $contents->next ) {
69
                while ( my $content = $contents->next ) {
70
                    my $biblionumber = $content->biblionumber;
70
                    my $biblionumber = $content->biblionumber;
71
                    my $record = GetMarcBiblio({
71
                    my $biblio = Koha::Biblios->find($biblionumber);
72
                        biblionumber => $biblionumber,
72
                    my $record = $biblio->metadata->record({ embed_items => 1 });
73
                        embed_items  => 1 });
74
                    if ($format eq 'iso2709') {
73
                    if ($format eq 'iso2709') {
75
                        $output .= $record->as_usmarc();
74
                        $output .= $record->as_usmarc();
76
                    }
75
                    }
(-)a/virtualshelves/sendshelf.pl (-5 / +3 lines)
Lines 26-32 use Try::Tiny qw( catch try ); Link Here
26
26
27
use C4::Auth qw( get_template_and_user );
27
use C4::Auth qw( get_template_and_user );
28
use C4::Biblio qw(
28
use C4::Biblio qw(
29
    GetMarcBiblio
30
    GetMarcISBN
29
    GetMarcISBN
31
    GetMarcSubjects
30
    GetMarcSubjects
32
);
31
);
Lines 35-40 use C4::Output qw( Link Here
35
    output_html_with_http_headers
34
    output_html_with_http_headers
36
    output_and_exit
35
    output_and_exit
37
);
36
);
37
38
use Koha::Biblios;
38
use Koha::Email;
39
use Koha::Email;
39
use Koha::Virtualshelves;
40
use Koha::Virtualshelves;
40
41
Lines 78-86 if ($to_address) { Link Here
78
        my $biblionumber     = $content->biblionumber;
79
        my $biblionumber     = $content->biblionumber;
79
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
80
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
80
        my $dat              = $biblio->unblessed;
81
        my $dat              = $biblio->unblessed;
81
        my $record           = GetMarcBiblio({
82
        my $record           = $biblio->metadata->record({ embed_items => 1 });
82
            biblionumber => $biblionumber,
83
            embed_items  => 1 });
84
        my $marcauthorsarray = $biblio->get_marc_authors;
83
        my $marcauthorsarray = $biblio->get_marc_authors;
85
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
84
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
86
85
87
- 

Return to bug 29697