1 package Koha::Import::Record;
3 # This file is part of Koha.
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.
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.
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>.
24 use C4::Biblio qw(ModBiblio);
25 use C4::AuthoritiesMarc qw(GuessAuthTypeCode ModAuthority);
27 use Koha::Import::Record::Biblios;
28 use Koha::Import::Record::Auths;
29 use Koha::Import::Record::Matches;
31 use base qw(Koha::Object);
35 Koha::Import::Record - Koha Import Record Object class
41 =head3 get_marc_record
43 Returns a MARC::Record object
45 my $marc_record = $import_record->get_marc_record()
52 my $marcflavour = C4::Context->preference('marcflavour');
54 my $format = $marcflavour eq 'UNIMARC' ? 'UNIMARC' : 'USMARC';
55 if ($marcflavour eq 'UNIMARC' && $self->record_type eq 'auth') {
56 $format = 'UNIMARCAUTH';
59 my $record = MARC::Record->new_from_xml($self->marcxml, $self->encoding, $format);
66 Returns the import biblio object for this import record
68 my $import_biblio = $import_record->import_biblio()
74 my $import_biblio_rs = $self->_result->import_biblio;
75 return Koha::Import::Record::Biblio->_new_from_dbic( $import_biblio_rs );
80 Returns the import auth object for this import record
82 my $import_auth = $import_record->import_auth()
88 my $import_auth_rs = $self->_result->import_auth;
89 return Koha::Import::Record::Auth->_new_from_dbic( $import_auth_rs );
92 =head3 get_import_record_matches
94 Returns the Import::Record::Matches for the record
95 optionally specify a 'chosen' param to get only the chosen match
97 my $matches = $import_record->get_import_record_matches([{ chosen => 1 }])
101 sub get_import_record_matches {
102 my ($self, $params) = @_;
103 my $chosen = $params->{chosen};
105 my $matches = $self->_result->import_record_matches;
106 $matches = Koha::Import::Record::Matches->_new_from_dbic( $matches );
108 return $matches->filter_by_chosen() if $chosen;
110 return $matches->search({},{ order_by => { -desc => ['score','candidate_match_id'] } });
115 Replace an existing record ($auth or $biblio) with the import record.
117 $import_record->replace({ biblio => $biblio | authority => $auth });
118 # where $biblio and $auth are Koha objects
123 my ($self, $params) = @_;
124 my $biblio = $params->{biblio};
125 my $authority = $params->{authority};
127 my $userenv = C4::Context->userenv;
128 my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
130 my $marc_record = $self->get_marc_record;
133 my $record = $biblio->metadata->record;
134 $xmlrecord = $record->as_xml;
135 my $context = { source => 'batchimport' };
136 if ($logged_in_patron) {
137 $context->{categorycode} = $logged_in_patron->categorycode;
138 $context->{userid} = $logged_in_patron->userid;
143 $biblio->frameworkcode,
145 overlay_context => $context,
146 skip_record_index => 1
149 $self->import_biblio->matched_biblionumber( $biblio->id )->store;
150 } elsif( $authority ) {
151 $xmlrecord = $authority->marcxml;
155 GuessAuthTypeCode($marc_record)
157 $self->import_auth->matched_authid( $authority->id )->store;
159 # We could also throw an exception
162 $self->marcxml_old( $xmlrecord );
163 $self->status('imported');
164 $self->overlay_status('match_applied');
170 =head2 Internal methods
174 Returns name of corresponding DBIC resultset
179 return 'ImportRecord';