Bugzilla – Attachment 139646 Details for
Bug 31415
Script to automate converting holds to recalls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31415: Script to automate converting reserves to recalls
Bug-31415-Script-to-automate-converting-reserves-t.patch (text/plain), 4.55 KB, created by
Aleisha Amohia
on 2022-08-23 02:02:06 UTC
(
hide
)
Description:
Bug 31415: Script to automate converting reserves to recalls
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2022-08-23 02:02:06 UTC
Size:
4.55 KB
patch
obsolete
>From 4087825388e87f9d91528b00415f73a092ca6488 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Fri, 8 Oct 2021 16:09:11 +1300 >Subject: [PATCH] Bug 31415: Script to automate converting reserves to recalls > >This is a work in progress and not ready for testing. >--- > .../recalls/convert_reserves_to_recalls.pl | 117 +++++++++++++++++++++ > 1 file changed, 117 insertions(+) > create mode 100755 misc/cronjobs/recalls/convert_reserves_to_recalls.pl > >diff --git a/misc/cronjobs/recalls/convert_reserves_to_recalls.pl b/misc/cronjobs/recalls/convert_reserves_to_recalls.pl >new file mode 100755 >index 0000000000..18e1936398 >--- /dev/null >+++ b/misc/cronjobs/recalls/convert_reserves_to_recalls.pl >@@ -0,0 +1,117 @@ >+#!/usr/bin/perl >+ >+# Copyright 2021 Aleisha Amohia <aleisha@catalyst.net.nz> >+# >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Getopt::Long; >+ >+BEGIN { >+ # find Koha's Perl modules >+ # test carefully before changing this >+ use FindBin; >+ eval { require "$FindBin::Bin/../kohalib.pl" }; >+} >+ >+use Koha::Script -cron; >+use Koha::DateUtils qw( dt_from_string ); >+use Koha::Recalls; >+use C4::Log; >+ >+cronlogaction(); >+ >+=head1 NAME >+ >+convert_reserves_to_recalls.pl >+ >+=head1 SYNOPSIS >+ >+convert_reserves_to_recalls.pl [-v] [--min X] >+ >+This script converts reserves to recalls when a record has a set minimum number of reserves placed. >+ >+Options: >+ -v verbose >+ --min X minimum number of reserves >+ >+=cut >+ >+my $min = 1; >+my $verbose; >+ >+GetOptions( >+ 'min|m=i' => \$min, >+ 'verbose|v' => \$verbose >+) or pod2usage(1); >+ >+# get reserves where there is more than $min reserves on one biblio >+my @bib_reserves = Koha::Holds->search({}, { >+ select => [ >+ 'biblionumber', >+ { count => 'biblionumber', -as => 'bibcount' } >+ ], >+ group_by => 'biblionumber', >+ having => { 'bibcount' => { '>=', $min } }, >+})->as_list; >+ >+my $count = 0; >+foreach my $bib ( @bib_reserves ) { >+ $bib = $bib->unblessed; >+ if ( $bib->{bibcount} >= $min ) { >+ # If there are $min or more holds on the same record, convert the oldest hold to a recall >+ >+ my @reserves = Koha::Holds->search({ biblionumber => $bib->{biblionumber} }, { order_by => { -asc => 'reservedate' } })->as_list; >+ my $reserve_to_convert = $reserves[0]; >+ foreach my $res ( @reserves ) { >+ if ( dt_from_string($res->reservedate) < dt_from_string($reserve_to_convert->reservedate) ) { >+ $reserve_to_convert = $res; >+ } >+ } >+ >+ my $patron = Koha::Patrons->find( $reserve_to_convert->borrowernumber ); >+ my $biblio = Koha::Biblios->find( $reserve_to_convert->biblionumber ); >+ my $item; >+ my $can_convert; >+ if ( $reserve_to_convert->item_level_hold ) { >+ $item = Koha::Items->find( $reserve_to_convert->itemnumber ); >+ if ( $item->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { >+ $can_convert = 1; >+ } >+ } else { >+ if ( $biblio->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { >+ $can_convert = 1; >+ } >+ } >+ if ( $can_convert ) { >+ my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ >+ patron => $patron, >+ biblio => $biblio, >+ branchcode => $reserve_to_convert->branchcode, >+ item => $item, >+ expirationdate => $reserve_to_convert->expirationdate, >+ interface => 'commandline', >+ }); >+ $reserve_to_convert->cancel({ cancellation_reason => 'RECALLED' }); >+ $count++; >+ if ( $verbose ) { >+ my $reserve_id = $reserve_to_convert->reserve_id; >+ my $biblionumber = $reserve_to_convert->biblionumber; >+ print "$count. Hold $reserve_id converted to recall on biblio $biblionumber.\n"; >+ } >+ } >+ } >+} >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31415
:
139440
|
139441
|
139646
|
139737
|
145796
|
148112
|
157002
|
159010
|
159016
|
159017