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

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

Return to bug 29440