# BulkEdit marc records
# May be used as a template for a bulkedit field
my $overwrite = C4::Context->preference( 'AuthorityMergeMode' ) eq 'strict';
+ my $skip_subfields = $overwrite
+ # This hash contains all subfields from the authority report fields
+ # Including $MARCfrom as well as $MARCto
+ # We only need it in loose merge mode; replaces the former $exclude
+ ? {}
+ : { map { ( $_->[0], 1 ); } ( @record_from, @record_to ) };
foreach my $marcrecord(@reccache){
my $update = 0;
foreach my $tagfield (@$tags_using_authtype){
$field->indicator(2),
"9" => $mergeto,
);
- my $exclude='9';
foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
$field_to->add_subfields($subfield->[0] =>$subfield->[1]);
- $exclude.= $subfield->[0];
}
- $exclude='['.$exclude.']';
-# add subfields in $field not included in @record_to
- my @restore= $overwrite ? () : grep {$_->[0]!~/$exclude/} $field->subfields();
- foreach my $subfield (@restore) {
- $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
- }
+ if( !$overwrite ) {
+ # add subfields back in loose mode, check skip_subfields
+ foreach my $subfield ( $field->subfields ) {
+ next if $skip_subfields->{ $subfield->[0] };
+ $field_to->add_subfields( $subfield->[0], $subfield->[1] );
+ }
+ }
if( $tags_new ) {
$marcrecord->delete_field( $field );
append_fields_ordered( $marcrecord, $field_to );
# Tests were aimed for bug 9988, moved to 17909 in adjusted form
# Would not encourage this type of merge, but we should test what we offer
# The merge routine still needs the fixes on bug 17913
- plan tests => 12;
+ plan tests => 13;
# create two auth recs of different type
my $auth1 = MARC::Record->new;
is( $newbiblio->subfield( '112', 'c' ),
$auth2->subfield( '112', 'c' ), 'Check new 112c' );
+ # Check 112b; this subfield was cleared when moving from 109 to 112
+ # Note that this fix only applies to the current loose mode only
+ is( $newbiblio->subfield( '112', 'b' ), undef,
+ 'Merge respects a cleared subfield in loose mode' );
+
# Check the original 612
is( ( $newbiblio->field('612') )[0]->subfield( 'a' ),
$oldbiblio->subfield( '612', 'a' ), 'Check untouched 612a' );