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 1159-1249 sub GetMarcSubfieldStructureFromKohaField { Link Here
1159
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1158
    return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0];
1160
}
1159
}
1161
1160
1162
=head2 GetMarcBiblio
1163
1164
  my $record = GetMarcBiblio({
1165
      biblionumber => $biblionumber,
1166
      embed_items  => $embeditems,
1167
      opac         => $opac,
1168
      borcat       => $patron_category });
1169
1170
Returns MARC::Record representing a biblio record, or C<undef> if the
1171
biblionumber doesn't exist.
1172
1173
Both embed_items and opac are optional.
1174
If embed_items is passed and is 1, items are embedded.
1175
If opac is passed and is 1, the record is filtered as needed.
1176
1177
=over 4
1178
1179
=item C<$biblionumber>
1180
1181
the biblionumber
1182
1183
=item C<$embeditems>
1184
1185
set to true to include item information.
1186
1187
=item C<$opac>
1188
1189
set to true to make the result suited for OPAC view. This causes things like
1190
OpacHiddenItems to be applied.
1191
1192
=item C<$borcat>
1193
1194
If the OpacHiddenItemsExceptions system preference is set, this patron category
1195
can be used to make visible OPAC items which would be normally hidden.
1196
It only makes sense in combination both embed_items and opac values true.
1197
1198
=back
1199
1200
=cut
1201
1202
sub GetMarcBiblio {
1203
    my ($params) = @_;
1204
1205
    if (not defined $params) {
1206
        carp 'GetMarcBiblio called without parameters';
1207
        return;
1208
    }
1209
1210
    my $biblionumber = $params->{biblionumber};
1211
    my $embeditems   = $params->{embed_items} || 0;
1212
    my $opac         = $params->{opac} || 0;
1213
    my $borcat       = $params->{borcat} // q{};
1214
1215
    if (not defined $biblionumber) {
1216
        carp 'GetMarcBiblio called with undefined biblionumber';
1217
        return;
1218
    }
1219
1220
    my $marcxml = GetXmlBiblio( $biblionumber );
1221
    $marcxml = StripNonXmlChars( $marcxml );
1222
    MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') );
1223
    my $record = MARC::Record->new();
1224
1225
    if ($marcxml) {
1226
        $record = eval {
1227
            MARC::Record::new_from_xml( $marcxml, "UTF-8",
1228
                C4::Context->preference('marcflavour') );
1229
        };
1230
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1231
        return unless $record;
1232
1233
        C4::Biblio::EmbedItemsInMarcBiblio({
1234
            marc_record  => $record,
1235
            biblionumber => $biblionumber,
1236
            opac         => $opac,
1237
            borcat       => $borcat })
1238
          if ($embeditems);
1239
1240
        return $record;
1241
    }
1242
    else {
1243
        return;
1244
    }
1245
}
1246
1247
=head2 GetXmlBiblio
1161
=head2 GetXmlBiblio
1248
1162
1249
  my $marcxml = GetXmlBiblio($biblionumber);
1163
  my $marcxml = GetXmlBiblio($biblionumber);
Lines 2455-2536 sub ModZebra { Link Here
2455
    }
2369
    }
2456
}
2370
}
2457
2371
2458
=head2 EmbedItemsInMarcBiblio
2459
2460
    EmbedItemsInMarcBiblio({
2461
        marc_record  => $marc,
2462
        biblionumber => $biblionumber,
2463
        item_numbers => $itemnumbers,
2464
        opac         => $opac });
2465
2466
Given a MARC::Record object containing a bib record,
2467
modify it to include the items attached to it as 9XX
2468
per the bib's MARC framework.
2469
if $itemnumbers is defined, only specified itemnumbers are embedded.
2470
2471
If $opac is true, then opac-relevant suppressions are included.
2472
2473
If opac filtering will be done, borcat should be passed to properly
2474
override if necessary.
2475
2476
=cut
2477
2478
sub EmbedItemsInMarcBiblio {
2479
    my ($params) = @_;
2480
    my ($marc, $biblionumber, $itemnumbers, $opac, $borcat);
2481
    $marc = $params->{marc_record};
2482
    if ( !$marc ) {
2483
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2484
        return;
2485
    }
2486
    $biblionumber = $params->{biblionumber};
2487
    $itemnumbers = $params->{item_numbers};
2488
    $opac = $params->{opac};
2489
    $borcat = $params->{borcat} // q{};
2490
2491
    $itemnumbers = [] unless defined $itemnumbers;
2492
2493
    my $frameworkcode = GetFrameworkCode($biblionumber);
2494
    _strip_item_fields($marc, $frameworkcode);
2495
2496
    # ... and embed the current items
2497
    my $dbh = C4::Context->dbh;
2498
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2499
    $sth->execute($biblionumber);
2500
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
2501
2502
    my @item_fields; # Array holding the actual MARC data for items to be included.
2503
    my @items;       # Array holding items which are both in the list (sitenumbers)
2504
                     # and on this biblionumber
2505
2506
    # Flag indicating if there is potential hiding.
2507
    my $opachiddenitems = $opac
2508
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2509
2510
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2511
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2512
        my $item;
2513
        if ( $opachiddenitems ) {
2514
            $item = Koha::Items->find($itemnumber);
2515
            $item = $item ? $item->unblessed : undef;
2516
        }
2517
        push @items, { itemnumber => $itemnumber, item => $item };
2518
    }
