From 8425cf1e13da5ccd7854bf01f3327f1601d3877f Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 20 Oct 2021 17:17:31 +0200 Subject: [PATCH] Bug 14957: Fix field order issue Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/MarcOverlayRules.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Koha/MarcOverlayRules.pm b/Koha/MarcOverlayRules.pm index 884da13ca7..b874f7cd07 100644 --- a/Koha/MarcOverlayRules.pm +++ b/Koha/MarcOverlayRules.pm @@ -160,7 +160,7 @@ sub merge_records { my %keys_index = map { $_ => undef } (keys %{$a}, keys %{$b}); foreach my $key (keys %keys_index) { if ($a->{$key} && $b->{$key}) { - push @intersecting, $a->{$key}; + push @intersecting, [$a->{$key}, $b->{$key}]; } elsif ($a->{$key}) { push @removed, $a->{$key}; @@ -254,7 +254,23 @@ sub merge_records { # First add common fields (intersection) # Unchanged if (@{$common_fields}) { - push @merged_fields, @{$common_fields}; + if( + $rule->{delete}->{allow} && + $rule->{add}->{allow} && ( + @{$common_fields} == 1 || ( + $rule->{append}->{allow} && + $rule->{remove}->{allow} + ) + ) + ) { + # If overwritable apply possible subfield order + # changes from incoming fields + push @merged_fields, map { $_->[1] } @{$common_fields}; + } + else { + # else keep existing subfield order + push @merged_fields, map { $_->[0] } @{$common_fields}; + } } # Removed if (@{$current_fields_only}) { -- 2.39.5