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 Import the record to replace an existing record which is passed to this sub
117 $import_record->replace({ biblio => $biblio_object });
122 my ($self, $params) = @_;
123 my $biblio = $params->{biblio};
124 my $authority = $params->{authority};
126 my $userenv = C4::Context->userenv;
127 my $logged_in_patron = Koha::Patrons->find( $userenv->{number} );
129 my $marc_record = $self->get_marc_record;
132 my $record = $biblio->metadata->record;
133 $xmlrecord = $record->as_xml;
134 my $context = { source => 'batchimport' };
135 if ($logged_in_patron) {
136 $context->{categorycode} = $logged_in_patron->categorycode;
137 $context->{userid} = $logged_in_patron->userid;
142 $biblio->frameworkcode,
144 overlay_context => $context,
145 skip_record_index => 1
148 $self->import_biblio->matched_biblionumber( $biblio->id )->store;
149 } elsif( $authority ) {
150 $xmlrecord = $authority->marcxml;
154 GuessAuthTypeCode($marc_record)
156 $self->import_auth->matched_authid( $authority->id )->store;
158 # We could also throw an exception
161 $self->marcxml_old( $xmlrecord );
162 $self->status('imported');
163 $self->overlay_status('match_applied');
169 =head2 Internal methods
173 Returns name of corresponding DBIC resultset
178 return 'ImportRecord';