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