From 90c87b2ab2022bf82ea0ddc967c7338984bb1176 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 27 Oct 2021 12:48:35 +0000 Subject: [PATCH] Bug 29334: Do not apply defaultvalue to existing auth record Note: The check in build_authorized_values_list with defaultvalue can be simplified since $value may already contain the defaultvalue. It is filled before the sub is called. The test for inserting a blank option is generalized; and may be still improved when using required attributes in the template? Note that we might experience some browser issues for these placeholders. Removed a few useless lines with respect to fields controlled by itemtypes. The last assignment to $value was useless and its probable intention unwanted (just use defaultvalue). Test plan: Put a defaultvalue in an authority framework. Add a new authority. Check for that value. Open existing authority. Clear field, save and reopen. Check if field is still empty. Bonus: test field controlled by authorised values. Signed-off-by: Marcel de Rooy Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- authorities/authorities.pl | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/authorities/authorities.pl b/authorities/authorities.pl index fc4ae1a200..3b4a5d64be 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -36,7 +36,6 @@ use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); -my $itemtype; # created here because it can be used in build_authorized_values_list sub our($authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950); =head1 FUNCTIONS @@ -70,50 +69,34 @@ sub build_authorized_values_list { my @authorised_values; my %authorised_lib; - - #---- branch my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'}; + push @authorised_values, q{} unless $tagslib->{$tag}->{$subfield}->{mandatory} && $value; + if ( $category eq "branches" ) { - my $sth = - $dbh->prepare( - "select branchcode,branchname from branches order by branchname"); + my $sth = $dbh->prepare( "select branchcode,branchname from branches order by branchname" ); $sth->execute; - push @authorised_values, "" - unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); - while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) { push @authorised_values, $branchcode; $authorised_lib{$branchcode} = $branchname; } } elsif ( $category eq "itemtypes" ) { - push @authorised_values, "" - unless ( $tagslib->{$tag}->{$subfield}->{mandatory} - && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); - - my $itemtype; my $itemtypes = Koha::ItemTypes->search_with_localization; - while ( $itemtype = $itemtypes->next ) { + while ( my $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; } - $value = $itemtype unless ($value); - - #---- "true" authorised value } - else { + else { # "true" authorised value $authorised_values_sth->execute( - $tagslib->{$tag}->{$subfield}->{authorised_value} ); - - push @authorised_values, "" - unless ( $tagslib->{$tag}->{$subfield}->{mandatory} - && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); - + $tagslib->{$tag}->{$subfield}->{authorised_value} + ); while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { push @authorised_values, $value; $authorised_lib{$value} = $lib; } } + return { type => 'select', id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, @@ -125,7 +108,6 @@ sub build_authorized_values_list { }; } - =item create_input builds the entry for a subfield. @@ -133,7 +115,7 @@ builds the entry for a subfield. =cut sub create_input { - my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth,$cgi ) = @_; + my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth, $cgi ) = @_; my $index_subfield = CreateKey(); # create a specifique key for each subfield @@ -147,7 +129,7 @@ sub create_input { # if there is no value provided but a default value in parameters, get it if ($value eq '') { - $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; + $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} if !$cgi->param('authid'); # only for new records if (!defined $value) { $value = q{}; } -- 2.39.5