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

(-)a/C4/AuthoritiesMarc.pm (-4 / +14 lines)
Lines 693-699 sub DelAuthority { Link Here
693
    my $dbh=C4::Context->dbh;
693
    my $dbh=C4::Context->dbh;
694
694
695
    unless( C4::Context->preference('dontmerge') eq '1' ) {
695
    unless( C4::Context->preference('dontmerge') eq '1' ) {
696
        &merge( $authid, GetAuthority($authid) );
696
        &merge({ mergefrom => $authid, MARCfrom => GetAuthority($authid) });
697
    } else {
697
    } else {
698
        # save a record in need_merge_authorities table
698
        # save a record in need_merge_authorities table
699
        my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) VALUES (?,?)";
699
        my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) VALUES (?,?)";
Lines 725-731 sub ModAuthority { Link Here
725
  # In that case set system preference "dontmerge" to 1. Otherwise biblios will
725
  # In that case set system preference "dontmerge" to 1. Otherwise biblios will
726
  # be updated.
726
  # be updated.
727
  unless(C4::Context->preference('dontmerge') eq '1'){
727
  unless(C4::Context->preference('dontmerge') eq '1'){
728
      &merge($authid,$oldrecord,$authid,$record);
728
      &merge({ mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record });
729
  } else {
729
  } else {
730
      # save a record in need_merge_authorities table
730
      # save a record in need_merge_authorities table
731
      my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ".
731
      my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ".
Lines 1388-1394 sub AddAuthorityTrees{ Link Here
1388
1388
1389
=head2 merge
1389
=head2 merge
1390
1390
1391
  $count = merge ( mergefrom, $MARCfrom, [$mergeto, $MARCto] )
1391
    $count = merge({
1392
        mergefrom => mergefrom,
1393
        MARCfrom => $MARCfrom,
1394
        [ mergeto => $mergeto, ]
1395
        [ MARCto => $MARCto, ]
1396
    });
1392
1397
1393
Merge biblios linked to authority $mergefrom.
1398
Merge biblios linked to authority $mergefrom.
1394
If $mergeto equals mergefrom, the linked biblio field is updated.
1399
If $mergeto equals mergefrom, the linked biblio field is updated.
Lines 1401-1407 authority type, merge also supports moving to another authority type. Link Here
1401
=cut
1406
=cut
1402
1407
1403
sub merge {
1408
sub merge {
1404
    my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1409
    my ( $params ) = @_;
1410
    my $mergefrom = $params->{mergefrom};
1411
    my $MARCfrom = $params->{MARCfrom};
1412
    my $mergeto = $params->{mergeto};
1413
    my $MARCto = $params->{MARCto};
1414
1405
    return 0 unless $mergefrom > 0; # prevent abuse
1415
    return 0 unless $mergefrom > 0; # prevent abuse
1406
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1416
    my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);        
1407
    my $dbh=C4::Context->dbh;
1417
    my $dbh=C4::Context->dbh;
(-)a/authorities/merge.pl (-1 / +1 lines)
Lines 64-70 if ($merge) { Link Here
64
    # Now merge for biblios attached to $recordid2
64
    # Now merge for biblios attached to $recordid2
65
    # We ignore dontmerge now, since recordid2 is deleted
65
    # We ignore dontmerge now, since recordid2 is deleted
66
    my $MARCfrom = GetAuthority( $recordid2 );
66
    my $MARCfrom = GetAuthority( $recordid2 );
67
    merge( $recordid2, $MARCfrom, $recordid1, $record );
67
    merge({ mergefrom => $recordid2, MARCfrom => $MARCfrom, mergeto => $recordid1, MARCto => $record });
68
68
69
    # Deleting the other record
69
    # Deleting the other record
70
    DelAuthority( $recordid2 );
70
    DelAuthority( $recordid2 );
(-)a/misc/migration_tools/merge_authority.pl (-3 / +3 lines)
Lines 86-101 if ($batch) { Link Here
86
      print "managing $authid\n" if $verbose;
86
      print "managing $authid\n" if $verbose;
87
      my $MARCauth = GetAuthority( $authid );
87
      my $MARCauth = GetAuthority( $authid );
88
      if( $MARCauth ) {
88
      if( $MARCauth ) {
89
          merge( $authid, $MARCauth, $authid, $MARCauth );
89
          merge({ mergefrom => $authid, MARCfrom => $MARCauth, mergeto => $authid, MARCto => $MARCauth });
90
      } else {
90
      } else {
91
          merge( $authid, undef ); # handle a delete
91
          merge({ mergefrom => $authid }); # handle a delete
92
      }
92
      }
93
  }
93
  }
94
  $dbh->do("update need_merge_authorities set done=1 where done=2"); #DONE
94
  $dbh->do("update need_merge_authorities set done=1 where done=2"); #DONE
95
} else {
95
} else {
96
  my $MARCfrom = GetAuthority($mergefrom);
96
  my $MARCfrom = GetAuthority($mergefrom);
97
  my $MARCto = GetAuthority($mergeto);
97
  my $MARCto = GetAuthority($mergeto);
98
  &merge($mergefrom,$MARCfrom,$mergeto,$MARCto);
98
  &merge({ mergefrom => $mergefrom, MARCfrom => $MARCfrom, mergeto => $mergeto, MARCto => $MARCto });
99
  #Could add mergefrom authority to mergeto rejected forms before deletion 
99
  #Could add mergefrom authority to mergeto rejected forms before deletion 
100
  DelAuthority($mergefrom) if ($mergefrom != $mergeto);
100
  DelAuthority($mergefrom) if ($mergefrom != $mergeto);
101
}
101
}
(-)a/t/db_dependent/Authorities/Merge.t (-6 / +5 lines)
Lines 60-66 subtest 'Test merge A1 to A2 (within same authtype)' => sub { Link Here
60
    # Time to merge
60
    # Time to merge
61
    @zebrarecords = ( $biblio1, $biblio2 );
61
    @zebrarecords = ( $biblio1, $biblio2 );
62
    $index = 0;
62
    $index = 0;
63
    my $rv = C4::AuthoritiesMarc::merge( $authid2, $auth2, $authid1, $auth1 );
63
    my $rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid2, MARCfrom => $auth2, mergeto => $authid1, MARCto => $auth1 });
64
    is( $rv, 1, 'We expect one biblio record (out of two) to be updated' );
64
    is( $rv, 1, 'We expect one biblio record (out of two) to be updated' );
65
65
66
    # Check the results
66
    # Check the results
Lines 105-111 subtest 'Test merge A1 to modified A1, test strict mode' => sub { Link Here
105
    @zebrarecords = ( $MARC1, $MARC2 );
105
    @zebrarecords = ( $MARC1, $MARC2 );
106
    $index = 0;
106
    $index = 0;
107
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
107
    t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose');
108
    my $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new );
108
    my $rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new });
109
    is( $rv, 2, 'Both records are updated now' );
109
    is( $rv, 2, 'Both records are updated now' );
110
110
111
    #Check the results
111
    #Check the results
Lines 125-131 subtest 'Test merge A1 to modified A1, test strict mode' => sub { Link Here
125
    ModBiblio( $MARC1, $biblionumber1, '' );
125
    ModBiblio( $MARC1, $biblionumber1, '' );
126
    @zebrarecords = ( $MARC1 );
126
    @zebrarecords = ( $MARC1 );
127
    $index = 0;
127
    $index = 0;
128
    $rv = C4::AuthoritiesMarc::merge( $authid1, $auth1old, $authid1, $auth1new );
128
    $rv = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1old, mergeto => $authid1, MARCto => $auth1new });