2519
            items  => \@items2pass,
2520
            borcat => $borcat })
2521
      : ();
2522
    # Convert to a hash for quick searching
2523
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2524
    my @itemnumbers = Koha::Items->search( { itemnumber => $itemnumbers } )
2525
      ->filter_by_visible_in_opac({ patron => })->get_column('itemnumber');
2526
    foreach my $itemnumber ( map { $_->{itemnumber} } @items ) {
2527
        next if $hiddenitems{$itemnumber};
2528
        my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
2529
        push @item_fields, $item_marc->field($itemtag);
2530
    }
2531
    $marc->append_fields(@item_fields);
2532
}
2533
2534
=head1 INTERNAL FUNCTIONS
2372
=head1 INTERNAL FUNCTIONS
2535
2373
2536
=head2 _koha_marc_update_bib_ids
2374
=head2 _koha_marc_update_bib_ids
Lines 3074-3080 sub UpdateTotalIssues { Link Here
3074
2912
3075
    my $biblio = Koha::Biblios->find($biblionumber);
2913
    my $biblio = Koha::Biblios->find($biblionumber);
3076
    unless ($biblio) {
2914
    unless ($biblio) {
3077
        carp "UpdateTotalIssues could not get datas of biblio";
2915
        carp "UpdateTotalIssues could not get biblio";
3078
        return;
2916
        return;
3079
    }
2917
    }
3080
2918
(-)a/C4/ILSDI/Services.pm (-5 / +1 lines)
Lines 24-30 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 );
28
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
27
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
29
use C4::Context;
28
use C4::Context;
30
use C4::Auth;
29
use C4::Auth;
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 27-34 use Koha::Exceptions; Link Here
27
use Koha::Exceptions::Elasticsearch;
27
use Koha::Exceptions::Elasticsearch;
28
use Koha::SearchEngine::Zebra::Indexer;
28
use Koha::SearchEngine::Zebra::Indexer;
29
use C4::AuthoritiesMarc qw//;
29
use C4::AuthoritiesMarc qw//;
30
use C4::Biblio;
31
use C4::Context;
30
use C4::Context;
31
use Koha::Biblios;
32
32
33
=head1 NAME
33
=head1 NAME
34
34
Lines 331-337 sub index_records { Link Here
331
sub _get_record {
331
sub _get_record {
332
    my ( $id, $server ) = @_;
332
    my ( $id, $server ) = @_;
333
    return $server eq 'biblioserver'
333
    return $server eq 'biblioserver'
334
        ? C4::Biblio::GetMarcBiblio({ biblionumber => $id, embed_items  => 1 })
334
        ? Koha::Biblios->find($id)->metadata->record({ embed_items => 1 })
335
        : C4::AuthoritiesMarc::GetAuthority($id);
335
        : C4::AuthoritiesMarc::GetAuthority($id);
336
}
336
}
337
337
(-)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 85-92 if ( C4::Context->config('enable_plugins') ) { Link Here
85
my $biblionumber = $query->param('biblionumber');
85
my $biblionumber = $query->param('biblionumber');
86
$biblionumber = HTML::Entities::encode($biblionumber);
86
$biblionumber = HTML::Entities::encode($biblionumber);
87
# FIXME Special case here
87
# FIXME Special case here
88
my $record       = GetMarcBiblio({ biblionumber => $biblionumber });
89
my $biblio = Koha::Biblios->find( $biblionumber );
88
my $biblio = Koha::Biblios->find( $biblionumber );
89
my $record = $biblio->metadata->record;
90
$template->param( 'biblio', $biblio );
90
$template->param( 'biblio', $biblio );
91
91
92
if ( not defined $record ) {
92
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 284-300 if ( $pending_checkouts->count ) { # Useless test Link Here
284
            $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
281
            $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
285
        }
282
        }
286
283
287
        $issue->{biblio_object} = Koha::Biblios->find($issue->{biblionumber});
284
        my $biblio_object = Koha::Biblios->find($issue->{biblionumber});
285
        $issue->{biblio_object} = $biblio_object;
288
        push @issuedat, $issue;
286
        push @issuedat, $issue;
289
        $count++;
287
        $count++;
290
288
291
        my $isbn = GetNormalizedISBN($issue->{'isbn'});
289
        my $isbn = GetNormalizedISBN($issue->{'isbn'});
292
        $issue->{normalized_isbn} = $isbn;
290
        $issue->{normalized_isbn} = $isbn;
293
        my $marcrecord = GetMarcBiblio({
291
        my $marcrecord = $biblio_object->metadata->record({ embed_items => 1, opac => 1, patron => $patron,});
294
            biblionumber => $issue->{'biblionumber'},
295
            embed_items  => 1,
296
            opac         => 1,
297
            borcat       => $borcat });
298
        $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
292
        $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
299
293
300
                # My Summary HTML
294
                # 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 362-368 sub redirect_add_subscription { Link Here
362
    }
361
    }
