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 169-180
if ($fk_off) {
Link Here
|
169 |
|
174 |
|
170 |
|
175 |
|
171 |
if ($delete) { |
176 |
if ($delete) { |
172 |
if ($biblios){ |
177 |
if ($biblios) { |
173 |
print "deleting biblios\n"; |
178 |
print "deleting biblios\n"; |
174 |
$dbh->do("DELETE FROM biblio"); |
179 |
$dbh->do("DELETE FROM biblio"); |
175 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
180 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
176 |
$dbh->do("DELETE FROM biblioitems"); |
181 |
$dbh->do("DELETE FROM biblioitems"); |
177 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
182 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
183 |
$dbh->do("DELETE FROM holdings"); |
184 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
178 |
$dbh->do("DELETE FROM items"); |
185 |
$dbh->do("DELETE FROM items"); |
179 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
186 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
180 |
} |
187 |
} |
Lines 230-235
if (defined $format && $format =~ /XML/i) {
Link Here
|
230 |
$batch->warnings_off(); |
237 |
$batch->warnings_off(); |
231 |
$batch->strict_off(); |
238 |
$batch->strict_off(); |
232 |
my $i=0; |
239 |
my $i=0; |
|
|
240 |
my $holdings_count = 0; |
233 |
my $commitnum = $commit ? $commit : 50; |
241 |
my $commitnum = $commit ? $commit : 50; |
234 |
my $yamlhash; |
242 |
my $yamlhash; |
235 |
|
243 |
|
Lines 259-264
if ($logfile){
Link Here
|
259 |
print $loghandle "id;operation;status\n"; |
267 |
print $loghandle "id;operation;status\n"; |
260 |
} |
268 |
} |
261 |
|
269 |
|
|
|
270 |
my $biblionumber; |
262 |
RECORD: while ( ) { |
271 |
RECORD: while ( ) { |
263 |
my $record; |
272 |
my $record; |
264 |
# get records |
273 |
# get records |
Lines 307-317
RECORD: while ( ) {
Link Here
|
307 |
$field->update('a' => $isbn); |
316 |
$field->update('a' => $isbn); |
308 |
} |
317 |
} |
309 |
} |
318 |
} |
|
|
319 |
|
320 |
# check for holdings records |
321 |
my $holdings_record = 0; |
322 |
if ($biblios && $marcFlavour eq 'MARC21') { |
323 |
my $leader = $record->leader(); |
324 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
325 |
} |
326 |
|
310 |
my $id; |
327 |
my $id; |
311 |
# search for duplicates (based on Local-number) |
328 |
# search for duplicates (based on Local-number) |
312 |
my $originalid; |
329 |
my $originalid; |
313 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
330 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
314 |
if ($match) { |
331 |
if ($match && !$holdings_record) { |
315 |
require C4::Search; |
332 |
require C4::Search; |
316 |
my $query = build_query( $match, $record ); |
333 |
my $query = build_query( $match, $record ); |
317 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
334 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 429-436
RECORD: while ( ) {
Link Here
|
429 |
$yamlhash->{$originalid}->{'updated'} = 1; |
446 |
$yamlhash->{$originalid}->{'updated'} = 1; |
430 |
} |
447 |
} |
431 |
} |
448 |
} |
|
|
449 |
elsif ($holdings_record) { |
450 |
if ($import_holdings) { |
451 |
if (!defined $biblionumber) { |
452 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
453 |
} else { |
454 |
if ($insert) { |
455 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
456 |
$holding->set_marc({ record => $record }); |
457 |
my $branchcode = $holding->holdingbranch(); |
458 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
459 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
460 |
} else { |
461 |
$holding->store(); |
462 |
++$holdings_count; |
463 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
464 |
} |
465 |
} else { |
466 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
467 |
} |
468 |
} |
469 |
} |
470 |
} |
432 |
else { |
471 |
else { |
433 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
472 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
434 |
$biblionumber = $id; |
473 |
$biblionumber = $id; |
435 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
474 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
436 |
if (!$biblionumber && $isbn_check && $isbn) { |
475 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 566-572
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
566 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
605 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
567 |
|
606 |
|
568 |
my $timeneeded = gettimeofday - $starttime; |
607 |
my $timeneeded = gettimeofday - $starttime; |
569 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
608 |
if ($import_holdings) { |
|
|
609 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
610 |
} else { |
611 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
612 |
} |
570 |
if ($logfile){ |
613 |
if ($logfile){ |
571 |
print $loghandle "file : $input_marc_file\n"; |
614 |
print $loghandle "file : $input_marc_file\n"; |
572 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
615 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 687-692
Type of import: authority records
Link Here
|
687 |
|
730 |
|
688 |
The I<FILE> to import |
731 |
The I<FILE> to import |
689 |
|
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 |
|
690 |
=item B<-v> |
738 |
=item B<-v> |
691 |
|
739 |
|
692 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
740 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 732-738
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
732 |
=item B<-d> |
780 |
=item B<-d> |
733 |
|
781 |
|
734 |
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, |
735 |
biblioitems, items |
783 |
biblioitems, items, holdings |
736 |
|
784 |
|
737 |
=item B<-m>=I<FORMAT> |
785 |
=item B<-m>=I<FORMAT> |
738 |
|
786 |
|