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 426-433
RECORD: while ( ) {
Link Here
|
426 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
443 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
427 |
} |
444 |
} |
428 |
} |
445 |
} |
|
|
446 |
elsif ($holdings_record) { |
447 |
if ($import_holdings) { |
448 |
if (!defined $biblionumber) { |
449 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
450 |
} else { |
451 |
if ($insert) { |
452 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
453 |
$holding->set_marc({ record => $record }); |
454 |
my $branchcode = $holding->holdingbranch(); |
455 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
456 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
457 |
} else { |
458 |
$holding->store(); |
459 |
++$holdings_count; |
460 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
461 |
} |
462 |
} else { |
463 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
464 |
} |
465 |
} |
466 |
} |
467 |
} |
429 |
else { |
468 |
else { |
430 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
469 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
431 |
$biblionumber = $id; |
470 |
$biblionumber = $id; |
432 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
471 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
433 |
if (!$biblionumber && $isbn_check && $isbn) { |
472 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 563-569
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
563 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
602 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
564 |
|
603 |
|
565 |
my $timeneeded = gettimeofday - $starttime; |
604 |
my $timeneeded = gettimeofday - $starttime; |
566 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
605 |
if ($import_holdings) { |
|
|
606 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
607 |
} else { |
608 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
609 |
} |
567 |
if ($logfile){ |
610 |
if ($logfile){ |
568 |
print $loghandle "file : $input_marc_file\n"; |
611 |
print $loghandle "file : $input_marc_file\n"; |
569 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
612 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 698-703
Type of import: authority records
Link Here
|
698 |
|
741 |
|
699 |
The I<FILE> to import |
742 |
The I<FILE> to import |
700 |
|
743 |
|
|
|
744 |
=item B<-holdings> |
745 |
|
746 |
Import MARC 21 holdings records when interleaved with bibliographic records |
747 |
(insert only, update not supported). Used only with -biblios. |
748 |
|
701 |
=item B<-v> |
749 |
=item B<-v> |
702 |
|
750 |
|
703 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
751 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 743-749
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
743 |
=item B<-d> |
791 |
=item B<-d> |
744 |
|
792 |
|
745 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
793 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
746 |
biblioitems, items |
794 |
biblioitems, items, holdings |
747 |
|
795 |
|
748 |
=item B<-m>=I<FORMAT> |
796 |
=item B<-m>=I<FORMAT> |
749 |
|
797 |
|