From ed4dc50c933d3923e4644f4d1c48237497f140f9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 28 Aug 2024 10:30:30 +0200 Subject: [PATCH] Bug 37675: Use UUID --- Koha/UI/Form/Builder/Biblio.pm | 14 +++++--------- cataloguing/addbiblio.pl | 18 ++++++------------ koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Koha/UI/Form/Builder/Biblio.pm b/Koha/UI/Form/Builder/Biblio.pm index 36865ea3c82..4e596f731ff 100644 --- a/Koha/UI/Form/Builder/Biblio.pm +++ b/Koha/UI/Form/Builder/Biblio.pm @@ -16,6 +16,7 @@ package Koha::UI::Form::Builder::Biblio; # along with Koha; if not, see . use Modern::Perl; +use UUID; use C4::Context; use C4::ClassSource qw( GetClassSources ); use Koha::DateUtils qw( dt_from_string ); @@ -393,15 +394,10 @@ sub build_authorized_values_list { sub create_key { my ($self) = @_; - my $unique_keys = $self->{unique_keys}; - my $max_num = 10000000; - #TODO: Note this could lead to a near infinite loop - while (my $value = int(rand($max_num)) ){ - if ( ! $unique_keys->{$value} ){ - $unique_keys->{$value} = 1; - return $value; - } - } + my ($uuid, $key); + UUID::generate($uuid); + UUID::unparse($uuid, $key); + return $key; } 1; diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 9a5964b7ac0..3d5179ab942 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -23,6 +23,7 @@ use Modern::Perl; use CGI; use POSIX qw( strftime ); use Try::Tiny qw(catch try); +use UUID; use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user haspermission ); @@ -183,15 +184,10 @@ sub MARCfindbreeding { =cut sub CreateKey { - my ($unique_keys) = @_; - my $max_num = 10000000; - #TODO: Note this could lead to a near infinite loop - while (my $value = int(rand($max_num)) ){ - if ( ! $unique_keys->{$value} ){ - $unique_keys->{$value} = 1; - return $value; - } - } + my ($uuid, $key); + UUID::generate($uuid); + UUID::unparse($uuid, $key); + return $key; } =head2 GetMandatoryFieldZ3950 @@ -236,8 +232,6 @@ sub format_indicator { sub build_tabs { my ( $template, $record, $dbh, $encoding,$input ) = @_; - my $unique_keys = {}; - # fill arrays my @loop_data = (); my $tag; @@ -423,7 +417,7 @@ sub build_tabs { important => $tagslib->{$tag}->{important}, subfield_loop => \@subfields_data, fixedfield => $tag < 10?1:0, - random => CreateKey($unique_keys), + random => CreateKey(), ); if ($tag >= 10){ # no indicator for 00x tags $tag_data{indicator1} = format_indicator($field->indicator(1)), diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index ed0ac18b794..b3e455e1ec6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -506,7 +506,7 @@ function UnCloneField(index) { * This function create a random number */ function CreateKey(){ - return parseInt(Math.random() * 10000000); + return crypto.randomUUID(); } /* Functions developed for additem.tt */ -- 2.34.1