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

(-)a/C4/AuthoritiesMarc.pm (-3 / +67 lines)
Lines 1451-1456 sub merge { Link Here
1451
    $skip_subfields->{9} = 1 if !$overwrite;
1451
    $skip_subfields->{9} = 1 if !$overwrite;
1452
1452
1453
    my $counteditedbiblio = 0;
1453
    my $counteditedbiblio = 0;
1454
    my ($auth_ind1, $auth_ind2, $auth_008_11, $auth_040_f);
1455
    $auth_ind1 = $MARCto->field($auth_tag_to_report_to)->indicator('1');
1456
    $auth_ind2 = $MARCto->field($auth_tag_to_report_to)->indicator('2');
1457
    $auth_008_11 = substr($MARCto->field('008')->data, 11, 1) if C4::Context->preference("marcflavour") eq "MARC21" && $MARCto->field('008');
1458
    $auth_040_f = $MARCto->subfield('040', 'f') if C4::Context->preference("marcflavour") eq "MARC21";
1454
    foreach my $biblionumber ( @biblionumbers ) {
1459
    foreach my $biblionumber ( @biblionumbers ) {
1455
        my $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
1460
        my $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
1456
        next if !$marcrecord;
1461
        next if !$marcrecord;
Lines 1473-1482 sub merge { Link Here
1473
                my $newtag = $tags_new && @$tags_new
1478
                my $newtag = $tags_new && @$tags_new
1474
                  ? _merge_newtag( $tag, $tags_new )
1479
                  ? _merge_newtag( $tag, $tags_new )
1475
                  : $tag;
1480
                  : $tag;
1481
                my ($indicator1, $indicator2, $subfield_2) = _merge_indicators({
1482
                        biblio_tag_to => $newtag,
1483
                        auth_tag => $auth_tag_to_report_to,
1484
                        auth_ind1 => $auth_ind1,
1485
                        auth_ind2 => $auth_ind2,
1486
                        auth_008_11 => $auth_008_11,
1487
                        auth_040_f => $auth_040_f
1488
                    });
1489
                $indicator1 //= $field->indicator(1);
1490
                $indicator2 //= $field->indicator(2);
1476
                my $field_to = MARC::Field->new(
1491
                my $field_to = MARC::Field->new(
1477
                    $newtag,
1492
                    $newtag,
1478
                    $field->indicator(1),
1493
                    $indicator1,
1479
                    $field->indicator(2),
1494
                    $indicator2,
1480
                    "9" => $mergeto,
1495
                    "9" => $mergeto,
1481
                );
1496
                );
1482
                foreach my $subfield ( grep { $_->[0] ne '9' } @record_to ) {
1497
                foreach my $subfield ( grep { $_->[0] ne '9' } @record_to ) {
Lines 1489-1494 sub merge { Link Here
1489
                        $field_to->add_subfields( $subfield->[0], $subfield->[1] );
1504
                        $field_to->add_subfields( $subfield->[0], $subfield->[1] );
1490
                    }
1505
                    }
1491
                }
1506
                }
1507
                if ($subfield_2) {
1508
                    $field_to->update(2 => $subfield_2);  # update -- if there was one, should be updated, otherwise will be added
1509
                } elsif (defined $subfield_2) {  # defined but empty = MARC 21 6XX, auth 008/11 !~ /[rsz]/ -> $2 should be removed if exist
1510
                    $field_to->delete_subfield(code => '2');
1511
                }
1492
                if ($tags_new && @$tags_new) {
1512
                if ($tags_new && @$tags_new) {
1493
                    $marcrecord->delete_field($field);
1513
                    $marcrecord->delete_field($field);
1494
                    append_fields_ordered( $marcrecord, $field_to );
1514
                    append_fields_ordered( $marcrecord, $field_to );
Lines 1522-1527 sub _merge_newtag { Link Here
1522
    return @same_block ? $same_block[0] : $new_tags->[0];
1542
    return @same_block ? $same_block[0] : $new_tags->[0];
1523
}
1543
}
1524
1544
1545
sub _merge_indicators {
1546
    my $params = shift;
1547
    my ($indicator1, $indicator2, $subfield_2);
1548
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
1549
        $indicator1 = $params->{auth_ind1};
1550
        $indicator2 = $params->{auth_ind2};
1551
    } elsif (C4::Context->preference('marcflavour') eq 'MARC21') {
1552
        if ($params->{biblio_tag_to} =~ /^6/) {  # MARC 21 subject heading - 2nd ind. depends on 008/11 of auth. rec.
1553
            my %thes_mapping = qw / a 0
1554
                                    b 1
1555
                                    c 2
1556
                                    d 3
1557
                                    k 5
1558
                                    n 4
1559
                                    r 7
1560
                                    s 7
1561
                                    v 6
1562
                                    z 7
1563
                                    | 4 /;
1564
            $indicator2 = defined $thes_mapping{$params->{auth_008_11}}  ? $thes_mapping{$params->{auth_008_11}} : ($params->{auth_008_11} ? $params->{auth_008_11} : '4');
1565
            if ($indicator2 eq '7') {
1566
                if ($params->{auth_008_11} eq 'r') {
1567
                    $subfield_2 = 'aat';
1568
                } elsif ($params->{auth_008_11} eq 's') {
1569
                    $subfield_2 = 'sears';
1570
                } else {  # z -- let's check 040 $f
1571
                    $subfield_2 = $params->{auth_040_f};  # OK if undefined -- will do nothing to $2 in biblio, if there is
1572
                }
1573
            } else {
1574
                $subfield_2 //= '';  #  ind2 != 7 --> there shouldn't be $2 in 6XX field (MARC 21)
1575
            }
1576
        }
1577
        if ($params->{auth_tag} eq '130') {  # unified title -- the special case
1578
            if ($params->{biblio_tag_to} =~ /830|240/) {
1579
                $indicator2 = $params->{auth_ind2};
1580
            } else {
1581
                $indicator1 = $params->{auth_ind2};
1582
            }
1583
        } else {
1584
            $indicator1 = $params->{auth_ind1};
1585
        }
1586
    }
1587
    return ($indicator1, $indicator2, $subfield_2);
1588
}
1589
1525
sub append_fields_ordered {
1590
sub append_fields_ordered {
1526
# while we lack this function in MARC::Record
1591
# while we lack this function in MARC::Record
1527
# we do not want insert_fields_ordered since it inserts before
1592
# we do not want insert_fields_ordered since it inserts before
1528
- 

Return to bug 14769