Bug 35414

Summary: Silence warn related to number_of_copies
Product: Koha Reporter: Magnus Enger <magnus>
Component: CatalogingAssignee: Magnus Enger <magnus>
Status: Pushed to oldstable --- QA Contact: Testopia <testopia>
Severity: trivial    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, lucas, m.de.rooy
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,23.11.01,23.05.07
Circulation function:
Attachments: Bug 35414: Silence warn related to number_of_copies
Bug 35414: Silence warn related to number_of_copies
Bug 35414: Silence warn related to number_of_copies

Description Magnus Enger 2023-11-28 12:58:26 UTC
cataloguing/additem.pl has this code: 

my $number_of_copies           = min( scalar $input->param('number_of_copies'), 1000 ); # TODO refine hardcoded maximum?

"number_of_copies" comes from the "Add multiple copies of this item" feature. The field for entering the number of copies defaults to empty, and this results in this warning, from the code above: 

[WARN] Argument "" isn't numeric in subroutine entry at /usr/share/koha/intranet/cgi-bin/cataloguing/additem.pl line 233.

We could fix this a couple of ways: 

- Make the number_of_copies field default to 1
- Fix the code, so 1 is used for number_of_copies, if the input is empty
Comment 1 Jonathan Druart 2023-11-29 12:58:44 UTC
I would do this:

-    my $number_of_copies           = min( scalar $input->param('number_of_copies'), 1000 ); # TODO refine hardcoded maximum?
+    my $number_of_copies           = min( $input->param('number_of_copies') || 0, 1000 ); # TODO refine hardcoded maximum?
Comment 2 Magnus Enger 2023-11-29 14:02:23 UTC Comment hidden (obsolete)
Comment 3 Owen Leonard 2023-11-29 18:46:11 UTC Comment hidden (obsolete)
Comment 4 Marcel de Rooy 2023-12-01 07:26:37 UTC
Created attachment 159425 [details] [review]
Bug 35414: Silence warn related to number_of_copies

To test in ktd:
- Tail the logs with "sudo tail -f /var/log/koha/kohadev/plack*.log"
- Find a record in the staff client
- Add an item to the record
- Observe "[WARN] Argument "" isn't numeric in subroutine entry ..."
  in /var/log/koha/kohadev/plack-intranet-error.log
- Apply this patch
- restart_all
- Tail the logs again
- Add another item
- Observe the absence of the earlier warning

Thanks to Jonathan Druart for suggesting this particular solution!

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 5 Katrin Fischer 2023-12-11 18:47:05 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 6 Fridolin Somers 2023-12-12 07:38:20 UTC
Pushed to 23.11.x for 23.11.01
Comment 7 Lucas Gass (lukeg) 2023-12-14 21:17:27 UTC
Backported to 23.05.x for upcoming 23.05.07