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 176-181
if ($fk_off) {
Link Here
|
176 |
if ($delete) { |
181 |
if ($delete) { |
177 |
if ($biblios){ |
182 |
if ($biblios){ |
178 |
print "deleting biblios\n"; |
183 |
print "deleting biblios\n"; |
|
|
184 |
$dbh->do("truncate holdings"); |
179 |
$dbh->do("truncate biblio"); |
185 |
$dbh->do("truncate biblio"); |
180 |
$dbh->do("truncate biblioitems"); |
186 |
$dbh->do("truncate biblioitems"); |
181 |
$dbh->do("truncate items"); |
187 |
$dbh->do("truncate items"); |
Lines 193-200
if ($test_parameter) {
Link Here
|
193 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
199 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
194 |
} |
200 |
} |
195 |
|
201 |
|
196 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
197 |
|
198 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
202 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
199 |
my $starttime = gettimeofday; |
203 |
my $starttime = gettimeofday; |
200 |
my $batch; |
204 |
my $batch; |
Lines 260-265
my $searcher = Koha::SearchEngine::Search->new(
Link Here
|
260 |
} |
264 |
} |
261 |
); |
265 |
); |
262 |
|
266 |
|
|
|
267 |
my $biblionumber; |
263 |
RECORD: while ( ) { |
268 |
RECORD: while ( ) { |
264 |
my $record; |
269 |
my $record; |
265 |
# get records |
270 |
# get records |
Lines 308-318
RECORD: while ( ) {
Link Here
|
308 |
$field->update('a' => $isbn); |
313 |
$field->update('a' => $isbn); |
309 |
} |
314 |
} |
310 |
} |
315 |
} |
|
|
316 |
|
317 |
# check for holdings records |
318 |
my $holdings_record = 0; |
319 |
if ($biblios && $marcFlavour eq 'MARC21') { |
320 |
my $leader = $record->leader(); |
321 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
322 |
} |
323 |
|
311 |
my $id; |
324 |
my $id; |
312 |
# search for duplicates (based on Local-number) |
325 |
# search for duplicates (based on Local-number) |
313 |
my $originalid; |
326 |
my $originalid; |
314 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
327 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
315 |
if ($match) { |
328 |
if ($match && !$holdings_record) { |
316 |
require C4::Search; |
329 |
require C4::Search; |
317 |
my $query = build_query( $match, $record ); |
330 |
my $query = build_query( $match, $record ); |
318 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
331 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 428-435
RECORD: while ( ) {
Link Here
|
428 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
441 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
429 |
} |
442 |
} |
430 |
} |
443 |
} |
|
|
444 |
elsif ($holdings_record) { |
445 |
if ($import_holdings) { |
446 |
if (!defined $biblionumber) { |
447 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
448 |
} else { |
449 |
if ($insert) { |
450 |
my $holdings_id = 0; |
451 |
eval { ( $holdings_id ) = AddHolding( $record, '', $biblionumber ) }; |
452 |
if ($@) { |
453 |
warn "ERROR: Adding holdings record $holdings_id for biblio $biblionumber failed: $@\n"; |
454 |
printlog( { $holdings_id, op => "insert", status => "ERROR" } ) if ($logfile); |
455 |
next RECORD; |
456 |
} else { |
457 |
printlog( { $holdings_id, op => "insert", status => "ok" } ) if ($logfile); |
458 |
} |
459 |
} else { |
460 |
printlog( { 0, op => "update", status => "warning : not in database" } ) if ($logfile); |
461 |
} |
462 |
} |
463 |
} |
464 |
} |
431 |
else { |
465 |
else { |
432 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
466 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
433 |
$biblionumber = $id; |
467 |
$biblionumber = $id; |
434 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
468 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
435 |
if (!$biblionumber && $isbn_check && $isbn) { |
469 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 701-706
Type of import: authority records
Link Here
|
701 |
|
735 |
|
702 |
The I<FILE> to import |
736 |
The I<FILE> to import |
703 |
|
737 |
|
|
|
738 |
=item B<-holdings> |
739 |
|
740 |
Import MARC 21 holdings records when interleaved with bibliographic records |
741 |
(insert only, update not supported). Used only with -biblios. |
742 |
|
704 |
=item B<-v> |
743 |
=item B<-v> |
705 |
|
744 |
|
706 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
745 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 746-752
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
746 |
=item B<-d> |
785 |
=item B<-d> |
747 |
|
786 |
|
748 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
787 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
749 |
biblioitems, items |
788 |
biblioitems, items, holdings |
750 |
|
789 |
|
751 |
=item B<-m>=I<FORMAT> |
790 |
=item B<-m>=I<FORMAT> |
752 |
|
791 |
|