Lines 33-38
use IO::File;
Link Here
|
33 |
use Pod::Usage; |
33 |
use Pod::Usage; |
34 |
|
34 |
|
35 |
use Koha::Biblios; |
35 |
use Koha::Biblios; |
|
|
36 |
use Koha::Holdings; |
36 |
use Koha::SearchEngine; |
37 |
use Koha::SearchEngine; |
37 |
use Koha::SearchEngine::Search; |
38 |
use Koha::SearchEngine::Search; |
38 |
|
39 |
|
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 174-185
if ($fk_off) {
Link Here
|
174 |
|
179 |
|
175 |
|
180 |
|
176 |
if ($delete) { |
181 |
if ($delete) { |
177 |
if ($biblios){ |
182 |
if ($biblios) { |
178 |
print "deleting biblios\n"; |
183 |
print "deleting biblios\n"; |
179 |
$dbh->do("DELETE FROM biblio"); |
184 |
$dbh->do("DELETE FROM biblio"); |
180 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
185 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
181 |
$dbh->do("DELETE FROM biblioitems"); |
186 |
$dbh->do("DELETE FROM biblioitems"); |
182 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
187 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
188 |
$dbh->do("DELETE FROM holdings"); |
189 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
183 |
$dbh->do("DELETE FROM items"); |
190 |
$dbh->do("DELETE FROM items"); |
184 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
191 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
185 |
} |
192 |
} |
Lines 196-203
if ($test_parameter) {
Link Here
|
196 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
203 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
197 |
} |
204 |
} |
198 |
|
205 |
|
199 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
200 |
|
201 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
206 |
print "Characteristic MARC flavour: $marcFlavour\n" if $verbose; |
202 |
my $starttime = gettimeofday; |
207 |
my $starttime = gettimeofday; |
203 |
my $batch; |
208 |
my $batch; |
Lines 224-229
if (defined $format && $format =~ /XML/i) {
Link Here
|
224 |
$batch->warnings_off(); |
229 |
$batch->warnings_off(); |
225 |
$batch->strict_off(); |
230 |
$batch->strict_off(); |
226 |
my $i=0; |
231 |
my $i=0; |
|
|
232 |
my $holdings_count = 0; |
227 |
my $commitnum = $commit ? $commit : 50; |
233 |
my $commitnum = $commit ? $commit : 50; |
228 |
my $yamlhash; |
234 |
my $yamlhash; |
229 |
|
235 |
|
Lines 263-268
my $searcher = Koha::SearchEngine::Search->new(
Link Here
|
263 |
} |
269 |
} |
264 |
); |
270 |
); |
265 |
|
271 |
|
|
|
272 |
my $biblionumber; |
266 |
RECORD: while ( ) { |
273 |
RECORD: while ( ) { |
267 |
my $record; |
274 |
my $record; |
268 |
# get records |
275 |
# get records |
Lines 311-321
RECORD: while ( ) {
Link Here
|
311 |
$field->update('a' => $isbn); |
318 |
$field->update('a' => $isbn); |
312 |
} |
319 |
} |
313 |
} |
320 |
} |
|
|
321 |
|
322 |
# check for holdings records |
323 |
my $holdings_record = 0; |
324 |
if ($biblios && $marcFlavour eq 'MARC21') { |
325 |
my $leader = $record->leader(); |
326 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
327 |
} |
328 |
|
314 |
my $id; |
329 |
my $id; |
315 |
# search for duplicates (based on Local-number) |
330 |
# search for duplicates (based on Local-number) |
316 |
my $originalid; |
331 |
my $originalid; |
317 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
332 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
318 |
if ($match) { |
333 |
if ($match && !$holdings_record) { |
319 |
require C4::Search; |
334 |
require C4::Search; |
320 |
my $query = build_query( $match, $record ); |
335 |
my $query = build_query( $match, $record ); |
321 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
336 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 431-438
RECORD: while ( ) {
Link Here
|
431 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
446 |
$yamlhash->{$originalid}->{'subfields'} = \@subfields; |
432 |
} |
447 |
} |
433 |
} |
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 |
} |
434 |
else { |
471 |
else { |
435 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
472 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
436 |
$biblionumber = $id; |
473 |
$biblionumber = $id; |
437 |
# 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 |
438 |
if (!$biblionumber && $isbn_check && $isbn) { |
475 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 569-575
C4::Context->set_preference( 'CataloguingLog', $CataloguingLog );
Link Here
|
569 |
C4::Context->set_preference( 'AuthoritiesLog', $AuthoritiesLog ); |
606 |
C4::Context->set_preference( 'AuthoritiesLog', $AuthoritiesLog ); |
570 |
|
607 |
|
571 |
my $timeneeded = gettimeofday - $starttime; |
608 |
my $timeneeded = gettimeofday - $starttime; |
572 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
609 |
if ($import_holdings) { |
|
|
610 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
611 |
} else { |
612 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
613 |
} |
573 |
if ($logfile){ |
614 |
if ($logfile){ |
574 |
print $loghandle "file : $input_marc_file\n"; |
615 |
print $loghandle "file : $input_marc_file\n"; |
575 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
616 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 704-709
Type of import: authority records
Link Here
|
704 |
|
745 |
|
705 |
The I<FILE> to import |
746 |
The I<FILE> to import |
706 |
|
747 |
|
|
|
748 |
=item B<-holdings> |
749 |
|
750 |
Import MARC 21 holdings records when interleaved with bibliographic records |
751 |
(insert only, update not supported). Used only with -biblios. |
752 |
|
707 |
=item B<-v> |
753 |
=item B<-v> |
708 |
|
754 |
|
709 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
755 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 749-755
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
749 |
=item B<-d> |
795 |
=item B<-d> |
750 |
|
796 |
|
751 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
797 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
752 |
biblioitems, items |
798 |
biblioitems, items, holdings |
753 |
|
799 |
|
754 |
=item B<-m>=I<FORMAT> |
800 |
=item B<-m>=I<FORMAT> |
755 |
|
801 |
|