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

(-)a/C4/AuthoritiesMarc.pm (-76 / +27 lines)
Lines 1398-1406 Then we should add some new parameter : bibliotargettag, authtargettag Link Here
1398
=cut
1398
=cut
1399
1399
1400
sub merge {
1400
sub merge {
1401
    my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1401
    my ($mergefrom, $MARCfrom, $mergeto, $MARCto) = @_;
1402
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1402
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1403
    my $dbh=C4::Context->dbh;
1403
    my $dbh = C4::Context->dbh;
1404
    my $authtypefrom = Koha::Authority::Types->find($mergefrom);
1404
    my $authtypefrom = Koha::Authority::Types->find($mergefrom);
1405
    my $authtypeto   = Koha::Authority::Types->find($mergeto);
1405
    my $authtypeto   = Koha::Authority::Types->find($mergeto);
1406
1406
Lines 1414-1420 sub merge { Link Here
1414
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1414
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1415
    my @record_from;
1415
    my @record_from;
1416
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1416
    @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1417
    
1417
1418
    my @reccache;
1418
    my @reccache;
1419
    # search all biblio tags using this authority.
1419
    # search all biblio tags using this authority.
1420
    #Getting marcbiblios impacted by the change.
1420
    #Getting marcbiblios impacted by the change.
Lines 1453-1494 sub merge { Link Here
1453
    while (my ($tagfield) = $sth->fetchrow) {
1453
    while (my ($tagfield) = $sth->fetchrow) {
1454
        push @tags_using_authtype,$tagfield ;
1454
        push @tags_using_authtype,$tagfield ;
1455
    }
1455
    }
1456
    my $tag_to=0;  
1456
    my $tag_to=0;
1457
    if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){
1457
    if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){
1458
        # If many tags, take the first
1458
        # If many tags, take the first
1459
        $sth->execute($authtypeto->authtypecode);
1459
        $sth->execute($authtypeto->authtypecode);
1460
        $tag_to=$sth->fetchrow;
1460
        $tag_to=$sth->fetchrow;
1461
        #warn $tag_to;    
1461
    }
1462
    }  
1463
    # BulkEdit marc records
1462
    # BulkEdit marc records
1464
    # May be used as a template for a bulkedit field  
1463
    # May be used as a template for a bulkedit field
1465
    foreach my $marcrecord(@reccache){
1464
    foreach my $marcrecord(@reccache){
1466
        my $update = 0;
1465
        my $update = 0;
1467
        foreach my $tagfield (@tags_using_authtype){
1466
        foreach my $tagfield (@tags_using_authtype){
1468
#             warn "tagfield : $tagfield ";
1469
            foreach my $field ($marcrecord->field($tagfield)){
1467
            foreach my $field ($marcrecord->field($tagfield)){
1470
                # biblio is linked to authority with $9 subfield containing authid
1468
                # biblio is linked to authority with $9 subfield containing authid
1471
                my $auth_number=$field->subfield("9");
1469
                my $auth_number=$field->subfield("9");
1472
                my $tag=$field->tag();          
1470
                my $tag=$field->tag();
1473
                if ($auth_number==$mergefrom) {
1471
                if ($auth_number==$mergefrom) {
1474
                my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1472
                    my $field_to = MARC::Field->new(($tag_to?$tag_to:$tag),
1475
		my $exclude='9';
1473
                        $field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1476
                foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1474
                    my $exclude='9';
1477
                    $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1475
                    foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1478
		    $exclude.= $subfield->[0];
1476
                        $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1479
                }
1477
                        $exclude.= $subfield->[0];
1480
		$exclude='['.$exclude.']';
1478
                    }
1481
#		add subfields in $field not included in @record_to
1479
                    $exclude='['.$exclude.']';
1482
		my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1480
                    #add subfields in $field not included in @record_to
1483
                foreach my $subfield (@restore) {
1481
                    my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1484
                   $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1482
                    foreach my $subfield (@restore) {
1485
		}
1483
                       $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1486
                $marcrecord->delete_field($field);
1484
                    }
1487
                $marcrecord->insert_grouped_field($field_to);            
1485
                    $marcrecord->delete_field($field);
1488
                $update=1;
1486
                    $marcrecord->insert_grouped_field($field_to);
1487
                    $update=1;
1489
                }
1488
                }
1490
            }#for each tag
1489
            }#for each tag
1491
        }#foreach tagfield
1490
        }#foreach tagfield
1491
1492
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1492
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1493
        my $biblionumber;
1493
        my $biblionumber;
1494
        if ($bibliotag<10){
1494
        if ($bibliotag<10){
Lines 1505-1562 sub merge { Link Here
1505
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1505
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1506
            $counteditedbiblio++;
1506
            $counteditedbiblio++;
1507
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1507
            warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1508
        }    
1508
        }
1509
    }#foreach $marc
1509
    }#foreach $marc
1510
    return $counteditedbiblio;  
1510
    return $counteditedbiblio;
1511
  # now, find every other authority linked with this authority
1511
}
1512
  # now, find every other authority linked with this authority
1513
#   my $oConnection=C4::Context->Zconn("authorityserver");
1514
#   my $query;
1515
# # att 9210               Auth-Internal-authtype
1516
# # att 9220               Auth-Internal-LN
1517
# # ccl.properties to add for authorities
1518
#   $query= "= ".$mergefrom;
1519
#   my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1520
#   my $count=$oResult->size() if  ($oResult);
1521
#   my @reccache;
1522
#   my $z=0;
1523
#   while ( $z<$count ) {
1524
#   my $rec;
1525
#           $rec=$oResult->record($z);
1526
#       my $marcdata = $rec->raw();
1527
#   push @reccache, $marcdata;
1528
#   $z++;
1529
#   }
1530
#   $oResult->destroy();
1531
#   foreach my $marc(@reccache){
1532
#     my $update;
1533
#     my $marcrecord;
1534
#     $marcrecord = MARC::File::USMARC::decode($marc);
1535
#     foreach my $tagfield (@tags_using_authtype){
1536
#       $tagfield=substr($tagfield,0,3);
1537
#       my @tags = $marcrecord->field($tagfield);
1538
#       foreach my $tag (@tags){
1539
#         my $tagsubs=$tag->subfield("9");
1540
#     #warn "$tagfield:$tagsubs:$mergefrom";
1541
#         if ($tagsubs== $mergefrom) {
1542
#           $tag->update("9" =>$mergeto);
1543
#           foreach my $subfield (@record_to) {
1544
#     #        warn "$subfield,$subfield->[0],$subfield->[1]";
1545
#             $tag->update($subfield->[0] =>$subfield->[1]);
1546
#           }#for $subfield
1547
#         }
1548
#         $marcrecord->delete_field($tag);
1549
#         $marcrecord->add_fields($tag);
1550
#         $update=1;
1551
#       }#for each tag
1552
#     }#foreach tagfield
1553
#     my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1554
#     if ($update==1){
1555
#       &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1556
#     }
1557
# 
1558
#   }#foreach $marc
1559
}#sub
1560
1512
1561
=head2 get_auth_type_location
1513
=head2 get_auth_type_location
1562
1514
1563
- 

Return to bug 11700