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