|
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 191-198
if ($test_parameter) {
Link Here
|
| 191 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
198 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
| 192 |
} |
199 |
} |
| 193 |
|
200 |
|
| 194 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
| 195 |
|
| 196 |
# The definition of $searcher must be before MARC::Batch->new |
201 |
# The definition of $searcher must be before MARC::Batch->new |
| 197 |
my $searcher = Koha::SearchEngine::Search->new( |
202 |
my $searcher = Koha::SearchEngine::Search->new( |
| 198 |
{ |
203 |
{ |
|
Lines 230-235
if (defined $format && $format =~ /XML/i) {
Link Here
|
| 230 |
$batch->warnings_off(); |
235 |
$batch->warnings_off(); |
| 231 |
$batch->strict_off(); |
236 |
$batch->strict_off(); |
| 232 |
my $i=0; |
237 |
my $i=0; |
|
|
238 |
my $holdings_count = 0; |
| 233 |
my $commitnum = $commit ? $commit : 50; |
239 |
my $commitnum = $commit ? $commit : 50; |
| 234 |
my $yamlhash; |
240 |
my $yamlhash; |
| 235 |
|
241 |
|
|
Lines 259-264
if ($logfile){
Link Here
|
| 259 |
print $loghandle "id;operation;status\n"; |
265 |
print $loghandle "id;operation;status\n"; |
| 260 |
} |
266 |
} |
| 261 |
|
267 |
|
|
|
268 |
my $biblionumber; |
| 262 |
RECORD: while ( ) { |
269 |
RECORD: while ( ) { |
| 263 |
my $record; |
270 |
my $record; |
| 264 |
# get records |
271 |
# get records |
|
Lines 307-317
RECORD: while ( ) {
Link Here
|
| 307 |
$field->update('a' => $isbn); |
314 |
$field->update('a' => $isbn); |
| 308 |
} |
315 |
} |
| 309 |
} |
316 |
} |
|
|
317 |
|
| 318 |
# check for holdings records |
| 319 |
my $holdings_record = 0; |
| 320 |
if ($biblios && $marcFlavour eq 'MARC21') { |
| 321 |
my $leader = $record->leader(); |
| 322 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
| 323 |
} |
| 324 |
|
| 310 |
my $id; |
325 |
my $id; |
| 311 |
# search for duplicates (based on Local-number) |
326 |
# search for duplicates (based on Local-number) |
| 312 |
my $originalid; |
327 |
my $originalid; |
| 313 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
328 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
| 314 |
if ($match) { |
329 |
if ($match && !$holdings_record) { |
| 315 |
require C4::Search; |
330 |
require C4::Search; |
| 316 |
my $query = build_query( $match, $record ); |
331 |
my $query = build_query( $match, $record ); |
| 317 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
332 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
|
Lines 418-425
RECORD: while ( ) {
Link Here
|
| 418 |
$yamlhash->{$originalid}->{'updated'} = 1; |
433 |
$yamlhash->{$originalid}->{'updated'} = 1; |
| 419 |
} |
434 |
} |
| 420 |
} |
435 |
} |
|
|
436 |
elsif ($holdings_record) { |
| 437 |
if ($import_holdings) { |
| 438 |
if (!defined $biblionumber) { |
| 439 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
| 440 |
} else { |
| 441 |
if ($insert) { |
| 442 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
| 443 |
$holding->set_marc({ record => $record }); |
| 444 |
my $branchcode = $holding->holdingbranch(); |
| 445 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
| 446 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
| 447 |
} else { |
| 448 |
$holding->store(); |
| 449 |
++$holdings_count; |
| 450 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
| 451 |
} |
| 452 |
} else { |
| 453 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
} |
| 421 |
else { |
458 |
else { |
| 422 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
459 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
| 423 |
$biblionumber = $id; |
460 |
$biblionumber = $id; |
| 424 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
461 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
| 425 |
if (!$biblionumber && $isbn_check && $isbn) { |
462 |
if (!$biblionumber && $isbn_check && $isbn) { |
|
Lines 555-561
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
| 555 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
592 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
| 556 |
|
593 |
|
| 557 |
my $timeneeded = gettimeofday - $starttime; |
594 |
my $timeneeded = gettimeofday - $starttime; |
| 558 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
595 |
if ($import_holdings) { |
|
|
596 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
| 597 |
} else { |
| 598 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
| 599 |
} |
| 559 |
if ($logfile){ |
600 |
if ($logfile){ |
| 560 |
print $loghandle "file : $input_marc_file\n"; |
601 |
print $loghandle "file : $input_marc_file\n"; |
| 561 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
602 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
|
Lines 676-681
Type of import: authority records
Link Here
|
| 676 |
|
717 |
|
| 677 |
The I<FILE> to import |
718 |
The I<FILE> to import |
| 678 |
|
719 |
|
|
|
720 |
=item B<-holdings> |
| 721 |
|
| 722 |
Import MARC 21 holdings records when interleaved with bibliographic records |
| 723 |
(insert only, update not supported). Used only with -biblios. |
| 724 |
|
| 679 |
=item B<-v> |
725 |
=item B<-v> |
| 680 |
|
726 |
|
| 681 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
727 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
|
Lines 721-727
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
| 721 |
=item B<-d> |
767 |
=item B<-d> |
| 722 |
|
768 |
|
| 723 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
769 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
| 724 |
biblioitems, items |
770 |
biblioitems, items, holdings |
| 725 |
|
771 |
|
| 726 |
=item B<-m>=I<FORMAT> |
772 |
=item B<-m>=I<FORMAT> |
| 727 |
|
773 |
|