From 7ffba280c786ccd2b3b57d392b00e08462561b0a Mon Sep 17 00:00:00 2001 From: John Doe Date: Fri, 23 Jan 2026 19:08:26 +0000 Subject: [PATCH] Bug 41698 - Add maintenance script to revert found holds for items currently checked out For reasons unknown, it is possible to get into a situation where an item is both checked out to one patron and associated with a found hold for another patron. We should add a script to Koha to fix items in this situation by reverting the found holds. Test Plan: 1) Check an item out to a patron 2) Place an item specific hold for another patron 3) Manually set the priority to 0 and found to "W" for that hold 4) Run misc/maintenance/fix_holds_waiting_and_issued.pl 5) Note the hold has been reverted! --- .../fix_holds_waiting_and_issued.pl | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 misc/maintenance/fix_holds_waiting_and_issued.pl diff --git a/misc/maintenance/fix_holds_waiting_and_issued.pl b/misc/maintenance/fix_holds_waiting_and_issued.pl new file mode 100755 index 00000000000..8b29e0a1375 --- /dev/null +++ b/misc/maintenance/fix_holds_waiting_and_issued.pl @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::Script; +use Koha::Holds; + +use C4::Context; + +use Getopt::Long qw( GetOptions ); + +=head1 NAME + +fix_holds_waiting_and_issued.pl - Revert waiting holds on items that are currently checked out + +=head1 SYNOPSIS + +fix_holds_waiting_and_issued.pl + +=head1 DESCRIPTION + +Sometimes it is possible to end up with items that are both checked out to a patron, and associated +with a hold waiting to be picked up by a different patron. This script finds those items and reverts +the waiting holds. + +=over 8 + +=item B<--help> + +Prints a brief usage message and exits. + +=item B<-c> + +Confirms this script should alter the found holds. + +=back + +=cut + +my $help = 0; +my $confirm; + +sub print_usage { + print <<_USAGE_; +$0: Revert waiting holds on items that are currently checked out + +Sometimes it is possible to end up with items that are both checked out to a patron, and associated +with a hold waiting to be picked up by a different patron. This script finds those items and reverts +the waiting holds. + +Parameters: + -c, --confirm Confirm the script should make the changes + -h, --help Print out this help message. +_USAGE_ +} + +my $result = GetOptions( + 'help|h' => \$help, + 'confirm|c' => \$confirm, +); + +if ( $help || !$confirm ) { + print_usage(); + exit 0; +} + +my $dbh = C4::Context->dbh; +my $sth = $dbh->prepare( + q{ + SELECT reserve_id FROM issues + LEFT JOIN reserves USING ( itemnumber ) + WHERE found IS NOT NULL +} +); +$sth->execute(); + +while ( my $r = $sth->fetchrow_hashref ) { + my $reserve_id = $r->{reserve_id}; + + my $hold = Koha::Holds->find($reserve_id); + $hold->revert_found(); +} -- 2.50.1 (Apple Git-155)