@@ -, +, @@ --- C4/AuthoritiesMarc.pm | 68 +++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 29 deletions(-) --- a/C4/AuthoritiesMarc.pm +++ a/C4/AuthoritiesMarc.pm @@ -1517,37 +1517,45 @@ sub merge { # biblio is linked to authority with $9 subfield containing authid my $auth_number=$field->subfield("9"); my $tag=$field->tag(); - if ($auth_number==$mergefrom) { - # If merging distinct authorities, - # look if field to add already exists in the record - # in order to avoid a duplicate. - my $field_to_exists; - if ( $mergefrom != $mergeto ) { - foreach ( $marcrecord->field( $tag_to ? $tag_to : $tag ) ) { - if ( $_->subfield('9') && $_->subfield('9') == $mergeto ) { - $field_to_exists = 1; - last; + if ( $auth_number == $mergefrom ) { + + # If merging distinct authorities, + # look if field to add already exists in the record + # in order to avoid a duplicate. + my $field_to_exists; + if ( $mergefrom != $mergeto ) { + foreach ( $marcrecord->field( $tag_to ? $tag_to : $tag ) ) { + if ( $_->subfield('9') && $_->subfield('9') == $mergeto ) { + $field_to_exists = 1; + last; + } } } - } - # Go editing - $marcrecord->delete_field($field); - unless ($field_to_exists) { - my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$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= grep {$_->[0]!~/$exclude/} $field->subfields(); - foreach my $subfield (@restore) { - $field_to->add_subfields($subfield->[0] =>$subfield->[1]); - } - $marcrecord->insert_grouped_field($field_to); - } - $update=1; + + # Go editing + $marcrecord->delete_field($field); + unless ($field_to_exists) { + my $field_to = MARC::Field->new( + ( $tag_to ? $tag_to : $tag ), + $field->indicator(1), + $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 = + grep { $_->[0] !~ /$exclude/ } $field->subfields(); + foreach my $subfield (@restore) { + $field_to->add_subfields( $subfield->[0] => $subfield->[1] ); + } + $marcrecord->insert_grouped_field($field_to); + } + $update = 1; } }#for each tag }#foreach tagfield @@ -1653,6 +1661,8 @@ sub get_auth_type_location { END { } # module clean-up code here (global destructor) + + 1; __END__ --