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 <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Joonas Kylmälä 2022-09-03 13:37:31 +03:00 committed by Katrin Fischer
parent fa4fd2005e
commit 97aab6a98e
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -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 {