Lines 3-8
Link Here
|
3 |
|
3 |
|
4 |
use strict; |
4 |
use strict; |
5 |
use warnings; |
5 |
use warnings; |
|
|
6 |
use Modern::Perl; |
6 |
#use diagnostics; |
7 |
#use diagnostics; |
7 |
BEGIN { |
8 |
BEGIN { |
8 |
# find Koha's Perl modules |
9 |
# find Koha's Perl modules |
Lines 24-29
Link Here
|
24 |
use C4::Debug; |
25 |
use C4::Debug; |
25 |
use C4::Charset; |
26 |
use C4::Charset; |
26 |
use C4::Items; |
27 |
use C4::Items; |
|
|
28 |
use C4::MarcModificationTemplates; |
29 |
|
27 |
use YAML; |
30 |
use YAML; |
28 |
use Unicode::Normalize; |
31 |
use Unicode::Normalize; |
29 |
use Time::HiRes qw(gettimeofday); |
32 |
use Time::HiRes qw(gettimeofday); |
Lines 43-48
Link Here
|
43 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
46 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
44 |
my $framework = ''; |
47 |
my $framework = ''; |
45 |
my $localcust; |
48 |
my $localcust; |
|
|
49 |
my $marc_mod_template = ''; |
50 |
my $marc_mod_template_id = -1; |
46 |
|
51 |
|
47 |
$|=1; |
52 |
$|=1; |
48 |
|
53 |
|
Lines 79-84
Link Here
|
79 |
'dedupbarcode' => \$dedup_barcode, |
84 |
'dedupbarcode' => \$dedup_barcode, |
80 |
'framework=s' => \$framework, |
85 |
'framework=s' => \$framework, |
81 |
'custom:s' => \$localcust, |
86 |
'custom:s' => \$localcust, |
|
|
87 |
'marcmodtemplate:s' => \$marc_mod_template, |
82 |
); |
88 |
); |
83 |
$biblios ||= !$authorities; |
89 |
$biblios ||= !$authorities; |
84 |
$insert ||= !$update; |
90 |
$insert ||= !$update; |
Lines 114-119
Link Here
|
114 |
$localcust=\&customize if $localcust; |
120 |
$localcust=\&customize if $localcust; |
115 |
} |
121 |
} |
116 |
|
122 |
|
|
|
123 |
if($marc_mod_template ne '') { |
124 |
my @templates = GetModificationTemplates(); |
125 |
foreach my $this_template (@templates) { |
126 |
if($this_template->{'name'} eq $marc_mod_template) { |
127 |
$marc_mod_template_id = $this_template->{'template_id'}; |
128 |
last; |
129 |
} |
130 |
} |
131 |
if($marc_mod_template_id < 0) { |
132 |
die "Can't located MARC modification template '$marc_mod_template'\n"; |
133 |
} |
134 |
} |
135 |
|
117 |
my $dbh = C4::Context->dbh; |
136 |
my $dbh = C4::Context->dbh; |
118 |
my $heading_fields=get_heading_fields(); |
137 |
my $heading_fields=get_heading_fields(); |
119 |
|
138 |
|
Lines 263-268
Link Here
|
263 |
} |
282 |
} |
264 |
} |
283 |
} |
265 |
SetUTF8Flag($record); |
284 |
SetUTF8Flag($record); |
|
|
285 |
if($marc_mod_template_id > 0) { |
286 |
print "Modifying MARC\n"; |
287 |
ModifyRecordWithTemplate( $marc_mod_template_id, $record ) |
288 |
} |
266 |
&$localcust($record) if $localcust; |
289 |
&$localcust($record) if $localcust; |
267 |
my $isbn; |
290 |
my $isbn; |
268 |
# remove trailing - in isbn (only for biblios, of course) |
291 |
# remove trailing - in isbn (only for biblios, of course) |
Lines 404-421
Link Here
|
404 |
$sth_isbn->execute($isbn); |
427 |
$sth_isbn->execute($isbn); |
405 |
($biblionumber,$biblioitemnumber) = $sth_isbn->fetchrow; |
428 |
($biblionumber,$biblioitemnumber) = $sth_isbn->fetchrow; |
406 |
} |
429 |
} |
407 |
if (defined $idmapfl) { |
430 |
if (defined $idmapfl) { |
408 |
if ($sourcetag < "010"){ |
431 |
if ($sourcetag < "010"){ |
409 |
if ($record->field($sourcetag)){ |
432 |
if ($record->field($sourcetag)){ |
410 |
my $source = $record->field($sourcetag)->data(); |
433 |
my $source = $record->field($sourcetag)->data(); |
411 |
printf(IDMAP "%s|%s\n",$source,$biblionumber); |
434 |
printf(IDMAP "%s|%s\n",$source,$biblionumber); |
412 |
} |
435 |
} |
413 |
} else { |
436 |
} else { |
414 |
my $source=$record->subfield($sourcetag,$sourcesubfield); |
437 |
my $source=$record->subfield($sourcetag,$sourcesubfield); |
415 |
printf(IDMAP "%s|%s\n",$source,$biblionumber); |
438 |
printf(IDMAP "%s|%s\n",$source,$biblionumber); |
416 |
} |
439 |
} |
417 |
} |
440 |
} |
418 |
# create biblio, unless we already have it ( either match or isbn ) |
441 |
|
|
|
442 |
# create biblio, unless we already have it ( either match or isbn ) |
419 |
if ($biblionumber) { |
443 |
if ($biblionumber) { |
420 |
eval{$biblioitemnumber=GetBiblioData($biblionumber)->{biblioitemnumber};}; |
444 |
eval{$biblioitemnumber=GetBiblioData($biblionumber)->{biblioitemnumber};}; |
421 |
if ($update) { |
445 |
if ($update) { |
Lines 446-468
Link Here
|
446 |
} |
470 |
} |
447 |
eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; |
471 |
eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; |
448 |
my $error_adding = $@; |
472 |
my $error_adding = $@; |
|
|
473 |
|
449 |
# Work on a clone so that if there are real errors, we can maybe |
474 |
# Work on a clone so that if there are real errors, we can maybe |
450 |
# fix them up later. |
475 |
# fix them up later. |
451 |
my $clone_record = $record->clone(); |
476 |
my $clone_record = $record->clone(); |
452 |
C4::Biblio::_strip_item_fields($clone_record, ''); |
477 |
C4::Biblio::_strip_item_fields($clone_record, ''); |
453 |
# This sets the marc fields if there was an error, and also calls |
478 |
# This sets the marc fields if there was an error, and also calls |
454 |
# defer_marc_save. |
479 |
# defer_marc_save. |
455 |
ModBiblioMarc( $clone_record, $biblionumber, $framework ); |
480 |
ModBiblioMarc( $clone_record, $biblionumber, $framework ); |
456 |
if ( $error_adding ) { |
481 |
if ( $error_adding ) { |
457 |
warn "ERROR: Adding items to bib $biblionumber failed: $error_adding"; |
482 |
warn "ERROR: Adding items to bib $biblionumber failed: $error_adding"; |
458 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); |
483 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); |
459 |
# if we failed because of an exception, assume that |
484 |
# if we failed because of an exception, assume that |
460 |
# the MARC columns in biblioitems were not set. |
485 |
# the MARC columns in biblioitems were not set. |
461 |
next RECORD; |
486 |
next RECORD; |
462 |
} |
487 |
} else { |
463 |
else{ |
488 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
464 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
489 |
} |
465 |
} |
490 |
|
466 |
if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) { |
491 |
if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) { |
467 |
# Find the record called 'barcode' |
492 |
# Find the record called 'barcode' |
468 |
my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', $framework); |
493 |
my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', $framework); |