From ac8b17f8c70877e4003775288025e3b345a8aa24 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 28 Aug 2024 04:36:05 +0000 Subject: [PATCH] Bug 37675: Remove need for random numbers in MARC subfields This change removes the need for random numbers in the index_tag and index_subfield variables. Instead, respectively, we use the tag number and an incrementing integer. This eliminates the possibility of duplicate ID/name values in server-side generated content. Note that there is still a risk of a collision when generating these values via the Javascript at this time. --- Koha/UI/Form/Builder/Biblio.pm | 10 +++++++++- cataloguing/addbiblio.pl | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Koha/UI/Form/Builder/Biblio.pm b/Koha/UI/Form/Builder/Biblio.pm index 72d7db99dc..36865ea3c8 100644 --- a/Koha/UI/Form/Builder/Biblio.pm +++ b/Koha/UI/Form/Builder/Biblio.pm @@ -78,8 +78,16 @@ sub generate_subfield_form { my $breedingid = $params->{breedingid}; my $tagslib = $params->{tagslib}; my $mandatory_z3950 = $params->{mandatory_z3950} // {}; + my $subfield_counter = $params->{subfield_counter}; + if ( $subfield_counter->{$subfield} ){ + $subfield_counter->{$subfield}++; + } + else { + $subfield_counter->{$subfield} = 1; + } + my $subfield_number = $subfield_counter->{$subfield}; - my $index_subfield = $self->create_key(); # create a specific key for each subfield + my $index_subfield = $subfield_number; # create a specific key for each subfield # Apply optional framework default value when it is a new record, # or when editing as new (duplicating a record), diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 626c3cb4c4..9a5964b7ac 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -289,8 +289,9 @@ sub build_tabs { $i++; next if ! $tag; my ($indicator1, $indicator2); - my $index_tag = CreateKey($unique_keys); + my $index_tag = $tag; + my $subfield_counter = {}; # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab. # if MARC::Record is empty => use tab as master loop. if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) { @@ -334,6 +335,7 @@ sub build_tabs { breedingid => scalar $input->param('breedingid'), tagslib => $tagslib, mandatory_z3950 => $mandatory_z3950, + subfield_counter => $subfield_counter, } ) ); @@ -360,6 +362,7 @@ sub build_tabs { breedingid => scalar $input->param('breedingid'), tagslib => $tagslib, mandatory_z3950 => $mandatory_z3950, + subfield_counter => $subfield_counter, } ) ); @@ -401,6 +404,7 @@ sub build_tabs { breedingid => scalar $input->param('breedingid'), tagslib => $tagslib, mandatory_z3950 => $mandatory_z3950, + subfield_counter => $subfield_counter, } ) ); @@ -468,6 +472,7 @@ sub build_tabs { breedingid => scalar $input->param('breedingid'), tagslib => $tagslib, mandatory_z3950 => $mandatory_z3950, + subfield_counter => $subfield_counter, } ) ); -- 2.39.2