Bug 29333: Fix encoding of imported UNIMARC authorities
[koha.git] / Koha / Import / Record.pm
1 package Koha::Import::Record;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Carp;
21 use MARC::Record;
22
23 use C4::Context;
24 use Koha::Database;
25
26 use base qw(Koha::Object);
27
28 =head1 NAME
29
30 Koha::Import::Record - Koha Import Record Object class
31
32 =head1 API
33
34 =head2 Public methods
35
36 =head3 get_marc_record
37
38 Returns a MARC::Record object
39
40     my $marc_record = $import_record->get_marc_record({ embed_items => $embed_items })
41
42 If $embed_items is true then items from import_items are embedded into the
43 MARC::Record returned
44
45 =cut
46
47 sub get_marc_record {
48     my ($self, $args) = @_;
49
50     my $marcflavour = C4::Context->preference('marcflavour');
51
52     my $format = $marcflavour eq 'UNIMARC' ? 'UNIMARC' : 'USMARC';
53     if ($marcflavour eq 'UNIMARC' && $self->record_type eq 'auth') {
54         $format = 'UNIMARCAUTH';
55     }
56
57     my $record = MARC::Record->new_from_xml($self->marcxml, $self->encoding, $format);
58
59     if ($self->record_type eq 'biblio' && $args->{embed_items}) {
60         require C4::ImportBatch;
61         C4::ImportBatch::EmbedItemsInImportBiblio($record, $self->id);
62     }
63
64     return $record;
65 }
66
67 =head2 Internal methods
68
69 =head3 _type
70
71 Returns name of corresponding DBIC resultset
72
73 =cut
74
75 sub _type {
76     return 'ImportRecord';
77 }
78
79 1;