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

(-)a/Koha/Authority.pm (-3 / +16 lines)
Lines 148-158 Return the MARC::Record for this authority Link Here
148
sub record {
148
sub record {
149
    my ( $self ) = @_;
149
    my ( $self ) = @_;
150
150
151
    my $flavour =
151
    my $flavour = $self->record_schema;
152
      C4::Context->preference('marcflavour') eq 'UNIMARC'
152
    return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
153
}
154
155
=head3 record_schema
156
157
my $schema = $biblio->record_schema();
158
159
Returns the record schema (MARC21 or UNIMARCAUTH).
160
161
=cut
162
163
sub record_schema {
164
    my ( $self ) = @_;
165
166
    return C4::Context->preference('marcflavour') eq 'UNIMARC'
153
      ? 'UNIMARCAUTH'
167
      ? 'UNIMARCAUTH'
154
      : 'MARC21';
168
      : 'MARC21';
155
    return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
156
}
169
}
157
170
158
=head2 Class Methods
171
=head2 Class Methods
(-)a/Koha/Biblio.pm (+14 lines)
Lines 105-110 sub record { Link Here
105
    return $self->metadata->record;
105
    return $self->metadata->record;
106
}
106
}
107
107
108
=head3 record_schema
109
110
my $schema = $biblio->record_schema();
111
112
Returns the record schema (MARC21, USMARC or UNIMARC).
113
114
=cut
115
116
sub record_schema {
117
    my ( $self ) = @_;
118
119
    return $self->metadata->schema // C4::Context->preference("marcflavour");
120
}
121
108
=head3 orders
122
=head3 orders
109
123
110
my $orders = $biblio->orders();
124
my $orders = $biblio->orders();
(-)a/Koha/Objects/Record/Collections.pm (-3 / +6 lines)
Lines 84-93 sub print_collection { Link Here
84
        $end    = MARC::File::XML::footer();
84
        $end    = MARC::File::XML::footer();
85
    }
85
    }
86
    while ( my $element = $self->next ) {
86
    while ( my $element = $self->next ) {
87
        my $metadata = $element->metadata;
87
        my $schema = C4::Context->preference("marcflavour");
88
        MARC::File::XML->default_record_format( $metadata->schema // C4::Context->preference("marcflavour") )
88
        if ($element->can('record_schema')) {
89
            $schema = $element->record_schema;
90
        }
91
        MARC::File::XML->default_record_format( $schema )
89
          if $format eq 'marcxml';
92
          if $format eq 'marcxml';
90
        push @parts, $serializers{$format}->( $metadata->record );
93
        push @parts, $serializers{$format}->( $element->record );
91
    }
94
    }
92
    return
95
    return
93
        ( defined $start ? $start : '' )
96
        ( defined $start ? $start : '' )
(-)a/t/db_dependent/Biblio.t (-1 / +15 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 16;
20
use Test::More tests => 17;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
use List::MoreUtils qw( uniq );
23
use List::MoreUtils qw( uniq );
Lines 877-882 subtest 'record test' => sub { Link Here
877
        $biblio->metadata->record->as_formatted );
877
        $biblio->metadata->record->as_formatted );
878
};
878
};
879
879
880
subtest 'record_schema test' => sub {
881
    plan tests => 1;
882
883
    my $marc_record = MARC::Record->new;
884
    $marc_record->append_fields( create_isbn_field( '0590353403', 'MARC21' ) );
885
886
    my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record, '' );
887
888
    my $biblio = Koha::Biblios->find($biblionumber);
889
890
    is( $biblio->record_schema,
891
        $biblio->metadata->schema );
892
};
893
880
894
881
895
882
# Cleanup
896
# Cleanup
(-)a/t/db_dependent/Koha/Authorities.t (-2 / +15 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
use MARC::Field;
23
use MARC::Field;
24
use MARC::File::XML;
24
use MARC::File::XML;
25
use MARC::Record;
25
use MARC::Record;
Lines 321-324 subtest 'record tests' => sub { Link Here
321
321
322
};
322
};
323
323
324
subtest 'record_schema tests' => sub {
325
    plan tests => 2;
326
327
    my $authority = $builder->build_object({class => 'Koha::Authorities'});
328
329
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
330
331
    is($authority->record_schema, 'MARC21');
332
333
    t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
334
335
    is($authority->record_schema, 'UNIMARCAUTH');
336
};
337
324
$schema->storage->txn_rollback;
338
$schema->storage->txn_rollback;
325
- 

Return to bug 32735