Lines 451-480
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
451 |
unless ($test_parameter) { |
451 |
unless ($test_parameter) { |
452 |
if ($authorities) { |
452 |
if ($authorities) { |
453 |
my $authtypecode = GuessAuthTypeCode($record, $heading_fields); |
453 |
my $authtypecode = GuessAuthTypeCode($record, $heading_fields); |
454 |
my $authid = ($matched_record_id? $matched_record_id : GuessAuthId($record)); |
454 |
my $authid; |
455 |
if ($authid && GetAuthority($authid) && $update) { |
455 |
|
456 |
## Authority has an id and is in database : Replace |
456 |
if ($matched_record_id) { |
457 |
eval { ( $authid ) = ModAuthority($authid, $record, $authtypecode) }; |
457 |
if ($update) { |
458 |
if ($@) { |
458 |
## Authority has an id and is in database: update |
459 |
warn "Problem with authority $authid Cannot Modify"; |
459 |
eval { ($authid) = ModAuthority($matched_record_id, $record, $authtypecode) }; |
460 |
printlog({ id => $authid, op => "edit", status => "ERROR" }) if ($logfile); |
460 |
if ($@) { |
|
|
461 |
warn "ERROR: Update authority $matched_record_id failed: $@\n"; |
462 |
printlog({ id => $matched_record_id, op => "update", status => "ERROR" }) if ($logfile); |
463 |
} |
464 |
else { |
465 |
printlog({ id => $authid, op => "update", status => "ok" }) if ($logfile); |
466 |
} |
461 |
} |
467 |
} |
462 |
else{ |
468 |
elsif ($logfile) { |
463 |
printlog({ id=> $authid, op=> "edit", status => "ok"}) if ($logfile); |
469 |
warn "WARNING: Update authority $originalid skipped"; |
|
|
470 |
printlog({ |
471 |
id => $matched_record_id, |
472 |
op => "update", |
473 |
status => "warning: authority already in database and option -update not enabled, skipping..." |
474 |
}); |
464 |
} |
475 |
} |
465 |
} |
476 |
} |
466 |
else { |
477 |
elsif ($insert) { |
467 |
## True insert in database |
478 |
## An authid is defined but no authority in database: insert |
468 |
eval { ( $authid ) = AddAuthority($record, "", $authtypecode) }; |
479 |
eval { ($authid) = AddAuthority($record, undef, $authtypecode) }; |
469 |
if ($@) { |
480 |
if ($@) { |
470 |
warn "Problem with authority $originalid Cannot Add ".$@; |
481 |
warn "ERROR: Insert authority $originalid failed: $@\n"; |
471 |
printlog({ id => $originalid, op => "insert", status => "ERROR" }) if ($logfile); |
482 |
printlog({ id => $originalid, op => "insert", status => "ERROR" }) if ($logfile); |
472 |
} |
483 |
} |
473 |
else { |
484 |
else { |
474 |
printlog({ id => $authid, op => "insert", status => "ok" }) if ($logfile); |
485 |
printlog({ id => $authid, op => "insert", status => "ok" }) if ($logfile); |
475 |
} |
486 |
} |
476 |
|
|
|
477 |
} |
487 |
} |
|
|
488 |
else { |
489 |
warn "WARNING: Insert authority $originalid skipped"; |
490 |
printlog( { id => $originalid, op => "insert", status => "warning : biblio not in database and option -insert not enabled, skipping..." } ) if ($logfile); |
491 |
} |
492 |
|
478 |
if ($yamlfile) { |
493 |
if ($yamlfile) { |
479 |
$yamlhash->{$originalid} = YAMLFileEntry( |
494 |
$yamlhash->{$originalid} = YAMLFileEntry( |
480 |
$record, |
495 |
$record, |
Lines 504-512
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
504 |
} |
519 |
} |
505 |
} |
520 |
} |
506 |
|
521 |
|
507 |
# create biblio, unless we already have it ( either match or isbn ) |
522 |
# Create biblio, unless we already have it (either match or ISBN) |
508 |
if ($matched_record_id) { |
523 |
if ($matched_record_id) { |
509 |
# TODO: Implement also for authority records! |
|
|
510 |
eval{ |
524 |
eval{ |
511 |
$biblioitemnumber = Koha::Biblios->find( $matched_record_id )->biblioitem->biblioitemnumber; |
525 |
$biblioitemnumber = Koha::Biblios->find( $matched_record_id )->biblioitem->biblioitemnumber; |
512 |
}; |
526 |
}; |
Lines 514-525
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
514 |
my $success; |
528 |
my $success; |
515 |
eval { $success = ModBiblio($record, $matched_record_id, GetFrameworkCode($matched_record_id), $modify_biblio_marc_options) }; |
529 |
eval { $success = ModBiblio($record, $matched_record_id, GetFrameworkCode($matched_record_id), $modify_biblio_marc_options) }; |
516 |
if ($@) { |
530 |
if ($@) { |
517 |
warn "ERROR: Edit biblio $matched_record_id failed: $@\n"; |
531 |
warn "ERROR: Update biblio $matched_record_id failed: $@\n"; |
518 |
printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile); |
532 |
printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile); |
519 |
next RECORD; |
533 |
next RECORD; |
520 |
} |
534 |
} |
521 |
elsif (!$success) { |
535 |
elsif (!$success) { |
522 |
warn "ERROR: Edit biblio $matched_record_id failed for unkown reason"; |
536 |
warn "ERROR: Update biblio $matched_record_id failed for unkown reason"; |
523 |
printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile); |
537 |
printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile); |
524 |
next RECORD; |
538 |
next RECORD; |
525 |
} |
539 |
} |
Lines 529-551
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
529 |
} |
543 |
} |
530 |
} |
544 |
} |
531 |
else { |
545 |
else { |
|
|
546 |
warn "WARNING: Update biblio $originalid skipped"; |
532 |
printlog( { id => $matched_record_id, op => "update", status => "warning : already in database and option -update not enabled, skipping..." } ) if ($logfile); |
547 |
printlog( { id => $matched_record_id, op => "update", status => "warning : already in database and option -update not enabled, skipping..." } ) if ($logfile); |
533 |
} |
548 |
} |
534 |
} |
549 |
} |
535 |
elsif ($insert) { |
550 |
elsif ($insert) { |
536 |
eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) }; |
551 |
eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) }; |
537 |
if ($@) { |
552 |
if ($@) { |
538 |
warn "ERROR: Adding biblio $record_id failed: $@\n"; |
553 |
warn "ERROR: Insert biblio $originalid failed: $@\n"; |
539 |
printlog( { id => $record_id, op => "insert", status => "ERROR" } ) if ($logfile); |
554 |
printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile); |
540 |
next RECORD; |
555 |
next RECORD; |
541 |
} |
556 |
} |
542 |
else { |
557 |
else { |
543 |
printlog( { id => $record_id, op => "insert", status => "ok" } ) if ($logfile); |
558 |
printlog( { id => $originalid, op => "insert", status => "ok" } ) if ($logfile); |
544 |
} |
559 |
} |
545 |
} |
560 |
} |
546 |
else { |
561 |
else { |
547 |
warn "WARNING: Updating record ".($originalid)." failed"; |
562 |
warn "WARNING: Insert biblio $originalid skipped"; |
548 |
printlog( { id => $originalid, op => "insert", status => "warning : not in database and option -insert not enabled, skipping..." } ) if ($logfile); |
563 |
printlog( { id => $originalid, op => "insert", status => "warning : biblio not in database and option -insert not enabled, skipping..." } ) if ($logfile); |
549 |
next RECORD; |
564 |
next RECORD; |
550 |
} |
565 |
} |
551 |
my $record_has_added_items = 0; |
566 |
my $record_has_added_items = 0; |
Lines 553-558
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
553 |
$yamlhash->{$originalid} = $record_id if $yamlfile; |
568 |
$yamlhash->{$originalid} = $record_id if $yamlfile; |
554 |
eval { ($itemnumbers_ref, $errors_ref) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, $framework); }; |
569 |
eval { ($itemnumbers_ref, $errors_ref) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, $framework); }; |
555 |
$record_has_added_items = @{$itemnumbers_ref}; |
570 |
$record_has_added_items = @{$itemnumbers_ref}; |
|
|
571 |
|
556 |
my $error_adding = $@; |
572 |
my $error_adding = $@; |
557 |
# Work on a clone so that if there are real errors, we can maybe |
573 |
# Work on a clone so that if there are real errors, we can maybe |
558 |
# fix them up later. |
574 |
# fix them up later. |
559 |
- |
|
|