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

(-)a/C4/AuthoritiesMarc.pm (-81 / +32 lines)
Lines 1432-1440 Then we should add some new parameter : bibliotargettag, authtargettag Link Here
1432
=cut
1432
=cut
1433
1433
1434
sub merge {
1434
sub merge {
1435
    my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1435
    my ($mergefrom, $MARCfrom, $mergeto, $MARCto) = @_;
1436
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1436
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);
1437
    my $dbh=C4::Context->dbh;
1437
    my $dbh = C4::Context->dbh;
1438
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1438
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1439
    my $authtypecodeto = GetAuthTypeCode($mergeto);
1439
    my $authtypecodeto = GetAuthTypeCode($mergeto);
1440
#     warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
1440
#     warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
Lines 1447-1458 sub merge { Link Here
1447
    my ($auth_tag_to_report_from) = $sth->fetchrow;
1447
    my ($auth_tag_to_report_from) = $sth->fetchrow;
1448
    $sth->execute($authtypecodeto);
1448
    $sth->execute($authtypecodeto);
1449
    my ($auth_tag_to_report_to) = $sth->fetchrow;
1449
    my ($auth_tag_to_report_to) = $sth->fetchrow;
1450
    
1450
1451
    my @record_to;
1451
    my @record_to;
1452
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1452
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1453
    my @record_from;
1453
    my @record_from;
1454
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1454
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1455
    
1455
1456
    my @reccache;
1456
    my @reccache;
1457
    # search all biblio tags using this authority.
1457
    # search all biblio tags using this authority.
1458
    #Getting marcbiblios impacted by the change.
1458
    #Getting marcbiblios impacted by the change.
Lines 1491-1532 sub merge { Link Here
1491
    while (my ($tagfield) = $sth->fetchrow) {
1491
    while (my ($tagfield) = $sth->fetchrow) {
1492
        push @tags_using_authtype,$tagfield ;
1492
        push @tags_using_authtype,$tagfield ;
1493
    }
1493
    }
1494
    my $tag_to=0;  
1494
    my $tag_to=0;
1495
    if ($authtypecodeto ne $authtypecodefrom){  
1495
    if ($authtypecodeto ne $authtypecodefrom){
1496
        # If many tags, take the first
1496
        # If many tags, take the first
1497
        $sth->execute($authtypecodeto);    
1497
        $sth->execute($authtypecodeto);
1498
        $tag_to=$sth->fetchrow;
1498
        $tag_to=$sth->fetchrow;
1499
        #warn $tag_to;    
1499
    }
1500
    }  
1501
    # BulkEdit marc records
1500
    # BulkEdit marc records
1502
    # May be used as a template for a bulkedit field  
1501
    # May be used as a template for a bulkedit field
1503
    foreach my $marcrecord(@reccache){
1502
    foreach my $marcrecord(@reccache){
1504
        my $update;           
1503
        my $update;
1505
        foreach my $tagfield (@tags_using_authtype){
1504
        foreach my $tagfield (@tags_using_authtype){
1506
#             warn "tagfield : $tagfield ";
1507
            foreach my $field ($marcrecord->field($tagfield)){
1505
            foreach my $field ($marcrecord->field($tagfield)){
1508
                # biblio is linked to authority with $9 subfield containing authid
1506
                # biblio is linked to authority with $9 subfield containing authid
1509
                my $auth_number=$field->subfield("9");
1507
                my $auth_number=$field->subfield("9");
1510
                my $tag=$field->tag();          
1508
                my $tag=$field->tag();
1511
                if ($auth_number==$mergefrom) {
1509
                if ($auth_number==$mergefrom) {
1512
                my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1510
                    my $field_to = MARC::Field->new(($tag_to?$tag_to:$tag),
1513
		my $exclude='9';
1511
                        $field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1514
                foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1512
                    my $exclude='9';
1515
                    $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1513
                    foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1516
		    $exclude.= $subfield->[0];
1514
                        $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1517
                }
1515
                        $exclude.= $subfield->[0];
1518
		$exclude='['.$exclude.']';
1516
                    }
1519
#		add subfields in $field not included in @record_to
1517
                    $exclude='['.$exclude.']';
1520
		my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1518
                    #add subfields in $field not included in @record_to
1521
                foreach my $subfield (@restore) {
1519
                    my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1522
                   $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1520
                    foreach my $subfield (@restore) {
1523
		}
1521
                       $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1524
                $marcrecord->delete_field($field);
1522
                    }
1525
                $marcrecord->insert_grouped_field($field_to);            
1523
                    $marcrecord->delete_field($field);
1526
                $update=1;
1524
                    $marcrecord->insert_grouped_field($field_to);
1525
                    $update=1;
1527
                }
1526
                }
1528
            }#for each tag
1527
            }#for each tag
1529
        }#foreach tagfield
1528
        }#foreach tagfield
1529
1530
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1530
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1531
        my $biblionumber;
1531
        my $biblionumber;
1532
        if ($bibliotag<10){
1532
        if ($bibliotag<10){
Lines 1543-1600 sub merge { Link Here
1543
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1543
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1544
            $counteditedbiblio++;
1544
            $counteditedbiblio++;
1545
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1545
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1546
        }    
1546
        }
1547
    }#foreach $marc
1547
    }#foreach $marc
1548
    return $counteditedbiblio;  
1548
    return $counteditedbiblio;
1549
  # now, find every other authority linked with this authority
1549
}
1550
  # now, find every other authority linked with this authority
1551
#   my $oConnection=C4::Context->Zconn("authorityserver");
1552
#   my $query;
1553
# # att 9210               Auth-Internal-authtype
1554
# # att 9220               Auth-Internal-LN
1555
# # ccl.properties to add for authorities
1556
#   $query= "= ".$mergefrom;
1557
#   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1558
#   my $count=$oResult->size() if  ($oResult);
1559
#   my @reccache;
1560
#   my $z=0;
1561
#   while ( $z<$count ) {
1562
#   my $rec;
1563
#           $rec=$oResult->record($z);
1564
#       my $marcdata = $rec->raw();
1565
#   push @reccache, $marcdata;
1566
#   $z++;
1567
#   }
1568
#   $oResult->destroy();
1569
#   foreach my $marc(@reccache){
1570
#     my $update;
1571
#     my $marcrecord;
1572
#     $marcrecord = MARC::File::USMARC::decode($marc);
1573
#     foreach my $tagfield (@tags_using_authtype){
1574
#       $tagfield=substr($tagfield,0,3);
1575
#       my @tags = $marcrecord->field($tagfield);
1576
#       foreach my $tag (@tags){
1577
#         my $tagsubs=$tag->subfield("9");
1578
#     #warn "$tagfield:$tagsubs:$mergefrom";
1579
#         if ($tagsubs== $mergefrom) {
1580
#           $tag->update("9" =>$mergeto);
1581
#           foreach my $subfield (@record_to) {
1582
#     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1583
#             $tag->update($subfield->[0] =>$subfield->[1]);
1584
#           }#for $subfield
1585
#         }
1586
#         $marcrecord->delete_field($tag);
1587
#         $marcrecord->add_fields($tag);
1588
#         $update=1;
1589
#       }#for each tag
1590
#     }#foreach tagfield
1591
#     my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1592
#     if ($update==1){
1593
#       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1594
#     }
1595
# 
1596
#   }#foreach $marc
1597
}#sub
1598
1550
1599
=head2 get_auth_type_location
1551
=head2 get_auth_type_location
1600
1552
1601
- 

Return to bug 11700