Lines 24-29
use C4::Debug;
Link Here
|
24 |
use C4::Charset; |
24 |
use C4::Charset; |
25 |
use C4::Items; |
25 |
use C4::Items; |
26 |
use C4::MarcModificationTemplates; |
26 |
use C4::MarcModificationTemplates; |
|
|
27 |
use C4::Holdings; |
27 |
|
28 |
|
28 |
use YAML; |
29 |
use YAML; |
29 |
use Unicode::Normalize; |
30 |
use Unicode::Normalize; |
Lines 40-46
use open qw( :std :encoding(UTF-8) );
Link Here
|
40 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
41 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
41 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
42 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
42 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
43 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
43 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append ); |
44 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings ); |
44 |
my $cleanisbn = 1; |
45 |
my $cleanisbn = 1; |
45 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
46 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
46 |
my $framework = ''; |
47 |
my $framework = ''; |
Lines 84-96
GetOptions(
Link Here
|
84 |
'framework=s' => \$framework, |
85 |
'framework=s' => \$framework, |
85 |
'custom:s' => \$localcust, |
86 |
'custom:s' => \$localcust, |
86 |
'marcmodtemplate:s' => \$marc_mod_template, |
87 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
88 |
'holdings' => \$import_holdings, |
87 |
); |
89 |
); |
88 |
$biblios ||= !$authorities; |
90 |
$biblios ||= !$authorities; |
89 |
$insert ||= !$update; |
91 |
$insert ||= !$update; |
90 |
my $writemode = ($append) ? "a" : "w"; |
92 |
my $writemode = ($append) ? "a" : "w"; |
|
|
93 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
91 |
|
94 |
|
92 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
95 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
93 |
|
96 |
|
|
|
97 |
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21'); |
98 |
|
94 |
if ($all) { |
99 |
if ($all) { |
95 |
$insert = 1; |
100 |
$insert = 1; |
96 |
$update = 1; |
101 |
$update = 1; |
Lines 173-178
if ($fk_off) {
Link Here
|
173 |
if ($delete) { |
178 |
if ($delete) { |
174 |
if ($biblios){ |
179 |
if ($biblios){ |
175 |
print "deleting biblios\n"; |
180 |
print "deleting biblios\n"; |
|
|
181 |
$dbh->do("truncate holdings"); |
176 |
$dbh->do("truncate biblio"); |
182 |
$dbh->do("truncate biblio"); |
177 |
$dbh->do("truncate biblioitems"); |
183 |
$dbh->do("truncate biblioitems"); |
178 |
$dbh->do("truncate items"); |
184 |
$dbh->do("truncate items"); |
Lines 190-197
if ($test_parameter) {
Link Here
|
190 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
196 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
191 |
} |
197 |
} |
192 |
|
198 |
|
193 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
194 |
|
195 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
199 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
196 |
my $starttime = gettimeofday; |
200 |
my $starttime = gettimeofday; |
197 |
my $batch; |
201 |
my $batch; |
Lines 257-262
my $searcher = Koha::SearchEngine::Search->new(
Link Here
|
257 |
} |
261 |
} |
258 |
); |
262 |
); |
259 |
|
263 |
|
|
|
264 |
my $biblionumber; |
260 |
RECORD: while ( ) { |
265 |
RECORD: while ( ) { |
261 |
my $record; |
266 |
my $record; |
262 |
# get records |
267 |
# get records |
Lines 305-315
RECORD: while ( ) {
Link Here
|
305 |
$field->update('a' => $isbn); |
310 |
$field->update('a' => $isbn); |
306 |
} |
311 |
} |
307 |
} |
312 |
} |
|
|
313 |
|
314 |
# check for holdings records |
315 |
my $holdings_record = 0; |
316 |
if ($biblios && $marcFlavour eq 'MARC21') { |
317 |
my $leader = $record->leader(); |
318 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
319 |
} |
320 |
|
308 |
my $id; |
321 |
my $id; |
309 |
# search for duplicates (based on Local-number) |
322 |
# search for duplicates (based on Local-number) |
310 |
my $originalid; |
323 |
my $originalid; |
311 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
324 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
312 |
if ($match) { |
325 |
if ($match && !$holdings_record) { |
313 |
require C4::Search; |
326 |
require C4::Search; |
314 |
my $query = build_query( $match, $record ); |
327 |
my $query = build_query( $match, $record ); |
315 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
328 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 425-432
RECORD: while ( ) {
Link Here
|
425 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
438 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
426 |
} |
439 |
} |
427 |
} |
440 |
} |
|
|
441 |
elsif ($holdings_record) { |
442 |
if ($import_holdings) { |
443 |
if (!defined $biblionumber) { |
444 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
445 |
} else { |
446 |
if ($insert) { |
447 |
my $holdings_id = 0; |
448 |
eval { ( $holdings_id ) = AddHolding( $record, '', $biblionumber ) }; |
449 |
if ($@) { |
450 |
warn "ERROR: Adding holdings record $holdings_id for biblio $biblionumber failed: $@\n"; |
451 |
printlog( { $holdings_id, op => "insert", status => "ERROR" } ) if ($logfile); |
452 |
next RECORD; |
453 |
} else { |
454 |
printlog( { $holdings_id, op => "insert", status => "ok" } ) if ($logfile); |
455 |
} |
456 |
} else { |
457 |
printlog( { 0, op => "update", status => "warning : not in database" } ) if ($logfile); |
458 |
} |
459 |
} |
460 |
} |
461 |
} |
428 |
else { |
462 |
else { |
429 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
463 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
430 |
$biblionumber = $id; |
464 |
$biblionumber = $id; |
431 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
465 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
432 |
if (!$biblionumber && $isbn_check && $isbn) { |
466 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 696-701
Type of import: authority records
Link Here
|
696 |
|
730 |
|
697 |
The I<FILE> to import |
731 |
The I<FILE> to import |
698 |
|
732 |
|
|
|
733 |
=item B<-holdings> |
734 |
|
735 |
Import MARC 21 holdings records when interleaved with bibliographic records |
736 |
(insert only, update not supported). Used only with -biblios. |
737 |
|
699 |
=item B<-v> |
738 |
=item B<-v> |
700 |
|
739 |
|
701 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
740 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 741-747
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
741 |
=item B<-d> |
780 |
=item B<-d> |
742 |
|
781 |
|
743 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
782 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
744 |
biblioitems, items |
783 |
biblioitems, items, holdings |
745 |
|
784 |
|
746 |
=item B<-m>=I<FORMAT> |
785 |
=item B<-m>=I<FORMAT> |
747 |
|
786 |
|