From 97aab6a98e05ed989e7cc719450d274c80e34bb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Sat, 3 Sep 2022 13:37:31 +0300 Subject: [PATCH] Bug 28012: Use definedness test instead of bool when checking whether to null fields Saving a new numbering pattern didn't work without having to fill all the fields, even those that are not mandatory. To test: 1) Go to /cgi-bin/koha/serials/subscription-numberpatterns.pl and try creating a new pattern, notice that only Name and Description are mandatory after applying this patch 2) Make sure editing existing numbering patterns still works Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- serials/subscription-numberpatterns.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/serials/subscription-numberpatterns.pl b/serials/subscription-numberpatterns.pl index a9bc998835..1669b4d66f 100755 --- a/serials/subscription-numberpatterns.pl +++ b/serials/subscription-numberpatterns.pl @@ -43,6 +43,12 @@ use C4::Serials::Numberpattern qw( ); use C4::Serials::Frequency qw( GetSubscriptionFrequencies ); +my @NUMBERPATTERN_FIELDS = qw/ + label description numberingmethod displayorder + label1 label2 label3 add1 add2 add3 every1 every2 every3 + setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3 + numbering1 numbering2 numbering3 /; + my $input = CGI->new; my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { template_name => 'serials/subscription-numberpatterns.tt', @@ -56,12 +62,9 @@ my $op = $input->param('op'); if($op && $op eq 'savenew') { my $label = $input->param('label'); my $numberpattern; - foreach(qw/ label description numberingmethod displayorder - label1 label2 label3 add1 add2 add3 every1 every2 every3 - setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3 - numbering1 numbering2 numbering3 /) { + foreach(@NUMBERPATTERN_FIELDS) { $numberpattern->{$_} = $input->param($_); - if($numberpattern->{$_} and $numberpattern->{$_} eq '') { + if(defined $numberpattern->{$_} and $numberpattern->{$_} eq '') { $numberpattern->{$_} = undef; } } @@ -86,11 +89,11 @@ if($op && $op eq 'savenew') { } } if($mod_ok) { - foreach(qw/ id label description numberingmethod displayorder - label1 label2 label3 add1 add2 add3 every1 every2 every3 - setto1 setto2 setto3 whenmorethan1 whenmorethan2 whenmorethan3 - numbering1 numbering2 numbering3 /) { + foreach(@NUMBERPATTERN_FIELDS) { $numberpattern->{$_} = $input->param($_) || undef; + if(defined $numberpattern->{$_} and $numberpattern->{$_} eq '') { + $numberpattern->{$_} = undef; + } } ModSubscriptionNumberpattern($numberpattern); } else { -- 2.39.5