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

(-)a/C4/AuthoritiesMarc.pm (-2 / +9 lines)
Lines 1477-1490 sub merge { Link Here
1477
        my $update = 0;
1477
        my $update = 0;
1478
        foreach my $tagfield (@$tags_using_authtype){
1478
        foreach my $tagfield (@$tags_using_authtype){
1479
#             warn "tagfield : $tagfield ";
1479
#             warn "tagfield : $tagfield ";
1480
            my $countfrom = 0; # used in strict mode to remove duplicates
1480
            foreach my $field ($marcrecord->field($tagfield)){
1481
            foreach my $field ($marcrecord->field($tagfield)){
1481
                # biblio is linked to authority with $9 subfield containing authid
1482
                # biblio is linked to authority with $9 subfield containing authid
1482
                my $auth_number=$field->subfield("9");
1483
                my $auth_number=$field->subfield("9");
1483
                my $tag=$field->tag();
1484
                my $tag=$field->tag();
1485
                next if !defined($auth_number) || $auth_number ne $mergefrom;
1486
                $countfrom++;
1487
                if( $overwrite && $countfrom > 1 ) {
1488
                    # remove this duplicate in strict mode
1489
                    $marcrecord->delete_field( $field );
1490
                    $update = 1;
1491
                    next;
1492
                }
1484
                my $newtag = $tags_new
1493
                my $newtag = $tags_new
1485
                    ? _merge_newtag( $tag, $tags_new )
1494
                    ? _merge_newtag( $tag, $tags_new )
1486
                    : $tag;
1495
                    : $tag;
1487
                if ($auth_number==$mergefrom) {
1488
                    my $field_to = MARC::Field->new(
1496
                    my $field_to = MARC::Field->new(
1489
                        $newtag,
1497
                        $newtag,
1490
                        $field->indicator(1),
1498
                        $field->indicator(1),
Lines 1508-1514 sub merge { Link Here
1508
                $field->replace_with($field_to);
1516
                $field->replace_with($field_to);
1509
            }
1517
            }
1510
                $update=1;
1518
                $update=1;
1511
                }
1512
            }#for each tag
1519
            }#for each tag
1513
        }#foreach tagfield
1520
        }#foreach tagfield
1514
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1521
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
(-)a/t/db_dependent/Authorities/Merge.t (-2 / +8 lines)
Lines 82-88 subtest 'Test merge A1 to A2 (within same authtype)' => sub { Link Here
82
82
83
subtest 'Test merge A1 to modified A1' => sub {
83
subtest 'Test merge A1 to modified A1' => sub {
84
# Tests originate from bug 11700
84
# Tests originate from bug 11700
85
    plan tests => 9;
85
    plan tests => 11;
86
86
87
    # Simulate modifying an authority from auth1old to auth1new
87
    # Simulate modifying an authority from auth1old to auth1new
88
    my $auth1old = MARC::Record->new;
88
    my $auth1old = MARC::Record->new;
Lines 95-100 subtest 'Test merge A1 to modified A1' => sub { Link Here
95
    my $MARC1 = MARC::Record->new;
95
    my $MARC1 = MARC::Record->new;
96
    $MARC1->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Bruce Wayne', 'b' => '2014', '9' => $authid1 ));
96
    $MARC1->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Bruce Wayne', 'b' => '2014', '9' => $authid1 ));
97
    $MARC1->append_fields( MARC::Field->new( '245', '', '', 'a' => 'From the depths' ));
97
    $MARC1->append_fields( MARC::Field->new( '245', '', '', 'a' => 'From the depths' ));
98
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'b' => 'Should be cleared too', '9' => $authid1 ));
99
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'c' => 'This is a duplicate to be removed in strict mode', '9' => $authid1 ));
98
    my $MARC2 = MARC::Record->new;
100
    my $MARC2 = MARC::Record->new;
99
    $MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Batman', '9' => $authid1 ));
101
    $MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Batman', '9' => $authid1 ));
100
    $MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' ));
102
    $MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' ));
Lines 128-133 subtest 'Test merge A1 to modified A1' => sub { Link Here
128
    $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new );
130
    $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new );
129
    $biblio1 = GetMarcBiblio($biblionumber1);
131
    $biblio1 = GetMarcBiblio($biblionumber1);
130
    is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' );
132
    is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' );
133
    is( $biblio1->fields, scalar( $MARC1->fields ) - 1, 'strict mode should remove a duplicate 609' );
134
    is( $biblio1->field(609)->subfields,
135
        scalar($auth1new->field('109')->subfields) + 1,
136
        'Check number of subfields in strict mode for the remaining 609' );
137
        # Note: the +1 comes from the added subfield $9 in the biblio
131
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
138
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
132
};
139
};
133
140
134
- 

Return to bug 17913