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

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

Return to bug 29440