From c2b8a5e7e9b6f08fbb6d15046ce62c9af4b7b241 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 27 Jun 2025 11:26:47 +0200 Subject: [PATCH] Bug 39871: (QA follow-up) Do not hardcode nullable check Content-Type: text/plain; charset=utf-8 Lets check DBIx's columns_info. Test plan: Try to blank an integer column and a string column. Verify results. Signed-off-by: Marcel de Rooy --- tools/batchMod.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 64892af373..620cce1a84 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -33,6 +33,7 @@ use Koha::Database; use Koha::Exception; use Koha::Biblios; use Koha::Items; +use Koha::Object; use Koha::Patrons; use Koha::Item::Attributes; use Koha::BackgroundJob::BatchDeleteItem; @@ -112,13 +113,13 @@ if ( $op eq "cud-action" ) { } else { # modification - my @item_columns = Koha::Items->columns; + my $items_info = Koha::Items->_resultset->result_source->columns_info; my $new_item_data; my ($columns_with_regex); my @subfields_to_blank = $input->multi_param('disable_input'); my @more_subfields = $input->multi_param("items.more_subfields_xml"); - for my $item_column (@item_columns) { + for my $item_column ( keys %$items_info ) { my @attributes = ($item_column); my $cgi_param_prefix = 'items.'; if ( $item_column eq 'more_subfields_xml' ) { @@ -136,13 +137,14 @@ if ( $op eq "cud-action" ) { if ( grep { $cgi_var_name eq $_ } @subfields_to_blank ) { - # Empty this column - if ( $attr eq 'withdrawn' || $attr eq 'itemlost' || $attr eq 'damaged' || $attr eq 'notforloan' ) { - - # these fields are not nullable; they must be set to 0 instead + # Empty this column, check nullable and data_type + next if !$items_info->{$attr}; # skip this weird case + if ( $items_info->{$attr}->{is_nullable} ) { + $new_item_data->{$attr} = undef; + } elsif ( Koha::Object::_numeric_column_type( $items_info->{$attr}->{data_type} ) ) { $new_item_data->{$attr} = 0; } else { - $new_item_data->{$attr} = undef; + $new_item_data->{$attr} = q{}; } } elsif ( my $regex_search = $input->param( $cgi_var_name . '_regex_search' ) ) { $columns_with_regex->{$attr} = { -- 2.39.5