From 97c09f1d3cf58500bf7b0f06446592fb77f6570f Mon Sep 17 00:00:00 2001 From: Emily Lamancusa Date: Mon, 30 Oct 2023 13:19:02 -0400 Subject: [PATCH] Bug 35190: Adjust UI handling to avoid inserting an empty string To test: 1. In the Administration module, create an Additional Field that is not linked to an authorized value 2. Create another Additional Field that is linked to an authorized value 3. Access the database in the command line (koha-mysql kohadev) 4. Select all from additional_fields 5. Confirm that each field correctly lists either the appropriate authorized value, or NULL Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- admin/additional-fields.pl | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/admin/additional-fields.pl b/admin/additional-fields.pl index 5e6b1e32d7..35dd1a97b1 100755 --- a/admin/additional-fields.pl +++ b/admin/additional-fields.pl @@ -49,21 +49,23 @@ my @messages; if ( $op eq 'add' ) { my $name = $input->param('name') // q{}; - my $authorised_value_category = $input->param('authorised_value_category') // q{}; + my $authorised_value_category = $input->param('authorised_value_category'); my $marcfield = $input->param('marcfield') // q{}; my $marcfield_mode = $input->param('marcfield_mode') // 'get'; my $searchable = $input->param('searchable') ? 1 : 0; if ( $field_id and $name ) { - my $updated = 0; + my $updated = 0; + my $set_fields = { + name => $name, + marcfield => $marcfield, + marcfield_mode => $marcfield_mode, + searchable => $searchable, + }; + $set_fields->{authorised_value_category} = $authorised_value_category if $authorised_value_category; + eval { my $af = Koha::AdditionalFields->find($field_id); - $af->set({ - name => $name, - authorised_value_category => $authorised_value_category, - marcfield => $marcfield, - marcfield_mode => $marcfield_mode, - searchable => $searchable, - }); + $af->set($set_fields); $updated = $af->store ? 1 : 0; }; push @messages, { @@ -71,16 +73,18 @@ if ( $op eq 'add' ) { number => $updated, }; } elsif ( $name ) { - my $inserted = 0; + my $inserted = 0; + my $set_fields = { + tablename => $tablename, + name => $name, + marcfield => $marcfield, + marcfield_mode => $marcfield_mode, + searchable => $searchable, + }; + $set_fields->{authorised_value_category} = $authorised_value_category if $authorised_value_category; + eval { - my $af = Koha::AdditionalField->new({ - tablename => $tablename, - name => $name, - authorised_value_category => $authorised_value_category, - marcfield => $marcfield, - marcfield_mode => $marcfield_mode, - searchable => $searchable, - }); + my $af = Koha::AdditionalField->new($set_fields); $inserted = $af->store ? 1 : 0; }; push @messages, { -- 2.39.5