Lines 34-39
use IO::File;
Link Here
|
34 |
use Pod::Usage; |
34 |
use Pod::Usage; |
35 |
|
35 |
|
36 |
use Koha::Biblios; |
36 |
use Koha::Biblios; |
|
|
37 |
use Koha::Holdings; |
37 |
use Koha::SearchEngine; |
38 |
use Koha::SearchEngine; |
38 |
use Koha::SearchEngine::Search; |
39 |
use Koha::SearchEngine::Search; |
39 |
|
40 |
|
Lines 41-47
use open qw( :std :encoding(UTF-8) );
Link Here
|
41 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
42 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
42 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
43 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
43 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
44 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
44 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append ); |
45 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings ); |
45 |
my $cleanisbn = 1; |
46 |
my $cleanisbn = 1; |
46 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
47 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
47 |
my $framework = ''; |
48 |
my $framework = ''; |
Lines 85-97
GetOptions(
Link Here
|
85 |
'framework=s' => \$framework, |
86 |
'framework=s' => \$framework, |
86 |
'custom:s' => \$localcust, |
87 |
'custom:s' => \$localcust, |
87 |
'marcmodtemplate:s' => \$marc_mod_template, |
88 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
89 |
'holdings' => \$import_holdings, |
88 |
); |
90 |
); |
89 |
$biblios ||= !$authorities; |
91 |
$biblios ||= !$authorities; |
90 |
$insert ||= !$update; |
92 |
$insert ||= !$update; |
91 |
my $writemode = ($append) ? "a" : "w"; |
93 |
my $writemode = ($append) ? "a" : "w"; |
|
|
94 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
92 |
|
95 |
|
93 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
96 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
94 |
|
97 |
|
|
|
98 |
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21'); |
99 |
|
95 |
if ($all) { |
100 |
if ($all) { |
96 |
$insert = 1; |
101 |
$insert = 1; |
97 |
$update = 1; |
102 |
$update = 1; |
Lines 168-179
if ($fk_off) {
Link Here
|
168 |
|
173 |
|
169 |
|
174 |
|
170 |
if ($delete) { |
175 |
if ($delete) { |
171 |
if ($biblios){ |
176 |
if ($biblios) { |
172 |
print "deleting biblios\n"; |
177 |
print "deleting biblios\n"; |
173 |
$dbh->do("DELETE FROM biblio"); |
178 |
$dbh->do("DELETE FROM biblio"); |
174 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
179 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
175 |
$dbh->do("DELETE FROM biblioitems"); |
180 |
$dbh->do("DELETE FROM biblioitems"); |
176 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
181 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
182 |
$dbh->do("DELETE FROM holdings"); |
183 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
177 |
$dbh->do("DELETE FROM items"); |
184 |
$dbh->do("DELETE FROM items"); |
178 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
185 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
179 |
} |
186 |
} |
Lines 229-234
if (defined $format && $format =~ /XML/i) {
Link Here
|
229 |
$batch->warnings_off(); |
236 |
$batch->warnings_off(); |
230 |
$batch->strict_off(); |
237 |
$batch->strict_off(); |
231 |
my $i=0; |
238 |
my $i=0; |
|
|
239 |
my $holdings_count = 0; |
232 |
my $commitnum = $commit ? $commit : 50; |
240 |
my $commitnum = $commit ? $commit : 50; |
233 |
my $yamlhash; |
241 |
my $yamlhash; |
234 |
|
242 |
|
Lines 258-263
if ($logfile){
Link Here
|
258 |
print $loghandle "id;operation;status\n"; |
266 |
print $loghandle "id;operation;status\n"; |
259 |
} |
267 |
} |
260 |
|
268 |
|
|
|
269 |
my $biblionumber; |
261 |
RECORD: while ( ) { |
270 |
RECORD: while ( ) { |
262 |
my $record; |
271 |
my $record; |
263 |
# get records |
272 |
# get records |
Lines 306-316
RECORD: while ( ) {
Link Here
|
306 |
$field->update('a' => $isbn); |
315 |
$field->update('a' => $isbn); |
307 |
} |
316 |
} |
308 |
} |
317 |
} |
|
|
318 |
|
319 |
# check for holdings records |
320 |
my $holdings_record = 0; |
321 |
if ($biblios && $marcFlavour eq 'MARC21') { |
322 |
my $leader = $record->leader(); |
323 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
324 |
} |
325 |
|
309 |
my $id; |
326 |
my $id; |
310 |
# search for duplicates (based on Local-number) |
327 |
# search for duplicates (based on Local-number) |
311 |
my $originalid; |
328 |
my $originalid; |
312 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
329 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
313 |
if ($match) { |
330 |
if ($match && !$holdings_record) { |
314 |
require C4::Search; |
331 |
require C4::Search; |
315 |
my $query = build_query( $match, $record ); |
332 |
my $query = build_query( $match, $record ); |
316 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
333 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 428-435
RECORD: while ( ) {
Link Here
|
428 |
$yamlhash->{$originalid}->{'updated'} = 1; |
445 |
$yamlhash->{$originalid}->{'updated'} = 1; |
429 |
} |
446 |
} |
430 |
} |
447 |
} |
|
|
448 |
elsif ($holdings_record) { |
449 |
if ($import_holdings) { |
450 |
if (!defined $biblionumber) { |
451 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
452 |
} else { |
453 |
if ($insert) { |
454 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
455 |
$holding->set_marc({ record => $record }); |
456 |
my $branchcode = $holding->holdingbranch(); |
457 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
458 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
459 |
} else { |
460 |
$holding->store(); |
461 |
++$holdings_count; |
462 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
463 |
} |
464 |
} else { |
465 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
466 |
} |
467 |
} |
468 |
} |
469 |
} |
431 |
else { |
470 |
else { |
432 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
471 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
433 |
$biblionumber = $id; |
472 |
$biblionumber = $id; |
434 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
473 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
435 |
if (!$biblionumber && $isbn_check && $isbn) { |
474 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 565-571
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
565 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
604 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
566 |
|
605 |
|
567 |
my $timeneeded = gettimeofday - $starttime; |
606 |
my $timeneeded = gettimeofday - $starttime; |
568 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
607 |
if ($import_holdings) { |
|
|
608 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
609 |
} else { |
610 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
611 |
} |
569 |
if ($logfile){ |
612 |
if ($logfile){ |
570 |
print $loghandle "file : $input_marc_file\n"; |
613 |
print $loghandle "file : $input_marc_file\n"; |
571 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
614 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 686-691
Type of import: authority records
Link Here
|
686 |
|
729 |
|
687 |
The I<FILE> to import |
730 |
The I<FILE> to import |
688 |
|
731 |
|
|
|
732 |
=item B<-holdings> |
733 |
|
734 |
Import MARC 21 holdings records when interleaved with bibliographic records |
735 |
(insert only, update not supported). Used only with -biblios. |
736 |
|
689 |
=item B<-v> |
737 |
=item B<-v> |
690 |
|
738 |
|
691 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
739 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 731-737
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
731 |
=item B<-d> |
779 |
=item B<-d> |
732 |
|
780 |
|
733 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
781 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
734 |
biblioitems, items |
782 |
biblioitems, items, holdings |
735 |
|
783 |
|
736 |
=item B<-m>=I<FORMAT> |
784 |
=item B<-m>=I<FORMAT> |
737 |
|
785 |
|