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

(-)a/C4/AuthoritiesMarc.pm (-58 / +6 lines)
Lines 1455-1461 sub merge { Link Here
1455
        $z++;
1455
        $z++;
1456
    }
1456
    }
1457
    $oResult->destroy();
1457
    $oResult->destroy();
1458
    #warn scalar(@reccache)." biblios to update";
1459
    # Get All candidate Tags for the change 
1458
    # Get All candidate Tags for the change 
1460
    # (This will reduce the search scope in marc records).
1459
    # (This will reduce the search scope in marc records).
1461
    my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?";
1460
    my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?";
Lines 1464-1471 sub merge { Link Here
1464
    if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){
1463
    if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){
1465
        $tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode ));
1464
        $tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode ));
1466
    }  
1465
    }  
1467
    # BulkEdit marc records
1466
1468
    # May be used as a template for a bulkedit field  
1469
    my $overwrite = C4::Context->preference( 'AuthorityMergeMode' ) eq 'strict';
1467
    my $overwrite = C4::Context->preference( 'AuthorityMergeMode' ) eq 'strict';
1470
    my $skip_subfields = $overwrite
1468
    my $skip_subfields = $overwrite
1471
        # This hash contains all subfields from the authority report fields
1469
        # This hash contains all subfields from the authority report fields
Lines 1476-1486 sub merge { Link Here
1476
    foreach my $marcrecord(@reccache){
1474
    foreach my $marcrecord(@reccache){
1477
        my $update = 0;
1475
        my $update = 0;
1478
        foreach my $tagfield (@$tags_using_authtype){
1476
        foreach my $tagfield (@$tags_using_authtype){
1479
#             warn "tagfield : $tagfield ";
1480
            my $countfrom = 0; # used in strict mode to remove duplicates
1477
            my $countfrom = 0; # used in strict mode to remove duplicates
1481
            foreach my $field ($marcrecord->field($tagfield)){
1478
            foreach my $field ($marcrecord->field($tagfield)){
1482
                # biblio is linked to authority with $9 subfield containing authid
1479
                my $auth_number = $field->subfield("9"); # link to authority
1483
                my $auth_number=$field->subfield("9");
1484
                my $tag=$field->tag();
1480
                my $tag=$field->tag();
1485
                next if !defined($auth_number) || $auth_number ne $mergefrom;
1481
                next if !defined($auth_number) || $auth_number ne $mergefrom;
1486
                $countfrom++;
1482
                $countfrom++;
Lines 1516-1523 sub merge { Link Here
1516
                $field->replace_with($field_to);
1512
                $field->replace_with($field_to);
1517
            }
1513
            }
1518
                $update=1;
1514
                $update=1;
1519
            }#for each tag
1515
            }
1520
        }#foreach tagfield
1516
        }
1521
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1517
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1522
        my $biblionumber;
1518
        my $biblionumber;
1523
        if ($bibliotag<10){
1519
        if ($bibliotag<10){
Lines 1535-1591 sub merge { Link Here
1535
            $counteditedbiblio++;
1531
            $counteditedbiblio++;
1536
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1532
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1537
        }    
1533
        }    
1538
    }#foreach $marc
1534
    }
1539
    return $counteditedbiblio;  
1535
    return $counteditedbiblio;  
1540
  # now, find every other authority linked with this authority
1536
}
1541
  # now, find every other authority linked with this authority
