From c2ba743b170589dfd6442ff5a4d0dfab692c19bc 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 --- Koha/MarcOverlayRules.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Koha/MarcOverlayRules.pm b/Koha/MarcOverlayRules.pm index 11b33d1928..7d7e07a1d4 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.20.1