129
    $biblio1 = GetMarcBiblio($biblionumber1);
129
    $biblio1 = GetMarcBiblio($biblionumber1);
130
    is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' );
130
    is( $biblio1->field(109)->subfield('b'), undef, 'Subfield overwritten in strict mode' );
131
    compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' );
131
    compare_fields( $MARC1, $biblio1, { 609 => 1 }, 'count' );
Lines 172-178 subtest 'Test merge A1 to B1 (changing authtype)' => sub { Link Here
172
    # Time to merge
172
    # Time to merge
173
    @zebrarecords = ( $marc );
173
    @zebrarecords = ( $marc );
174
    $index = 0;
174
    $index = 0;
175
    my $retval = C4::AuthoritiesMarc::merge( $authid1, $auth1, $authid2, $auth2 );
175
    my $retval = C4::AuthoritiesMarc::merge({ mergefrom => $authid1, MARCfrom => $auth1, mergeto => $authid2, MARCto => $auth2 });
176
    is( $retval, 1, 'We touched only one biblio' );
176
    is( $retval, 1, 'We touched only one biblio' );
177
177
178
    # Get new marc record for compares
178
    # Get new marc record for compares
Lines 256-262 subtest 'Merging authorities should handle deletes (BZ 18070)' => sub { Link Here
256
    C4::Context->dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid1 );
256
    C4::Context->dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid1 );
257
    @zebrarecords = ( $marc1 );
257
    @zebrarecords = ( $marc1 );
258
    $index = 0;
258
    $index = 0;
259
    merge( $authid1, undef );
259
    merge({ mergefrom => $authid1 });
260
    # Final check
260
    # Final check
261
    $marc1 = C4::Biblio::GetMarcBiblio( $biblionumber );
261
    $marc1 = C4::Biblio::GetMarcBiblio( $biblionumber );
262
    is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' );
262
    is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' );
263
- 

Return to bug 9988