Bug 40475 - Majority of CanBookBeReserved might be dead code?
Summary: Majority of CanBookBeReserved might be dead code?
Status: RESOLVED INVALID
Alias: None
Product: Koha
Classification: Unclassified
Component: Hold requests (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-23 05:01 UTC by David Cook
Modified: 2025-07-24 00:18 UTC (History)
5 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2025-07-23 05:01:15 UTC
I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed that the $itemtype in the following line of opac/opac-reserve.pl looks like it'll always be "undef" for "next available" holds:

my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $itemtype } )->{status};
Comment 1 David Cook 2025-07-23 05:06:16 UTC
In reserve/request.pl we just use this code:

my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );

CanItemBeReserved( $patron, $item_object, undef, { get_from_cache => 1 } )->{status};

So it looks like the majority of CanBookBeReserved never runs because $params->{itemtype} will always be null.

But that might be OK, because at the end of CanBookBeReserved we iterate through all the items attached to that bib and we check them using CanItemBeReserved...
Comment 2 David Cook 2025-07-23 05:06:34 UTC
Note we didn't notice this during manual testing but it came up when looking at t/db_dependent/Reserves.t
Comment 3 Jonathan Druart 2025-07-23 08:44:48 UTC
(In reply to David Cook from comment #0)
> I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed
> that the $itemtype in the following line of opac/opac-reserve.pl looks like
> it'll always be "undef" for "next available" holds:
> 
> my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, {
> itemtype => $itemtype } )->{status};

Are you sure?
Turn on AllowHoldItemTypeSelection

https://snipboard.io/sBaKNe.jpg
If I select "Book" here, I hit CanBookBeReserved with itemtype=BK
Comment 4 David Cook 2025-07-24 00:18:51 UTC
(In reply to Jonathan Druart from comment #3)
> (In reply to David Cook from comment #0)
> > I was discussing CanBookBeReserved with Pedro on bug 15516 when I noticed
> > that the $itemtype in the following line of opac/opac-reserve.pl looks like
> > it'll always be "undef" for "next available" holds:
> > 
> > my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, {
> > itemtype => $itemtype } )->{status};
> 
> Are you sure?

No, that's why I framed the bug report title as a question. 

> Turn on AllowHoldItemTypeSelection
> 
> https://snipboard.io/sBaKNe.jpg
> If I select "Book" here, I hit CanBookBeReserved with itemtype=BK

Thanks for sharing that. That's really helpful. 

It looks like there are a few bugs in the staff interface: it looks like "./reserve/placerequest.pl" isn't using the itemtype with "CanBookBeReserved", and "request.pl" is sending 2 "itemtype" arguments due to a duplicated "Request specific item type" field, so only the first field will ever work.

I'll raise a different report for those.