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

(-)a/C4/AuthoritiesMarc.pm (-3 / +11 lines)
Lines 1443-1448 sub merge { Link Here
1443
1443
1444
    my @record_to;
1444
    my @record_to;
1445
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to);
1445
    @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $auth_tag_to_report_to && $MARCto && $MARCto->field($auth_tag_to_report_to);
1446
    # Exceptional: If MARCto and authtypeto exist but $auth_tag_to_report_to
1447
    # is empty, make sure that $9 and $a remain (instead of clearing the
1448
    # reference) in order to allow for data recovery.
1449
    # Note: We need $a too, since a single $9 does not pass ModBiblio.
1450
    if( $MARCto && $authtypeto && !@record_to  ) {
1451
        push @record_to, [ 'a', ' ' ]; # do not remove the space
1452
    }
1453
1446
    my @record_from;
1454
    my @record_from;
1447
    if( !$authfrom && $MARCfrom && $MARCfrom->field('1..','2..') ) {
1455
    if( !$authfrom && $MARCfrom && $MARCfrom->field('1..','2..') ) {
1448
    # postponed merge, authfrom was deleted and MARCfrom only contains the old reporting tag (and possibly a 100 for UNIMARC)
1456
    # postponed merge, authfrom was deleted and MARCfrom only contains the old reporting tag (and possibly a 100 for UNIMARC)
Lines 1457-1463 sub merge { Link Here
1457
    # For a deleted authority record, we scan all auth controlled fields
1465
    # For a deleted authority record, we scan all auth controlled fields
1458
    my $dbh = C4::Context->dbh;
1466
    my $dbh = C4::Context->dbh;
1459
    my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?";
1467
    my $sql = "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode=?";
1460
    my $tags_using_authtype = $authtypefrom ? $dbh->selectcol_arrayref( $sql, undef, ( $authtypefrom->authtypecode )) : $dbh->selectcol_arrayref( "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode IS NOT NULL AND authtypecode<>''" );
1468
    my $tags_using_authtype = $authtypefrom && $authtypefrom->authtypecode ? $dbh->selectcol_arrayref( $sql, undef, ( $authtypefrom->authtypecode )) : $dbh->selectcol_arrayref( "SELECT DISTINCT tagfield FROM marc_subfield_structure WHERE authtypecode IS NOT NULL AND authtypecode<>''" );
1461
    my $tags_new;
1469
    my $tags_new;
1462
    if( $authtypeto && ( !$authtypefrom || $authtypeto->authtypecode ne $authtypefrom->authtypecode )) {
1470
    if( $authtypeto && ( !$authtypefrom || $authtypeto->authtypecode ne $authtypefrom->authtypecode )) {
1463
        $tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode ));
1471
        $tags_new = $dbh->selectcol_arrayref( $sql, undef, ( $authtypeto->authtypecode ));
Lines 1493-1499 sub merge { Link Here
1493
                    $update = 1;
1501
                    $update = 1;
1494
                    next;
1502
                    next;
1495
                }
1503
                }
1496
                my $newtag = $tags_new
1504
                my $newtag = $tags_new && @$tags_new
1497
                  ? _merge_newtag( $tag, $tags_new )
1505
                  ? _merge_newtag( $tag, $tags_new )
1498
                  : $tag;
1506
                  : $tag;
1499
                my $field_to = MARC::Field->new(
1507
                my $field_to = MARC::Field->new(
Lines 1512-1518 sub merge { Link Here
1512
                        $field_to->add_subfields( $subfield->[0], $subfield->[1] );
1520
                        $field_to->add_subfields( $subfield->[0], $subfield->[1] );
1513
                    }
1521
                    }
1514
                }
1522
                }
1515
                if ($tags_new) {
1523
                if ($tags_new && @$tags_new) {
1516
                    $marcrecord->delete_field($field);
1524
                    $marcrecord->delete_field($field);
1517
                    append_fields_ordered( $marcrecord, $field_to );
1525
                    append_fields_ordered( $marcrecord, $field_to );
1518
                } else {
1526
                } else {
(-)a/t/db_dependent/Authority/Merge.t (-2 / +32 lines)
Lines 4-10 Link Here
4
4
5
use Modern::Perl;
5
use Modern::Perl;
6
6
7
use Test::More tests => 7;
7
use Test::More tests => 8;
8
8
9
use Getopt::Long;
9
use Getopt::Long;
10
use MARC::Record;
10
use MARC::Record;
Lines 329-334 subtest "Test some specific postponed merge issues" => sub { Link Here
329
    is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' );
329
    is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' );
330
};
330
};
331
331
332
subtest "Graceful resolution of missing reporting tag" => sub {
333
    plan tests => 2;
334
335
    # Simulate merge with authority in Default fw without reporting tag
336
    # We expect data loss in biblio, but we keep $a and the reference in $9
337
    # in order to allow a future merge to restore data.
338
339
    # Accomplish the above by clearing reporting tag in $authtype2
340
    my $fw2 = Koha::Authority::Types->find( $authtype2 );
341
    $fw2->auth_tag_to_report('')->store;
342
343
    my $authmarc = MARC::Record->new;
344
    $authmarc->append_fields( MARC::Field->new( '109', '', '', 'a' => 'aa', b => 'bb' ));
345
    my $id1 = AddAuthority( $authmarc, undef, $authtype1 );
346
    my $id2 = AddAuthority( $authmarc, undef, $authtype2 );
347
348
    my $biblio = MARC::Record->new;
349
    $biblio->append_fields(
350
        MARC::Field->new( '609', '', '', a => 'aa', 9 => $id1 ),
351
    );
352
    my ( $biblionumber ) = C4::Biblio::AddBiblio( $biblio, '' );
353
354
    # Merge
355
    merge({ mergefrom => $id1, MARCfrom => $authmarc, mergeto => $id2, MARCto => $authmarc, biblionumbers => [ $biblionumber ] });
356
    $biblio = C4::Biblio::GetMarcBiblio( $biblionumber );
357
    is( $biblio->subfield('612', '9'), $id2, 'id2 saved in $9' );
358
    is( $biblio->subfield('612', 'a'), ' ', 'Kept an empty $a too' );
359
360
    $fw2->auth_tag_to_report('112')->store;
361
};
362
332
sub set_mocks {
363
sub set_mocks {
333
    # After we removed the Zebra code from merge, we only need to mock
364
    # After we removed the Zebra code from merge, we only need to mock
334
    # get_usage_count and linked_biblionumbers here.
365
    # get_usage_count and linked_biblionumbers here.
335
- 

Return to bug 17380