From 164893acfe89fbf1156ad8a93bee28771ba370d8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 4 Aug 2019 12:48:07 -0500 Subject: [PATCH] Bug 23242: Fix insert of Z3950 servers with strict SQL modes If strict SQL modes are set, the insertion of a new Z3950 server can fail. DBIx::Class::Storage::DBI::_dbh_execute(): Incorrect integer value: '' for column 'checked' at row 1 at /home/vagrant/kohaclone/admin/z3950servers.pl line 82 Using Koha::Z3950Servers fixes the issue (handled from Koha::Object->store) Test plan: - Turn the strict SQL modes on (config strict_sql_modes) - Create a new Z3950 server filling only the mandatory fields. => Without this patch you will get the failure, with this patch applied the server will be inserted sucessfully - Delete it => No regression should be found - Search for servers => No regression should be found (the search is a start-with, LIKE "$pattern%") Signed-off-by: Katrin Fischer Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize (cherry picked from commit a9c730244768ea355004e821d5be35dc2e617840) Signed-off-by: Fridolin Somers --- admin/z3950servers.pl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index bb15e39121..cb226663d8 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -30,6 +30,7 @@ use C4::Context; use C4::Auth; use C4::Output; use Koha::Database; +use Koha::Z3950Servers; # Initialize CGI, template, database @@ -56,7 +57,7 @@ my $schema = Koha::Database->new()->schema(); # First process a confirmed delete, or save a validated record if( $op eq 'delete_confirmed' && $id ) { - my $server = $schema->resultset('Z3950server')->find($id); + my $server = Koha::Z3950Servers->find($id); if ( $server ) { $server->delete; $template->param( msg_deleted => 1, msg_add => $server->servername ); @@ -70,16 +71,16 @@ if( $op eq 'delete_confirmed' && $id ) { add_xslt/; my $formdata = _form_data_hashref( $input, \@fields ); if( $id ) { - my $server = $schema->resultset('Z3950server')->find($id); + my $server = Koha::Z3950Servers->find($id); if ( $server ) { - $server->update( $formdata ); + $server->set( $formdata )->store; $template->param( msg_updated => 1, msg_add => $formdata->{servername} ); } else { $template->param( msg_notfound => 1, msg_add => $id ); } $id = 0; } else { - $schema->resultset('Z3950server')->create( $formdata ); + Koha::Z3950Server->new( $formdata )->store; $template->param( msg_added => 1, msg_add => $formdata->{servername} ); } } else { @@ -106,11 +107,10 @@ output_html_with_http_headers $input, $cookie, $template->output; sub ServerSearch { #find server(s) by id or name my ( $schema, $id, $searchstring )= @_; - my $rs = $schema->resultset('Z3950server')->search( - $id ? { id => $id }: { servername => { like => $searchstring.'%' } }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } - ); - return [ $rs->all ]; + + return Koha::Z3950Servers->search( + $id ? { id => $id } : { servername => { like => $searchstring . '%' } }, + )->unblessed; } sub _form_data_hashref { -- 2.39.5