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

(-)a/C4/AuthoritiesMarc.pm (-81 / +32 lines)
Lines 1446-1454 Then we should add some new parameter : bibliotargettag, authtargettag Link Here
1446
=cut
1446
=cut
1447
1447
1448
sub merge {
1448
sub merge {
1449
    my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1449
    my ($mergefrom, $MARCfrom, $mergeto, $MARCto) = @_;
1450
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1450
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);
1451
    my $dbh=C4::Context->dbh;
1451
    my $dbh = C4::Context->dbh;
1452
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1452
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1453
    my $authtypecodeto = GetAuthTypeCode($mergeto);
1453
    my $authtypecodeto = GetAuthTypeCode($mergeto);
1454
#     warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
1454
#     warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
Lines 1461-1472 sub merge { Link Here
1461
    my ($auth_tag_to_report_from) = $sth->fetchrow;
1461
    my ($auth_tag_to_report_from) = $sth->fetchrow;
1462
    $sth->execute($authtypecodeto);
1462
    $sth->execute($authtypecodeto);
1463
    my ($auth_tag_to_report_to) = $sth->fetchrow;
1463
    my ($auth_tag_to_report_to) = $sth->fetchrow;
1464
    
1464
1465
    my @record_to;
1465
    my @record_to;
1466
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1466
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1467
    my @record_from;
1467
    my @record_from;
1468
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1468
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1469
    
1469
1470
    my @reccache;
1470
    my @reccache;
1471
    # search all biblio tags using this authority.
1471
    # search all biblio tags using this authority.
1472
    #Getting marcbiblios impacted by the change.
1472
    #Getting marcbiblios impacted by the change.
Lines 1505-1546 sub merge { Link Here
1505
    while (my ($tagfield) = $sth->fetchrow) {
1505
    while (my ($tagfield) = $sth->fetchrow) {
1506
        push @tags_using_authtype,$tagfield ;
1506
        push @tags_using_authtype,$tagfield ;
1507
    }
1507
    }
1508
    my $tag_to=0;  
1508
    my $tag_to=0;
1509
    if ($authtypecodeto ne $authtypecodefrom){  
1509
    if ($authtypecodeto ne $authtypecodefrom){
1510
        # If many tags, take the first
1510
        # If many tags, take the first
1511
        $sth->execute($authtypecodeto);    
1511
        $sth->execute($authtypecodeto);
1512
        $tag_to=$sth->fetchrow;
1512
        $tag_to=$sth->fetchrow;
1513
        #warn $tag_to;    
1513
    }
1514
    }  
1515
    # BulkEdit marc records
1514
    # BulkEdit marc records
1516
    # May be used as a template for a bulkedit field  
1515
    # May be used as a template for a bulkedit field
1517
    foreach my $marcrecord(@reccache){
1516
    foreach my $marcrecord(@reccache){
1518
        my $update;           
1517
        my $update;
1519
        foreach my $tagfield (@tags_using_authtype){
1518
        foreach my $tagfield (@tags_using_authtype){
1520
#             warn "tagfield : $tagfield ";
1521
            foreach my $field ($marcrecord->field($tagfield)){
1519
            foreach my $field ($marcrecord->field($tagfield)){
1522
                # biblio is linked to authority with $9 subfield containing authid
1520
                # biblio is linked to authority with $9 subfield containing authid
1523
                my $auth_number=$field->subfield("9");
1521
                my $auth_number=$field->subfield("9");
1524
                my $tag=$field->tag();          
1522
                my $tag=$field->tag();
1525
                if ($auth_number==$mergefrom) {
1523
                if ($auth_number==$mergefrom) {
1526
                my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1524
                    my $field_to = MARC::Field->new(($tag_to?$tag_to:$tag),
1527
		my $exclude='9';
1525
                        $field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1528
                foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1526
                    my $exclude='9';
1529
                    $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1527
                    foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1530
		    $exclude.= $subfield->[0];
1528
                        $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1531
                }
1529
                        $exclude.= $subfield->[0];
1532
		$exclude='['.$exclude.']';
1530
                    }
1533
#		add subfields in $field not included in @record_to
1531
                    $exclude='['.$exclude.']';
1534
		my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1532
                    #add subfields in $field not included in @record_to
1535
                foreach my $subfield (@restore) {
1533
                    my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1536
                   $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1534
                    foreach my $subfield (@restore) {
1537
		}
1535
                       $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1538
                $marcrecord->delete_field($field);
1536
                    }
1539
                $marcrecord->insert_grouped_field($field_to);            
1537
                    $marcrecord->delete_field($field);
1540
                $update=1;
1538
                    $marcrecord->insert_grouped_field($field_to);
1539
                    $update=1;
1541
                }
1540
                }
1542
            }#for each tag
1541
            }#for each tag
1543
        }#foreach tagfield
1542
        }#foreach tagfield
1543
1544
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1544
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1545
        my $biblionumber;
1545
        my $biblionumber;
1546
        if ($bibliotag<10){
1546
        if ($bibliotag<10){
Lines 1557-1614 sub merge { Link Here
1557
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1557
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1558
            $counteditedbiblio++;
1558
            $counteditedbiblio++;
1559
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1559
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1560
        }    
1560
        }
1561
    }#foreach $marc
1561
    }#foreach $marc
1562
    return $counteditedbiblio;  
1562
    return $counteditedbiblio;
1563
  # now, find every other authority linked with this authority
1563
}
1564
  # now, find every other authority linked with this authority
1565
#   my $oConnection=C4::Context->Zconn("authorityserver");
1566
#   my $query;
1567
# # att 9210               Auth-Internal-authtype
1568
# # att 9220               Auth-Internal-LN
1569
# # ccl.properties to add for authorities
1570
#   $query= "= ".$mergefrom;
1571
#   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1572
#   my $count=$oResult->size() if  ($oResult);
1573
#   my @reccache;
1574
#   my $z=0;
1575
#   while ( $z<$count ) {
1576
#   my $rec;
1577
#           $rec=$oResult->record($z);
1578
#       my $marcdata = $rec->raw();
1579
#   push @reccache, $marcdata;
1580
#   $z++;
1581
#   }
1582
#   $oResult->destroy();
1583
#   foreach my $marc(@reccache){
1584
#     my $update;
1585
#     my $marcrecord;
1586
#     $marcrecord = MARC::File::USMARC::decode($marc);
1587
#     foreach my $tagfield (@tags_using_authtype){
1588
#       $tagfield=substr($tagfield,0,3);
1589
#       my @tags = $marcrecord->field($tagfield);
1590
#       foreach my $tag (@tags){
1591
#         my $tagsubs=$tag->subfield("9");
1592
#     #warn "$tagfield:$tagsubs:$mergefrom";
1593
#         if ($tagsubs== $mergefrom) {
1594
#           $tag->update("9" =>$mergeto);
1595
#           foreach my $subfield (@record_to) {
1596
#     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1597
#             $tag->update($subfield->[0] =>$subfield->[1]);
1598
#           }#for $subfield
1599
#         }
1600
#         $marcrecord->delete_field($tag);
1601
#         $marcrecord->add_fields($tag);
1602
#         $update=1;
1603
#       }#for each tag
1604
#     }#foreach tagfield
1605
#     my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1606
#     if ($update==1){
1607
#       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1608
#     }
1609
# 
1610
#   }#foreach $marc
1611
}#sub
1612
1564
1613
=head2 get_auth_type_location
1565
=head2 get_auth_type_location
1614
1566
1615
- 

Return to bug 11700