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

(-)a/Koha/Biblio/Metadata.pm (-5 / +6 lines)
Lines 129-134 sub record { Link Here
129
            'Koha::Biblio::Metadata->record called on unhandled format: ' . $format );
129
            'Koha::Biblio::Metadata->record called on unhandled format: ' . $format );
130
    }
130
    }
131
131
132
    # FIXME: Remove existing items from the MARC record. This should be handled
133
    #        at store() time or pre-filtering in {Add|Mod}Biblio. Remove the FIXME
134
    #        once we reach some consensus on how to handle this.
135
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
136
    $record->delete_field( ( $record->field($itemtag) ) );
137
132
    if ( $embed_items ) {
138
    if ( $embed_items ) {
133
        $self->_embed_items({ %$params, format => $format, record => $record });
139
        $self->_embed_items({ %$params, format => $format, record => $record });
134
    }
140
    }
Lines 223-234 sub _embed_items { Link Here
223
229
224
    if ( $format eq 'marcxml' ) {
230
    if ( $format eq 'marcxml' ) {
225
231
226
        # First remove the existing items from the MARC record
227
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
232
        my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
228
        foreach my $field ( $record->field($itemtag) ) {
229
            $record->delete_field($field);
230
        }
231
232
        my $biblio = Koha::Biblios->find($biblionumber);
233
        my $biblio = Koha::Biblios->find($biblionumber);
233
234
234
        my $items = $biblio->items;
235
        my $items = $biblio->items;
(-)a/t/db_dependent/Koha/Biblio/Metadata.t (-3 / +24 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 5;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::MockModule;
22
use Test::Warn;
23
use Test::Warn;
23
24
24
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 36-42 my $builder = t::lib::TestBuilder->new; Link Here
36
37
37
subtest 'record() tests' => sub {
38
subtest 'record() tests' => sub {
38
39
39
    plan tests => 9;
40
    plan tests => 11;
40
41
41
    $schema->storage->txn_begin;
42
    $schema->storage->txn_begin;
42
43
Lines 45-56 subtest 'record() tests' => sub { Link Here
45
    # Create a valid record
46
    # Create a valid record
46
    my $record = MARC::Record->new();
47
    my $record = MARC::Record->new();
47
    my $field  = MARC::Field->new( '245', '', '', 'a' => $title );
48
    my $field  = MARC::Field->new( '245', '', '', 'a' => $title );
48
    $record->append_fields($field);
49
    my $f952_1 = MARC::Field->new(
50
        '952', '', '', 0 => '1',
51
        y => 'BK',
52
        c => 'GEN',
53
        d => '2001-06-25',
54
    );
55
    my $f952_2 = MARC::Field->new(
56
        '952', '', '', 0 => '1',
57
        y => 'BK',
58
        c => 'GEN',
59
        d => '2001-06-25',
60
    );
61
    $record->append_fields( $field, $f952_1, $f952_2 );
49
    my ($biblio_id) = C4::Biblio::AddBiblio( $record, '' );
62
    my ($biblio_id) = C4::Biblio::AddBiblio( $record, '' );
50
63
64
    my @fields_952 = $record->field('952');
65
    is( scalar @fields_952, 2, 'The record to be inserted contains 2 item fields' );
66
67
    my $c4_biblio = Test::MockModule->new('C4::Biblio');
68
    $c4_biblio->mock( 'GetMarcFromKohaField', sub { return '952'; } );
69
51
    my $metadata = Koha::Biblios->find($biblio_id)->metadata;
70
    my $metadata = Koha::Biblios->find($biblio_id)->metadata;
52
    my $record2  = $metadata->record;
71
    my $record2  = $metadata->record;
53
72
73
    @fields_952 = $record2->field('952');
74
    is( scalar @fields_952, 0, 'Item fields stripped out then calling $metadata->record' );
75
54
    is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
76
    is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' );
55
    is( $record2->field('245')->subfield("a"),
77
    is( $record2->field('245')->subfield("a"),
56
        $title, 'Title in 245$a matches title from original record object' );
78
        $title, 'Title in 245$a matches title from original record object' );
57
- 

Return to bug 31224