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 504-512 RECORD: foreach my $record (@{$marc_records}) { Link Here
504
                }
522
                }
505
            }
523
            }
506
524
507
            # create biblio, unless we already have it ( either match or isbn )
525
            # Create biblio, unless we already have it (either match or ISBN)
508
            if ($matched_record_id) {
526
            if ($matched_record_id) {
509
                # TODO: Implement also for authority records!
510
                eval{
527
                eval{
511
                    $biblioitemnumber = Koha::Biblios->find( $matched_record_id )->biblioitem->biblioitemnumber;
528
                    $biblioitemnumber = Koha::Biblios->find( $matched_record_id )->biblioitem->biblioitemnumber;
512
                };
529
                };
Lines 514-525 RECORD: foreach my $record (@{$marc_records}) { Link Here
514
                    my $success;
531
                    my $success;
515
                    eval { $success = ModBiblio($record, $matched_record_id, GetFrameworkCode($matched_record_id), $modify_biblio_marc_options) };
532
                    eval { $success = ModBiblio($record, $matched_record_id, GetFrameworkCode($matched_record_id), $modify_biblio_marc_options) };
516
                    if ($@) {
533
                    if ($@) {
517
                        warn "ERROR: Edit biblio $matched_record_id failed: $@\n";
534
                        warn "ERROR: Update biblio $matched_record_id failed: $@\n";
518
                        printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile);
535
                        printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile);
519
                        next RECORD;
536
                        next RECORD;
520
                    }
537
                    }
521
                    elsif (!$success) {
538
                    elsif (!$success) {
522
                        warn "ERROR: Edit biblio $matched_record_id failed for unkown reason";
539
                        warn "ERROR: Update biblio $matched_record_id failed for unkown reason";
523
                        printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile);
540
                        printlog( { id => $matched_record_id, op => "update", status => "ERROR" } ) if ($logfile);
524
                        next RECORD;
541
                        next RECORD;
525
                    }
542
                    }
Lines 529-551 RECORD: foreach my $record (@{$marc_records}) { Link Here
529
                    }
546
                    }
530
                }
547
                }
531
                else {
548
                else {
549
                    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);
550
                    printlog( { id => $matched_record_id, op => "update", status => "warning : already in database and option -update not enabled, skipping..." } ) if ($logfile);
533
                }
551
                }
534
            }
552
            }
535
            elsif ($insert) {
553
            elsif ($insert) {
536
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) };
554
                eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) };
537
                if ($@) {
555
                if ($@) {
538
                    warn "ERROR: Adding biblio $record_id failed: $@\n";
556
                    warn "ERROR: Insert biblio $originalid failed: $@\n";
539
                    printlog( { id => $record_id, op => "insert", status => "ERROR" } ) if ($logfile);
557
                    printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile);
540
                    next RECORD;
558
                    next RECORD;
541
                }
559
                }
542
                else {
560
                else {
543
                    printlog( { id => $record_id, op => "insert", status => "ok" } ) if ($logfile);
561
                    printlog( { id => $originalid, op => "insert", status => "ok" } ) if ($logfile);
544
                }
562
                }
545
            }
563
            }
546
            else {
564
            else {
547
                warn "WARNING: Updating record ".($originalid)." failed";
565
                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);
566
                printlog( { id => $originalid, op => "insert", status => "warning : biblio not in database and option -insert not enabled, skipping..." } ) if ($logfile);
549
                next RECORD;
567
                next RECORD;
550
            }
568
            }
551
            my $record_has_added_items = 0;
569
            my $record_has_added_items = 0;
552
- 

Return to bug 29440