From ede8546e2b03199832637e7e79b3ab980edc47db Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 3 Aug 2020 13:41:11 +0000 Subject: [PATCH] Bug 21066: Resolve SQL errors in strict mode DBD::mysql::st execute failed: Incorrect integer value: '' for column `koha_master`.`opac_news`.`number` at row 1 [for Statement "INSERT INTO opac_news ( content,number,lang,title,branchcode,borrowernumber,expirationdate,publicationdate ) VALUES ( ?,?,?,?,?,?,?,? )" with ParamValues: 0="test", 1="", 2="", 3="test", 4=undef, 5="51", 6='2020-08-11', 7='2020-08-04'] at /usr/share/koha/C4/NewsChannels.pm line 68. DBD::mysql::st execute failed: Incorrect integer value: 'a' for column `koha_master`.`opac_news`.`number` at row 1 [for Statement "UPDATE opac_news SET lang = ?,publicationdate = ?,expirationdate = ?,number = ?,content = ?,branchcode = ?,title = ? WHERE idnew = ?;" with ParamValues: 0="", 1='2020-08-03', 2=undef, 3="a", 4="test", 5=undef, 6="test", 7="9"] at /usr/share/koha/C4/NewsChannels.pm line 107. Test plan: Do not apply this patch. Enable strict mode in koha-conf. Add new record in tools/news leaving 'Appear in position' blank. The record is not added; you have a warn in your plack-error log. Apply patch and try again. Signed-off-by: Marcel de Rooy Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/NewsChannels.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index bfcbfc6afe..f39113cd89 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -58,6 +58,7 @@ sub add_opac_new { my $retval = 0; if ($href_entry) { + $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/; my @fields = keys %{$href_entry}; my @values = values %{$href_entry}; my $field_string = join ',', @fields; @@ -85,6 +86,7 @@ sub upd_opac_new { my $retval = 0; if ($href_entry) { + $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/; # take the keys of hash entry and make a list, but... my @fields = keys %{$href_entry}; my @values; -- 2.39.5