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 175-186
if ($fk_off) {
Link Here
|
175 |
|
180 |
|
176 |
|
181 |
|
177 |
if ($delete) { |
182 |
if ($delete) { |
178 |
if ($biblios){ |
183 |
if ($biblios) { |
179 |
print "deleting biblios\n"; |
184 |
print "deleting biblios\n"; |
180 |
$dbh->do("DELETE FROM biblio"); |
185 |
$dbh->do("DELETE FROM biblio"); |
181 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
186 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
182 |
$dbh->do("DELETE FROM biblioitems"); |
187 |
$dbh->do("DELETE FROM biblioitems"); |
183 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
188 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
189 |
$dbh->do("DELETE FROM holdings"); |
190 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
184 |
$dbh->do("DELETE FROM items"); |
191 |
$dbh->do("DELETE FROM items"); |
185 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
192 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
186 |
} |
193 |
} |
Lines 197-204
if ($test_parameter) {
Link Here
|
197 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
204 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
198 |
} |
205 |
} |
199 |
|
206 |
|
200 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
201 |
|
202 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
207 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
203 |
my $starttime = gettimeofday; |
208 |
my $starttime = gettimeofday; |
204 |
my $batch; |
209 |
my $batch; |
Lines 225-230
if (defined $format && $format =~ /XML/i) {
Link Here
|
225 |
$batch->warnings_off(); |
230 |
$batch->warnings_off(); |
226 |
$batch->strict_off(); |
231 |
$batch->strict_off(); |
227 |
my $i=0; |
232 |
my $i=0; |
|
|
233 |
my $holdings_count = 0; |
228 |
my $commitnum = $commit ? $commit : 50; |
234 |
my $commitnum = $commit ? $commit : 50; |
229 |
my $yamlhash; |
235 |
my $yamlhash; |
230 |
|
236 |
|
Lines 264-269
my $searcher = Koha::SearchEngine::Search->new(
Link Here
|
264 |
} |
270 |
} |
265 |
); |
271 |
); |
266 |
|
272 |
|
|
|
273 |
my $biblionumber; |
267 |
RECORD: while ( ) { |
274 |
RECORD: while ( ) { |
268 |
my $record; |
275 |
my $record; |
269 |
# get records |
276 |
# get records |
Lines 312-322
RECORD: while ( ) {
Link Here
|
312 |
$field->update('a' => $isbn); |
319 |
$field->update('a' => $isbn); |
313 |
} |
320 |
} |
314 |
} |
321 |
} |
|
|
322 |
|
323 |
# check for holdings records |
324 |
my $holdings_record = 0; |
325 |
if ($biblios && $marcFlavour eq 'MARC21') { |
326 |
my $leader = $record->leader(); |
327 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
328 |
} |
329 |
|
315 |
my $id; |
330 |
my $id; |
316 |
# search for duplicates (based on Local-number) |
331 |
# search for duplicates (based on Local-number) |
317 |
my $originalid; |
332 |
my $originalid; |
318 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
333 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
319 |
if ($match) { |
334 |
if ($match && !$holdings_record) { |
320 |
require C4::Search; |
335 |
require C4::Search; |
321 |
my $query = build_query( $match, $record ); |
336 |
my $query = build_query( $match, $record ); |
322 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
337 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 432-439
RECORD: while ( ) {
Link Here
|
432 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
447 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
433 |
} |
448 |
} |
434 |
} |
449 |
} |
|
|
450 |
elsif ($holdings_record) { |
451 |
if ($import_holdings) { |
452 |
if (!defined $biblionumber) { |
453 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
454 |
} else { |
455 |
if ($insert) { |
456 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
457 |
$holding->set_marc({ record => $record }); |
458 |
my $branchcode = $holding->holdingbranch(); |
459 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
460 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
461 |
} else { |
462 |
$holding->store(); |
463 |
++$holdings_count; |
464 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
465 |
} |
466 |
} else { |
467 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
468 |
} |
469 |
} |
470 |
} |
471 |
} |
435 |
else { |
472 |
else { |
436 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
473 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
437 |
$biblionumber = $id; |
474 |
$biblionumber = $id; |
438 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
475 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
439 |
if (!$biblionumber && $isbn_check && $isbn) { |
476 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 570-576
C4::Context->set_preference( 'CataloguingLog', $CataloguingLog );
Link Here
|
570 |
C4::Context->set_preference( 'AuthoritiesLog', $AuthoritiesLog ); |
607 |
C4::Context->set_preference( 'AuthoritiesLog', $AuthoritiesLog ); |
571 |
|
608 |
|
572 |
my $timeneeded = gettimeofday - $starttime; |
609 |
my $timeneeded = gettimeofday - $starttime; |
573 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
610 |
if ($import_holdings) { |
|
|
611 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
612 |
} else { |
613 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
614 |
} |
574 |
if ($logfile){ |
615 |
if ($logfile){ |
575 |
print $loghandle "file : $input_marc_file\n"; |
616 |
print $loghandle "file : $input_marc_file\n"; |
576 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
617 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 705-710
Type of import: authority records
Link Here
|
705 |
|
746 |
|
706 |
The I<FILE> to import |
747 |
The I<FILE> to import |
707 |
|
748 |
|
|
|
749 |
=item B<-holdings> |
750 |
|
751 |
Import MARC 21 holdings records when interleaved with bibliographic records |
752 |
(insert only, update not supported). Used only with -biblios. |
753 |
|
708 |
=item B<-v> |
754 |
=item B<-v> |
709 |
|
755 |
|
710 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
756 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 750-756
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
750 |
=item B<-d> |
796 |
=item B<-d> |
751 |
|
797 |
|
752 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
798 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
753 |
biblioitems, items |
799 |
biblioitems, items, holdings |
754 |
|
800 |
|
755 |
=item B<-m>=I<FORMAT> |
801 |
=item B<-m>=I<FORMAT> |
756 |
|
802 |
|