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

(-)a/C4/AuthoritiesMarc.pm (-52 / +76 lines)
Lines 679-689 sub AddAuthority { Link Here
679
  my $auth_exists=0;
679
  my $auth_exists=0;
680
  my $oldRecord;
680
  my $oldRecord;
681
  if (!$authid) {
681
  if (!$authid) {
682
    my $sth=$dbh->prepare("select max(authid) from auth_header");
682
    my $sth = $dbh->prepare("select max(authid) from auth_header");
683
    $sth->execute;
683
    $sth->execute;
684
    ($authid)=$sth->fetchrow;
684
    ($authid) = $sth->fetchrow || 0;
685
    $authid=$authid+1;
685
    $authid++;
686
  ##Insert the recordID in MARC record 
686
687
    # Insert the recordID in MARC record 
687
    unless ($record->field('001') && $record->field('001')->data() eq $authid){
688
    unless ($record->field('001') && $record->field('001')->data() eq $authid){
688
        $record->delete_field($record->field('001'));
689
        $record->delete_field($record->field('001'));
689
        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
690
        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
Lines 1448-1466 Returns a list of biblionumbers of records that were modified. Link Here
1448
=cut
1449
=cut
1449
1450
1450
sub merge {
1451
sub merge {
1451
    my ($mergefrom, $MARCfrom, $mergeto, $MARCto) = @_;
1452
    my ( $mergefrom, $MARCfrom, $mergeto, $MARCto ) = @_;
1453
1452
    my @editedbiblios;
1454
    my @editedbiblios;
1453
    my $dbh = C4::Context->dbh;
1455
    my $dbh              = C4::Context->dbh;
1454
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1456
    my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1455
    my $authtypecodeto = GetAuthTypeCode($mergeto);
1457
    my $authtypecodeto   = GetAuthTypeCode($mergeto);
1456
1458
1457
    $MARCfrom ||= GetAuthority($mergefrom);
1459
    $MARCfrom ||= GetAuthority($mergefrom);
1458
    $MARCto ||= GetAuthority($mergeto);
1460
    $MARCto   ||= GetAuthority($mergeto);
1459
1461
1460
#     warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
1461
    # return if authority does not exist
1462
    # return if authority does not exist
1462
    return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0;
1463
    return "error MARCFROM not a marcrecord " . Data::Dumper::Dumper($MARCfrom)
1463
    return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0;
1464
      if scalar( $MARCfrom->fields() ) == 0;
1465
    return "error MARCTO not a marcrecord" . Data::Dumper::Dumper($MARCto)
1466
      if scalar( $MARCto->fields() ) == 0;
1467
1464
    # search the tag to report
1468
    # search the tag to report
1465
    my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1469
    my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1466
    $sth->execute($authtypecodefrom);
1470
    $sth->execute($authtypecodefrom);
Lines 1475-1569 sub merge { Link Here
1475
1479
1476
    my @reccache;
1480
    my @reccache;
1477
    # search all biblio tags using this authority.
1481
    # search all biblio tags using this authority.
1478
    #Getting marcbiblios impacted by the change.
1482
    # Getting marcbiblios impacted by the change.
1479
    #zebra connection
1483
    # zebra connection
1480
    my $oConnection=C4::Context->Zconn("biblioserver",0);
1484
    my $oConnection = C4::Context->Zconn( "biblioserver", 0 );
1481
    # We used to use XML syntax here, but that no longer works.
1485
    # We used to use XML syntax here, but that no longer works.
1482
    # Thankfully, we don't need it.
1486
    # Thankfully, we don't need it.
1483
    my $query;
1487
    my $query = "an=" . $mergefrom;
1484
    $query= "an=".$mergefrom;
1488
1485
    my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1489
    my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1486
    my $count = 0;
1490
    my $count = 0;
1487
    if  ($oResult) {
1491
    if ($oResult) {
1488
        $count=$oResult->size();
1492
        $count = $oResult->size();
1489
    }
1493
    }
1490
    my $z=0;
1494
1491
    while ( $z<$count ) {
1495
    my $z = 0;
1496
    while ( $z < $count ) {
1492
        my $marcrecordzebra = C4::Search::new_record_from_zebra(
1497
        my $marcrecordzebra = C4::Search::new_record_from_zebra(
1493
            'biblioserver',
1498
            'biblioserver',
1494
            $oResult->record($z)->raw()
1499
            $oResult->record($z)->raw()
1495
        );
1500
        );
1501
1496
        my ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", '' );
1502
        my ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", '' );
1503
1497
        my $i = ($biblionumbertagfield < 10)
1504
        my $i = ($biblionumbertagfield < 10)
1498
            ? $marcrecordzebra->field( $biblionumbertagfield )->data
1505
            ? $marcrecordzebra->field( $biblionumbertagfield )->data
1499
            : $marcrecordzebra->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
1506
            : $marcrecordzebra->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
1507
1500
        my $marcrecorddb = GetMarcBiblio($i);
1508
        my $marcrecorddb = GetMarcBiblio($i);
1509
1501
        push @reccache, $marcrecorddb;
1510
        push @reccache, $marcrecorddb;
1502
        $z++;
1511
        $z++;
1503
    }
1512
    }
1513
1504
    $oResult->destroy();
1514
    $oResult->destroy();
1515
1505
    #warn scalar(@reccache)." biblios to update";
1516
    #warn scalar(@reccache)." biblios to update";
1506
    # Get All candidate Tags for the change 
1517
    # Get All candidate Tags for the change 
1507
    # (This will reduce the search scope in marc records).
1518
    # (This will reduce the search scope in marc records).
1508
    $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1519
    $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1509
    $sth->execute($authtypecodefrom);
1520
    $sth->execute($authtypecodefrom);
1521
1510
    my @tags_using_authtype;
1522
    my @tags_using_authtype;
1511
    while (my ($tagfield) = $sth->fetchrow) {
1523
    while ( my ($tagfield) = $sth->fetchrow ) {
1512
        push @tags_using_authtype,$tagfield ;
1524
        push @tags_using_authtype, $tagfield;
1513
    }
1525
    }
1514
    my $tag_to=0;
1526
    my $tag_to = 0;
1515
    if ($authtypecodeto ne $authtypecodefrom){
1527
1528
    if ( $authtypecodeto ne $authtypecodefrom ) {
1516
        # If many tags, take the first
1529
        # If many tags, take the first
1517
        $sth->execute($authtypecodeto);
1530
        $sth->execute($authtypecodeto);
1518
        $tag_to=$sth->fetchrow;
1531
        $tag_to = $sth->fetchrow;
1519
    }
1532
    }
1533
1520
    # BulkEdit marc records
1534
    # BulkEdit marc records
1521
    # May be used as a template for a bulkedit field
1535
    # May be used as a template for a bulkedit field
1522
    foreach my $marcrecord(@reccache){
1536
    foreach my $marcrecord(@reccache){
1523
        my $update = 0;
1537
        my $update = 0;
1524
        foreach my $tagfield (@tags_using_authtype){
1538
        foreach my $tagfield (@tags_using_authtype) {
1525
            foreach my $field ($marcrecord->field($tagfield)){
1539
            foreach my $field ( $marcrecord->field($tagfield) ) {
1526
                # biblio is linked to authority with $9 subfield containing authid
1540
1527
                my $auth_number=$field->subfield("9");
1541
              # biblio is linked to authority with $9 subfield containing authid
1528
                my $tag=$field->tag();
1542
                my $auth_number = $field->subfield("9");
1529
                if ($auth_number==$mergefrom) {
1543
                my $tag         = $field->tag();
1530
                    my $field_to = MARC::Field->new(($tag_to?$tag_to:$tag),
1544
                if ( $auth_number == $mergefrom ) {
1531
                        $field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1545
                    my $field_to = MARC::Field->new(
1532
                    my $exclude='9';
1546
                        ( $tag_to ? $tag_to : $tag ), $field->indicator(1),
1533
                    foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1547
                        $field->indicator(2), "9" => $mergeto
1534
                        $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1548
                    );
1535
                        $exclude.= $subfield->[0];
1549
                    my $exclude = '9';
1550
                    foreach my $subfield ( grep { $_->[0] ne '9' } @record_to )
1551
                    {
1552
                        $field_to->add_subfields(
1553
                            $subfield->[0] => $subfield->[1] );
1554
                        $exclude .= $subfield->[0];
1536
                    }
1555
                    }
1537
                    $exclude='['.$exclude.']';
1556
                    $exclude = '[' . $exclude . ']';
1557
1538
                    #add subfields in $field not included in @record_to
1558
                    #add subfields in $field not included in @record_to
1539
                    my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1559
                    my @restore =
1560
                      grep { $_->[0] !~ /$exclude/ } $field->subfields();
1540
                    foreach my $subfield (@restore) {
1561
                    foreach my $subfield (@restore) {
1541
                       $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1562
                        $field_to->add_subfields(
1563
                            $subfield->[0] => $subfield->[1] );
1542
                    }
1564
                    }
1543
                    $marcrecord->delete_field($field);
1565
                    $marcrecord->delete_field($field);
1544
                    $marcrecord->insert_grouped_field($field_to);
1566
                    $marcrecord->insert_grouped_field($field_to);
1545
                    $update=1;
1567
                    $update = 1;
1546
                }
1568
                }
1547
            }#for each tag
1569
            }    #for each tag
1548
        }#foreach tagfield
1570
        }    #foreach tagfield
1549
1571
1550
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1572
        my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1551
        my $biblionumber;
1573
        my $biblionumber;
1552
        if ($bibliotag<10){
1574
1553
            $biblionumber=$marcrecord->field($bibliotag)->data;
1575
        if ( $bibliotag < 10 ) {
1576
            $biblionumber = $marcrecord->field($bibliotag)->data;
1554
        }
1577
        }
1555
        else {
1578
        else {
1556
            $biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
1579
            $biblionumber = $marcrecord->subfield( $bibliotag, $bibliosubf );
1557
        }
1580
        }
1558
        unless ($biblionumber){
1581
1559
            warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
1582
        unless ($biblionumber) {
1583
            warn "No biblionumber found for record: " . $marcrecord->as_formatted;
1560
            next;
1584
            next;
1561
        }
1585
        }
1562
        if ($update==1){
1586
1563
            &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1587
        if ( $update == 1 ) {
1588
            &ModBiblio( $marcrecord, $biblionumber, GetFrameworkCode($biblionumber) );
1564
            push @editedbiblios, $biblionumber;
1589
            push @editedbiblios, $biblionumber;
1565
        }
1590
        }
1566
    }#foreach $marc
1591
    }   #foreach $marc
1567
1592
1568
    if ( $mergefrom != $mergeto ) {
1593
    if ( $mergefrom != $mergeto ) {
1569
        my $number_of_authorities_deleted = DelAuthority($mergefrom);
1594
        my $number_of_authorities_deleted = DelAuthority($mergefrom);
1570
- 

Return to bug 11700