Lines 35-40
use IO::File;
Link Here
|
35 |
use Pod::Usage; |
35 |
use Pod::Usage; |
36 |
|
36 |
|
37 |
use Koha::Biblios; |
37 |
use Koha::Biblios; |
|
|
38 |
use Koha::Holdings; |
38 |
use Koha::SearchEngine; |
39 |
use Koha::SearchEngine; |
39 |
use Koha::SearchEngine::Search; |
40 |
use Koha::SearchEngine::Search; |
40 |
|
41 |
|
Lines 42-48
use open qw( :std :encoding(UTF-8) );
Link Here
|
42 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
43 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
43 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
44 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
44 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
45 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
45 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append ); |
46 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings ); |
46 |
my $cleanisbn = 1; |
47 |
my $cleanisbn = 1; |
47 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
48 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
48 |
my $framework = ''; |
49 |
my $framework = ''; |
Lines 86-98
GetOptions(
Link Here
|
86 |
'framework=s' => \$framework, |
87 |
'framework=s' => \$framework, |
87 |
'custom:s' => \$localcust, |
88 |
'custom:s' => \$localcust, |
88 |
'marcmodtemplate:s' => \$marc_mod_template, |
89 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
90 |
'holdings' => \$import_holdings, |
89 |
); |
91 |
); |
90 |
$biblios ||= !$authorities; |
92 |
$biblios ||= !$authorities; |
91 |
$insert ||= !$update; |
93 |
$insert ||= !$update; |
92 |
my $writemode = ($append) ? "a" : "w"; |
94 |
my $writemode = ($append) ? "a" : "w"; |
|
|
95 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
93 |
|
96 |
|
94 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
97 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
95 |
|
98 |
|
|
|
99 |
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21'); |
100 |
|
96 |
if ($all) { |
101 |
if ($all) { |
97 |
$insert = 1; |
102 |
$insert = 1; |
98 |
$update = 1; |
103 |
$update = 1; |
Lines 170-181
if ($fk_off) {
Link Here
|
170 |
|
175 |
|
171 |
|
176 |
|
172 |
if ($delete) { |
177 |
if ($delete) { |
173 |
if ($biblios){ |
178 |
if ($biblios) { |
174 |
print "deleting biblios\n"; |
179 |
print "deleting biblios\n"; |
175 |
$dbh->do("DELETE FROM biblio"); |
180 |
$dbh->do("DELETE FROM biblio"); |
176 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
181 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
177 |
$dbh->do("DELETE FROM biblioitems"); |
182 |
$dbh->do("DELETE FROM biblioitems"); |
178 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
183 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
184 |
$dbh->do("DELETE FROM holdings"); |
185 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
179 |
$dbh->do("DELETE FROM items"); |
186 |
$dbh->do("DELETE FROM items"); |
180 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
187 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
181 |
} |
188 |
} |
Lines 192-199
if ($test_parameter) {
Link Here
|
192 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
199 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
193 |
} |
200 |
} |
194 |
|
201 |
|
195 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
196 |
|
197 |
# The definition of $searcher must be before MARC::Batch->new |
202 |
# The definition of $searcher must be before MARC::Batch->new |
198 |
my $searcher = Koha::SearchEngine::Search->new( |
203 |
my $searcher = Koha::SearchEngine::Search->new( |
199 |
{ |
204 |
{ |
Lines 231-236
if (defined $format && $format =~ /XML/i) {
Link Here
|
231 |
$batch->warnings_off(); |
236 |
$batch->warnings_off(); |
232 |
$batch->strict_off(); |
237 |
$batch->strict_off(); |
233 |
my $i=0; |
238 |
my $i=0; |
|
|
239 |
my $holdings_count = 0; |
234 |
my $commitnum = $commit ? $commit : 50; |
240 |
my $commitnum = $commit ? $commit : 50; |
235 |
my $yamlhash; |
241 |
my $yamlhash; |
236 |
|
242 |
|
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 |
my $schema = Koha::Database->schema; |
269 |
my $schema = Koha::Database->schema; |
263 |
$schema->txn_begin; |
270 |
$schema->txn_begin; |
264 |
RECORD: while ( ) { |
271 |
RECORD: while ( ) { |
Lines 309-319
RECORD: while ( ) {
Link Here
|
309 |
$field->update('a' => $isbn); |
316 |
$field->update('a' => $isbn); |
310 |
} |
317 |
} |
311 |
} |
318 |
} |
|
|
319 |
|
320 |
# check for holdings records |
321 |
my $holdings_record = 0; |
322 |
if ($biblios && $marcFlavour eq 'MARC21') { |
323 |
my $leader = $record->leader(); |
324 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
325 |
} |
326 |
|
312 |
my $id; |
327 |
my $id; |
313 |
# search for duplicates (based on Local-number) |
328 |
# search for duplicates (based on Local-number) |
314 |
my $originalid; |
329 |
my $originalid; |
315 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
330 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
316 |
if ($match) { |
331 |
if ($match && !$holdings_record) { |
317 |
require C4::Search; |
332 |
require C4::Search; |
318 |
my $query = build_query( $match, $record ); |
333 |
my $query = build_query( $match, $record ); |
319 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
334 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 420-427
RECORD: while ( ) {
Link Here
|
420 |
$yamlhash->{$originalid}->{'updated'} = 1; |
435 |
$yamlhash->{$originalid}->{'updated'} = 1; |
421 |
} |
436 |
} |
422 |
} |
437 |
} |
|
|
438 |
elsif ($holdings_record) { |
439 |
if ($import_holdings) { |
440 |
if (!defined $biblionumber) { |
441 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
442 |
} else { |
443 |
if ($insert) { |
444 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
445 |
$holding->set_marc({ record => $record }); |
446 |
my $branchcode = $holding->holdingbranch(); |
447 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
448 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
449 |
} else { |
450 |
$holding->store(); |
451 |
++$holdings_count; |
452 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
453 |
} |
454 |
} else { |
455 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
456 |
} |
457 |
} |
458 |
} |
459 |
} |
423 |
else { |
460 |
else { |
424 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
461 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
425 |
$biblionumber = $id; |
462 |
$biblionumber = $id; |
426 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
463 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
427 |
if (!$biblionumber && $isbn_check && $isbn) { |
464 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 558-564
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
558 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
595 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
559 |
|
596 |
|
560 |
my $timeneeded = gettimeofday - $starttime; |
597 |
my $timeneeded = gettimeofday - $starttime; |
561 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
598 |
if ($import_holdings) { |
|
|
599 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
600 |
} else { |
601 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
602 |
} |
562 |
if ($logfile){ |
603 |
if ($logfile){ |
563 |
print $loghandle "file : $input_marc_file\n"; |
604 |
print $loghandle "file : $input_marc_file\n"; |
564 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
605 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 679-684
Type of import: authority records
Link Here
|
679 |
|
720 |
|
680 |
The I<FILE> to import |
721 |
The I<FILE> to import |
681 |
|
722 |
|
|
|
723 |
=item B<-holdings> |
724 |
|
725 |
Import MARC 21 holdings records when interleaved with bibliographic records |
726 |
(insert only, update not supported). Used only with -biblios. |
727 |
|
682 |
=item B<-v> |
728 |
=item B<-v> |
683 |
|
729 |
|
684 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
730 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 724-730
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
724 |
=item B<-d> |
770 |
=item B<-d> |
725 |
|
771 |
|
726 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
772 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
727 |
biblioitems, items |
773 |
biblioitems, items, holdings |
728 |
|
774 |
|
729 |
=item B<-m>=I<FORMAT> |
775 |
=item B<-m>=I<FORMAT> |
730 |
|
776 |
|