From e0098e72a84a6c5128c0e653f2882e3767849e58 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Fri, 17 Jan 2020 10:26:58 +0100 Subject: [PATCH] Bug 24480: Fix insert_fields_ordered instead of append_fields in SimpleMARC Test plan : - create a marc modification template which add a new field to a record - apply that template to some records - verify that the new field is always appended at the bottom of the record, even if some fields are higher. - apply patch - apply template to another set of records - verify the added field is now ordered within the already existing fields in the records Signed-off-by: Kelly Signed-off-by: Phil Ringnalda Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit d3112dc3191a82e6cc6072394bd8d6035f66e15c) Signed-off-by: Fridolin Somers --- Koha/SimpleMARC.pm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index 5aab1285d7..0c95ccf804 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -208,12 +208,12 @@ sub add_field { if ( $fieldName > 10 ) { foreach my $value ( @values ) { my $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value ); - $record->append_fields( $field ); + $record->insert_fields_ordered( $field ); } } else { foreach my $value ( @values ) { my $field = MARC::Field->new( $fieldName, $value ); - $record->append_fields( $field ); + $record->insert_fields_ordered( $field ); } } } @@ -236,7 +236,7 @@ sub _update_field { if ( $fieldName < 10 ) { foreach my $value ( @values ) { my $field = MARC::Field->new( $fieldName, $value ); - $record->append_fields( $field ); + $record->insert_fields_ordered( $field ); } } else { warn "Invalid operation, trying to add a new field without subfield"; @@ -279,7 +279,7 @@ sub _update_subfield { ## Field does not exist, create it. foreach my $value ( @values ) { my $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $values[$i++] ); - $record->append_fields( $field ); + $record->insert_fields_ordered( $field ); } } } @@ -575,7 +575,6 @@ sub _copy_move_field { @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers; } - my @new_fields; 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,9 +594,8 @@ sub _copy_move_field { $record->delete_field( $to_fields[0] ); } } - push @new_fields, $new_field; + $record->insert_grouped_field( $new_field ); } - $record->append_fields( @new_fields ); } sub _copy_move_subfield { -- 2.39.5