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 <katrin.fischer.83@web.de>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-08-04 12:48:07 -05:00 committed by Martin Renvoize
parent f9572dd1ac
commit a9c7302447
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 9 additions and 9 deletions

View File

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