1542
#   my $oConnection=C4::Context->Zconn("authorityserver");
1543
#   my $query;
1544
# # att 9210               Auth-Internal-authtype
1545
# # att 9220               Auth-Internal-LN
1546
# # ccl.properties to add for authorities
1547
#   $query= "= ".$mergefrom;
1548
#   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1549
#   my $count=$oResult->size() if  ($oResult);
1550
#   my @reccache;
1551
#   my $z=0;
1552
#   while ( $z<$count ) {
1553
#   my $rec;
1554
#           $rec=$oResult->record($z);
1555
#       my $marcdata = $rec->raw();
1556
#   push @reccache, $marcdata;
1557
#   $z++;
1558
#   }
1559
#   $oResult->destroy();
1560
#   foreach my $marc(@reccache){
1561
#     my $update;
1562
#     my $marcrecord;
1563
#     $marcrecord = MARC::File::USMARC::decode($marc);
1564
#     foreach my $tagfield (@tags_using_authtype){
1565
#       $tagfield=substr($tagfield,0,3);
1566
#       my @tags = $marcrecord->field($tagfield);
1567
#       foreach my $tag (@tags){
1568
#         my $tagsubs=$tag->subfield("9");
1569
#     #warn "$tagfield:$tagsubs:$mergefrom";
1570
#         if ($tagsubs== $mergefrom) {
1571
#           $tag->update("9" =>$mergeto);
1572
#           foreach my $subfield (@record_to) {
1573
#     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1574
#             $tag->update($subfield->[0] =>$subfield->[1]);
1575
#           }#for $subfield
1576
#         }
1577
#         $marcrecord->delete_field($tag);
1578
#         $marcrecord->add_fields($tag);
1579
#         $update=1;
1580
#       }#for each tag
1581
#     }#foreach tagfield
1582
#     my $authoritynumber = TransformMarcToKoha($marcrecord,"") ;
1583
#     if ($update==1){
1584
#       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1585
#     }
1586
# 
1587
#   }#foreach $marc
1588
}#sub
1589
1537
1590
sub _merge_newtag {
1538
sub _merge_newtag {
1591
# Routine is only called for an (exceptional) authtypecode change
1539
# Routine is only called for an (exceptional) authtypecode change
(-)a/t/db_dependent/Authorities/Merge.t (-5 / +8 lines)
Lines 43-48 subtest 'Test merge A1 to A2 (within same authtype)' => sub { Link Here
43
# Tests originate from bug 11700
43
# Tests originate from bug 11700
44
    plan tests => 9;
44
    plan tests => 9;
45
45
46
    # Start in loose mode, although it actually does not matter here
47
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
48
46
    # Add two authority records
49
    # Add two authority records
47
    my $auth1 = MARC::Record->new;
50
    my $auth1 = MARC::Record->new;
48
    $auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell' ));
51
    $auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell' ));
Lines 82-88 subtest 'Test merge A1 to A2 (within same authtype)' => sub { Link Here
82
        'Check biblio2 609$a' );
85
        'Check biblio2 609$a' );
83
};
86
};
84
87
85
subtest 'Test merge A1 to modified A1' => sub {
88
subtest 'Test merge A1 to modified A1, test strict mode' => sub {
86
# Tests originate from bug 11700
89
# Tests originate from bug 11700
87
    plan tests => 11;
90
    plan tests => 11;
88
91
Lines 105-111 subtest 'Test merge A1 to modified A1' => sub { Link Here
105
    my ( $biblionumber1 ) = AddBiblio( $MARC1, '');
108
    my ( $biblionumber1 ) = AddBiblio( $MARC1, '');
106
    my ( $biblionumber2 ) = AddBiblio( $MARC2, '');
109
    my ( $biblionumber2 ) = AddBiblio( $MARC2, '');
107
110
108
    # Time to merge
111
    # Time to merge in loose mode first
109
    @zebrarecords = ( $MARC1, $MARC2 );
112
    @zebrarecords = ( $MARC1, $MARC2 );
110
    $index = 0;
113
    $index = 0;
111
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
114
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
Lines 139-153 subtest 'Test merge A1 to modified A1' => sub { Link Here
139
        scalar($auth1new->field('109')->subfields) + 1,
142
        scalar($auth1new->field('109')->subfields) + 1,
140
        'Check number of subfields in strict mode for the remaining 609' );
143
        'Check number of subfields in strict mode for the remaining 609' );
141
        # Note: the +1 comes from the added subfield $9 in the biblio
144
        # Note: the +1 comes from the added subfield $9 in the biblio
142
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
143
};
145
};
144
146
145
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
147
subtest 'Test merge A1 to B1 (changing authtype)' => sub {
146
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
148
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
147
# Would not encourage this type of merge, but we should test what we offer
149
# Would not encourage this type of merge, but we should test what we offer
148
# The merge routine still needs the fixes on bug 17913
149
    plan tests => 13;
150
    plan tests => 13;
150
151
152
    # Get back to loose mode now
153
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
154
151
    # create two auth recs of different type
155
    # create two auth recs of different type
152
    my $auth1 = MARC::Record->new;
156
    my $auth1 = MARC::Record->new;
153
    $auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell', b => 'bb' ));
157
    $auth1->append_fields( MARC::Field->new( '109', '0', '0', 'a' => 'George Orwell', b => 'bb' ));
154
- 

Return to bug 17913