@@ -, +, @@ --- Koha/SimpleMARC.pm | 13 +++++++------ t/SimpleMARC.t | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 22 deletions(-) --- a/Koha/SimpleMARC.pm +++ a/Koha/SimpleMARC.pm @@ -582,6 +582,13 @@ sub _copy_move_field { @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers; } + if ( $action eq 'replace' ) { + my @to_fields = $record->field( $toFieldName ); + for my $to_field ( @to_fields ) { + $record->delete_field( $to_field ); + } + } + for my $from_field ( @from_fields ) { my $new_field = $from_field->clone; $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4 @@ -595,12 +602,6 @@ sub _copy_move_field { if ( $action eq 'move' ) { $record->delete_field( $from_field ) } - elsif ( $action eq 'replace' ) { - my @to_fields = $record->field( $toFieldName ); - if ( @to_fields ) { - $record->delete_field( $to_fields[0] ); - } - } $record->insert_grouped_field( $new_field ); } } --- a/t/SimpleMARC.t +++ a/t/SimpleMARC.t @@ -384,7 +384,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'Computer programming.', 'Computer algorithms.' ], + [ 'Computer algorithms.' , 'Computer programming.' ], 'Copy multivalued field' ); delete_field( { record => $record, field => '651' } ); @@ -445,7 +445,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.' ], + [ 'The art of algorithms.', 'The art of programming.' ], 'Copy field using regex' ); delete_field( { record => $record, field => '651' } ); @@ -464,7 +464,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The mistake of programming.', 'The mistake of algorithms.' ], + [ 'The mistake of algorithms.', 'The mistake of programming.' ], 'Copy fields using regex on existing fields' ); delete_field( { record => $record, field => '651' } ); @@ -483,7 +483,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.', ], + [ 'The art of algorithms.', 'The art of programming.', ], 'Copy all fields using regex' ); delete_field( { record => $record, field => '651' } ); @@ -531,7 +531,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '652', subfield => 'a' } ); is_deeply( \@fields_652a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy field using regex' ); @@ -549,7 +549,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '653', subfield => 'a' } ); is_deeply( \@fields_653a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy field using regex' ); @@ -567,7 +567,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '654', subfield => 'a' } ); is_deeply( \@fields_654a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy field using regex' ); @@ -585,7 +585,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '655', subfield => 'a' } ); is_deeply( \@fields_655a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy field using regex' ); @@ -958,7 +958,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'Computer programming.', 'Computer algorithms.' ], + [ 'Computer algorithms.', 'Computer programming.' ], 'Copy and replace multivalued field (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1018,7 +1018,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.' ], + [ 'The art of algorithms.', 'The art of programming.' ], 'Copy and replace field using regex (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1037,7 +1037,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The mistake of programming.', 'The mistake of algorithms.' ], + [ 'The mistake of algorithms.', 'The mistake of programming.' ], 'Copy and replace fields using regex on existing fields (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1056,7 +1056,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.', ], + [ 'The art of algorithms.', 'The art of programming.', ], 'Copy and replace all fields using regex (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1104,7 +1104,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '652', subfield => 'a' } ); is_deeply( \@fields_652a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1122,7 +1122,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '653', subfield => 'a' } ); is_deeply( \@fields_653a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1140,7 +1140,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '654', subfield => 'a' } ); is_deeply( \@fields_654a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1158,7 +1158,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '655', subfield => 'a' } ); is_deeply( \@fields_655a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy and replace field using regex (same as copy)' ); --