363
362
364
    my @additional_fields;
363
    my @additional_fields;
365
    my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 });
364
    my $biblio = Koha::Biblios->find($biblionumber);
365
    my $record = $biblio->metadata->record({ embed_items => 1 });
366
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
366
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
367
    while ( my $field = $subscription_fields->next ) {
367
    while ( my $field = $subscription_fields->next ) {
368
        my $value = $query->param('additional_field_' . $field->id);
368
        my $value = $query->param('additional_field_' . $field->id);
Lines 480-486 sub redirect_mod_subscription { Link Here
480
    );
480
    );
481
481
482
    my @additional_fields;
482
    my @additional_fields;
483
    my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 });
483
    my $biblio = Koha::Biblios->find($biblionumber);
484
    my $record = $biblio->metadata->record({ embed_items => 1 });
484
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
485
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
485
    while ( my $field = $subscription_fields->next ) {
486
    while ( my $field = $subscription_fields->next ) {
486
        my $value = $query->param('additional_field_' . $field->id);
487
        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 271-278 sub run_tests { Link Here
271
    is( $data->{ title }, undef,
271
    is( $data->{ title }, undef,
272
        '(GetBiblioData) Title field is empty in fresh biblio.');
272
        '(GetBiblioData) Title field is empty in fresh biblio.');
273
273
274
    my $biblio = Koha::Biblios->find($biblionumber);
275
274
    my ( $isbn_field, $isbn_subfield ) = get_isbn_field();
276
    my ( $isbn_field, $isbn_subfield ) = get_isbn_field();
275
    my $marc = GetMarcBiblio({ biblionumber => $biblionumber });
277
    my $marc = $biblio->metadata->record;
276
    is( $marc->subfield( $isbn_field, $isbn_subfield ), $isbn, );
278
    is( $marc->subfield( $isbn_field, $isbn_subfield ), $isbn, );
277
279
278
    # Add title
280
    # Add title
Lines 283-289 sub run_tests { Link Here
283
    is( $data->{ title }, $title,
285
    is( $data->{ title }, $title,
284
        'ModBiblio correctly added the title field, and GetBiblioData.');
286
        'ModBiblio correctly added the title field, and GetBiblioData.');
285
    is( $data->{ isbn }, $isbn, '(ModBiblio) ISBN is still there after ModBiblio.');
287
    is( $data->{ isbn }, $isbn, '(ModBiblio) ISBN is still there after ModBiblio.');
286
    $marc = GetMarcBiblio({ biblionumber => $biblionumber });
288
    $marc = $biblio->metadata->record;
287
    my ( $title_field, $title_subfield ) = get_title_field();
289
    my ( $title_field, $title_subfield ) = get_title_field();
288
    is( $marc->subfield( $title_field, $title_subfield ), $title, );
290
    is( $marc->subfield( $title_field, $title_subfield ), $title, );
289
291
Lines 420-428 sub run_tests { Link Here
420
422
421
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
423
    is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100,
422
        "GetMarcPrice returns the correct value");
424
        "GetMarcPrice returns the correct value");
423
    my $updatedrecord = GetMarcBiblio({
425
    my $updatedrecord = $biblio->metadata->record;
424
        biblionumber => $biblionumber,
425
        embed_items  => 0 });
426
    my $frameworkcode = GetFrameworkCode($biblionumber);
426
    my $frameworkcode = GetFrameworkCode($biblionumber);
427
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
427
    my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
428
    die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag;
428
    die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag;
Lines 699-705 subtest 'MarcFieldForCreatorAndModifier' => sub { Link Here
699
    my $record = MARC::Record->new();
699
    my $record = MARC::Record->new();
700
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
700
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
701
701
702
    $record = GetMarcBiblio({biblionumber => $biblionumber});
702
    my $biblio = Koha::Biblios->find($biblionumber);
703
    $record = $biblio->metadata->record;
703
    is($record->subfield('998', 'a'), 123, '998$a = 123');
704
    is($record->subfield('998', 'a'), 123, '998$a = 123');
704
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
705
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
705
    is($record->subfield('998', 'c'), 123, '998$c = 123');
706
    is($record->subfield('998', 'c'), 123, '998$c = 123');
Lines 708-714 subtest 'MarcFieldForCreatorAndModifier' => sub { Link Here
708
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
709
    $c4_context->mock('userenv', sub { return { number => 321, firstname => 'Jane', surname => 'Doe'}; });
709
    C4::Biblio::ModBiblio($record, $biblionumber, '');
710
    C4::Biblio::ModBiblio($record, $biblionumber, '');
710
711
711
    $record = GetMarcBiblio({biblionumber => $biblionumber});
712
    $record = $biblio->metadata->record;
712
    is($record->subfield('998', 'a'), 123, '998$a = 123');
713
    is($record->subfield('998', 'a'), 123, '998$a = 123');
713
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
714
    is($record->subfield('998', 'b'), 'John Doe', '998$b = John Doe');
714
    is($record->subfield('998', 'c'), 321, '998$c = 321');
715
    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 105-111 subtest 'index_records() tests' => sub { Link Here
105
        "When passing record and ids to index_records they are correctly passed through to update_index";
106
        "When passing record and ids to index_records they are correctly passed through to update_index";
106
107
107
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
108
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
108
    $marc_record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber, embed_items  => 1 });
109
    $marc_record = $biblio->metadata->record({ embed_items => 1 });
109
    warning_is{ $indexer->index_records([$biblio->biblionumber],'specialUpdate','biblioserver'); } $biblio->biblionumber.$marc_record->as_usmarc,
110
    warning_is{ $indexer->index_records([$biblio->biblionumber],'specialUpdate','biblioserver'); } $biblio->biblionumber.$marc_record->as_usmarc,
110
        "When passing id only to index_records the marc record is fetched and passed through to update_index";
111
        "When passing id only to index_records the marc record is fetched and passed through to update_index";
111
};
112
};
(-)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 CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
34
use C4::Reserves qw( AddReserve 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 583-589 t::lib::Mocks::mock_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' ); Link Here
583
#Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
584
#Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
584
585
585
#Set the ageRestriction for the Biblio
586
#Set the ageRestriction for the Biblio
586
my $record = GetMarcBiblio({ biblionumber =>  $bibnum });
587
$biblio = Koha::Biblios->find($bibnum);
588
my $record = $biblio->metadata->record;
587
my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
589
my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
588
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
590
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
589
C4::Biblio::ModBiblio( $record, $bibnum, $frameworkcode );
591
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( GetRecordFromImportBiblio GetImportBiblios );
32
use C4::ImportBatch qw( GetRecordFromImportBiblio GetImportBiblios );
34
use C4::AuthoritiesMarc qw( GetAuthority );
33
use C4::AuthoritiesMarc qw( GetAuthority );
Lines 61-71 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
61
);
60
);
62
61
63
if ( $type eq 'biblio' ) {
62
if ( $type eq 'biblio' ) {
64
    $record = GetMarcBiblio({
65
        biblionumber => $recordid,
66
        embed_items  => 1,
67
    });
68
    my $biblio = Koha::Biblios->find( $recordid );
63
    my $biblio = Koha::Biblios->find( $recordid );
64
    $record = $biblio->metadata->record->({ embed_items => 1 });
69
    $recordTitle = $biblio->title;
65
    $recordTitle = $biblio->title;
70
}
66
}
71
elsif ( $type eq 'auth' ) {
67
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