Lines 41-46
use Pod::Usage qw( pod2usage );
Link Here
|
41 |
|
41 |
|
42 |
use Koha::Logger; |
42 |
use Koha::Logger; |
43 |
use Koha::Biblios; |
43 |
use Koha::Biblios; |
|
|
44 |
use Koha::Holdings; |
44 |
use Koha::SearchEngine; |
45 |
use Koha::SearchEngine; |
45 |
use Koha::SearchEngine::Search; |
46 |
use Koha::SearchEngine::Search; |
46 |
|
47 |
|
Lines 48-54
use open qw( :std :encoding(UTF-8) );
Link Here
|
48 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
49 |
binmode( STDOUT, ":encoding(UTF-8)" ); |
49 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
50 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
50 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
51 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
51 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append ); |
52 |
my ( $insert, $filters, $update, $all, $yamlfile, $authtypes, $append, $import_holdings ); |
52 |
my $cleanisbn = 1; |
53 |
my $cleanisbn = 1; |
53 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
54 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
54 |
my $framework = ''; |
55 |
my $framework = ''; |
Lines 92-104
GetOptions(
Link Here
|
92 |
'framework=s' => \$framework, |
93 |
'framework=s' => \$framework, |
93 |
'custom:s' => \$localcust, |
94 |
'custom:s' => \$localcust, |
94 |
'marcmodtemplate:s' => \$marc_mod_template, |
95 |
'marcmodtemplate:s' => \$marc_mod_template, |
|
|
96 |
'holdings' => \$import_holdings, |
95 |
); |
97 |
); |
96 |
$biblios ||= !$authorities; |
98 |
$biblios ||= !$authorities; |
97 |
$insert ||= !$update; |
99 |
$insert ||= !$update; |
98 |
my $writemode = ($append) ? "a" : "w"; |
100 |
my $writemode = ($append) ? "a" : "w"; |
|
|
101 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
99 |
|
102 |
|
100 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
103 |
pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities; |
101 |
|
104 |
|
|
|
105 |
pod2usage( -msg => "\nHoldings only supported for MARC 21 biblios.\n", -exitval ) if $import_holdings && (!$biblios || $marcFlavour ne 'MARC21'); |
106 |
|
102 |
if ($all) { |
107 |
if ($all) { |
103 |
$insert = 1; |
108 |
$insert = 1; |
104 |
$update = 1; |
109 |
$update = 1; |
Lines 176-187
if ($fk_off) {
Link Here
|
176 |
|
181 |
|
177 |
|
182 |
|
178 |
if ($delete) { |
183 |
if ($delete) { |
179 |
if ($biblios){ |
184 |
if ($biblios) { |
180 |
print "deleting biblios\n"; |
185 |
print "deleting biblios\n"; |
181 |
$dbh->do("DELETE FROM biblio"); |
186 |
$dbh->do("DELETE FROM biblio"); |
182 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
187 |
$dbh->do("ALTER TABLE biblio AUTO_INCREMENT = 1"); |
183 |
$dbh->do("DELETE FROM biblioitems"); |
188 |
$dbh->do("DELETE FROM biblioitems"); |
184 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
189 |
$dbh->do("ALTER TABLE biblioitems AUTO_INCREMENT = 1"); |
|
|
190 |
$dbh->do("DELETE FROM holdings"); |
191 |
$dbh->do("ALTER TABLE holdings AUTO_INCREMENT = 1"); |
185 |
$dbh->do("DELETE FROM items"); |
192 |
$dbh->do("DELETE FROM items"); |
186 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
193 |
$dbh->do("ALTER TABLE items AUTO_INCREMENT = 1"); |
187 |
} |
194 |
} |
Lines 198-205
if ($test_parameter) {
Link Here
|
198 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
205 |
print "TESTING MODE ONLY\n DOING NOTHING\n===============\n"; |
199 |
} |
206 |
} |
200 |
|
207 |
|
201 |
my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21'; |
|
|
202 |
|
203 |
# The definition of $searcher must be before MARC::Batch->new |
208 |
# The definition of $searcher must be before MARC::Batch->new |
204 |
my $searcher = Koha::SearchEngine::Search->new( |
209 |
my $searcher = Koha::SearchEngine::Search->new( |
205 |
{ |
210 |
{ |
Lines 237-242
if (defined $format && $format =~ /XML/i) {
Link Here
|
237 |
$batch->warnings_off(); |
242 |
$batch->warnings_off(); |
238 |
$batch->strict_off(); |
243 |
$batch->strict_off(); |
239 |
my $i=0; |
244 |
my $i=0; |
|
|
245 |
my $holdings_count = 0; |
240 |
my $commitnum = $commit ? $commit : 50; |
246 |
my $commitnum = $commit ? $commit : 50; |
241 |
my $yamlhash; |
247 |
my $yamlhash; |
242 |
|
248 |
|
Lines 266-271
if ($logfile){
Link Here
|
266 |
} |
272 |
} |
267 |
|
273 |
|
268 |
my $logger = Koha::Logger->get; |
274 |
my $logger = Koha::Logger->get; |
|
|
275 |
my $biblionumber; |
269 |
my $schema = Koha::Database->schema; |
276 |
my $schema = Koha::Database->schema; |
270 |
$schema->txn_begin; |
277 |
$schema->txn_begin; |
271 |
RECORD: while ( ) { |
278 |
RECORD: while ( ) { |
Lines 316-326
RECORD: while ( ) {
Link Here
|
316 |
$field->update('a' => $isbn); |
323 |
$field->update('a' => $isbn); |
317 |
} |
324 |
} |
318 |
} |
325 |
} |
|
|
326 |
|
327 |
# check for holdings records |
328 |
my $holdings_record = 0; |
329 |
if ($biblios && $marcFlavour eq 'MARC21') { |
330 |
my $leader = $record->leader(); |
331 |
$holdings_record = $leader =~ /^.{6}[uvxy]/; |
332 |
} |
333 |
|
319 |
my $id; |
334 |
my $id; |
320 |
# search for duplicates (based on Local-number) |
335 |
# search for duplicates (based on Local-number) |
321 |
my $originalid; |
336 |
my $originalid; |
322 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
337 |
$originalid = GetRecordId( $record, $tagid, $subfieldid ); |
323 |
if ($match) { |
338 |
if ($match && !$holdings_record) { |
324 |
require C4::Search; |
339 |
require C4::Search; |
325 |
my $query = build_query( $match, $record ); |
340 |
my $query = build_query( $match, $record ); |
326 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
341 |
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' ); |
Lines 424-431
RECORD: while ( ) {
Link Here
|
424 |
$yamlhash->{$originalid}->{'updated'} = 1; |
439 |
$yamlhash->{$originalid}->{'updated'} = 1; |
425 |
} |
440 |
} |
426 |
} |
441 |
} |
|
|
442 |
elsif ($holdings_record) { |
443 |
if ($import_holdings) { |
444 |
if (!defined $biblionumber) { |
445 |
warn "ERROR: Encountered holdings record without preceding biblio record\n"; |
446 |
} else { |
447 |
if ($insert) { |
448 |
my $holding = Koha::Holding->new({ biblionumber => $biblionumber }); |
449 |
$holding->set_marc({ record => $record }); |
450 |
my $branchcode = $holding->holdingbranch(); |
451 |
if (defined $branchcode && !Koha::Libraries->find({ branchcode => $branchcode})) { |
452 |
printlog( { id => 0, op => 'insert', status => "warning : library $branchcode not defined, holdings record skipped" } ) if ($logfile); |
453 |
} else { |
454 |
$holding->store(); |
455 |
++$holdings_count; |
456 |
printlog( { id => $holding->holding_id(), op => 'insert', status => 'ok' } ) if ($logfile); |
457 |
} |
458 |
} else { |
459 |
printlog( { id => 0, op => 'update', status => 'warning : not in database' } ) if ($logfile); |
460 |
} |
461 |
} |
462 |
} |
463 |
} |
427 |
else { |
464 |
else { |
428 |
my ( $biblionumber, $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
465 |
my ( $biblioitemnumber, $itemnumbers_ref, $errors_ref ); |
429 |
$biblionumber = $id; |
466 |
$biblionumber = $id; |
430 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
467 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
431 |
if (!$biblionumber && $isbn_check && $isbn) { |
468 |
if (!$biblionumber && $isbn_check && $isbn) { |
Lines 562-568
delete $ENV{OVERRIDE_SYSPREF_CataloguingLog};
Link Here
|
562 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
599 |
delete $ENV{OVERRIDE_SYSPREF_AuthoritiesLog}; |
563 |
|
600 |
|
564 |
my $timeneeded = gettimeofday - $starttime; |
601 |
my $timeneeded = gettimeofday - $starttime; |
565 |
print "\n$i MARC records done in $timeneeded seconds\n"; |
602 |
if ($import_holdings) { |
|
|
603 |
printf("\n%i MARC bibliographic records and %i holdings records done in %0.3f seconds\n", $i, $holdings_count, $timeneeded); |
604 |
} else { |
605 |
printf("\n%i MARC records done in %0.3f seconds\n", $i, $timeneeded); |
606 |
} |
566 |
if ($logfile){ |
607 |
if ($logfile){ |
567 |
print $loghandle "file : $input_marc_file\n"; |
608 |
print $loghandle "file : $input_marc_file\n"; |
568 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
609 |
print $loghandle "$i MARC records done in $timeneeded seconds\n"; |
Lines 683-688
Type of import: authority records
Link Here
|
683 |
|
724 |
|
684 |
The I<FILE> to import |
725 |
The I<FILE> to import |
685 |
|
726 |
|
|
|
727 |
=item B<-holdings> |
728 |
|
729 |
Import MARC 21 holdings records when interleaved with bibliographic records |
730 |
(insert only, update not supported). Used only with -biblios. |
731 |
|
686 |
=item B<-v> |
732 |
=item B<-v> |
687 |
|
733 |
|
688 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
734 |
Verbose mode. 1 means "some infos", 2 means "MARC dumping" |
Lines 728-734
I<UNIMARC> are supported. MARC21 by default.
Link Here
|
728 |
=item B<-d> |
774 |
=item B<-d> |
729 |
|
775 |
|
730 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
776 |
Delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, |
731 |
biblioitems, items |
777 |
biblioitems, items, holdings |
732 |
|
778 |
|
733 |
=item B<-m>=I<FORMAT> |
779 |
=item B<-m>=I<FORMAT> |
734 |
|
780 |
|