View | Details | Raw Unified | Return to bug 29440
Collapse All | Expand All

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

Return to bug 29440