Bugzilla – Attachment 139440 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]
Issue 1: First pass at script to automate converting to recall
Issue-1-First-pass-at-script-to-automate-convertin.patch (text/plain), 7.44 KB, created by
Aleisha Amohia
on 2022-08-18 23:39:38 UTC
(
hide
)
Description:
Issue 1: First pass at script to automate converting to recall
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2022-08-18 23:39:38 UTC
Size:
7.44 KB
patch
obsolete
>From e7b050cfe21310c50509cdc6fcb3fe620b4f4182 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Fri, 8 Oct 2021 16:09:11 +1300 >Subject: [PATCH] Issue 1: First pass at script to automate converting to > recall > >(cherry picked from commit d97c04e398b857e39aed4c10406dd9805d419d31) > >https://bugs.koha-community.org/show_bug.cgi?id=31415 >--- > .../prog/en/modules/recalls/request.tt | 3 +- > .../recalls/convert_reserves_to_recalls.pl | 115 +++++++++++++++++++++ > recalls/request.pl | 13 +-- > 3 files changed, 124 insertions(+), 7 deletions(-) > create mode 100755 misc/cronjobs/recalls/convert_reserves_to_recalls.pl > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt >index 3da6909bd2..d278c186d6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt >@@ -50,7 +50,7 @@ > > [% IF error %] > <div class="dialog alert"> >- Unable to place a recall. Check your circulation rules. >+ Unable to place a recall. Check your system preferences and circulation rules. > </div> > [% END %] > >@@ -194,6 +194,7 @@ > [% IF recalls.count %] > <form method="post" action="/cgi-bin/koha/recalls/request.pl"> > <input type="hidden" name="op" value="cancel_multiple_recalls"> >+ <input type="hidden" name="biblionumber" value="[% biblio.biblionumber | html %]" /> > <input type="checkbox" id="select_all"> <span id="select_all_text">Select all</span> > [% INCLUDE 'recalls.inc' %] > <fieldset class="action"> >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..e808394973 >--- /dev/null >+++ b/misc/cronjobs/recalls/convert_reserves_to_recalls.pl >@@ -0,0 +1,115 @@ >+#!/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" }; >+} >+ >+# This script converts reserves to recalls when a record has a set minimum number of reserves placed. >+# It DOES NOT CHECK if this is a legal recall. It assumes that the same rules that apply to reserves, also apply to recalls. >+ >+use Koha::Script -cron; >+use Koha::DateUtils; >+use Koha::Recalls; >+use C4::Log; >+ >+my $min = 1; >+my $verbose; >+ >+GetOptions( >+ 'min|m=i' => \$min, >+ 'verbose|v' => \$verbose >+) or pod2usage(1); >+ >+cronlogaction(); >+ >+# 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 } }, >+}); >+ >+my $count = 0; >+foreach my $bib ( @bib_reserves ) { >+ $bib = $bib->unblessed; >+ if ( $bib->{bibcount} >= $min ) { >+ # "Currently, if all items on a record are unavailable and there are $min or more holds on that same record, then we place a recall" >+ >+ my @reserves = Koha::Holds->search({ biblionumber => $bib->{biblionumber} }, { order_by -=> { -asc => 'reservedate' } }); >+ my $reserve_to_convert = $reserves[0]; >+ foreach my $res ( @reserves ) { >+ # "Generally, we place the recall on the item that has been on loan for the longest." >+ 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 $item; >+ my $can_convert; >+ if ( $reserve_to_convert->item_level_hold ) { >+ $item = Koha::Items->find( $reserve_to_convert->itemnumber ); >+ if ( $item->checkout ) { >+ # item-level reserve can be recalled because the relevant item is unavailable >+ $can_convert = 1; >+ } >+ } else { >+ my @items = Koha::Items->search({ biblionumber => $reserve_to_convert->biblionumber }); >+ my $items_unavailable = 0; >+ foreach ( @items ) { >+ if ( $_->checkout or $_->itemlost or $_->withdrawn or $_->notforloan ) { >+ # item is unavailable to be checked out right now >+ $items_unavailable++; >+ } >+ } >+ if ( $items_unavailable > 0 and $items_unavailable == scalar @items ) { >+ # all items must be unavailable for this reserve to be converted to a recall >+ $can_convert = 1; >+ } >+ } >+ my $biblio = Koha::Biblios->find( $reserve_to_convert->biblionumber ); >+ 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"; >+ } >+ } >+ } >+} >diff --git a/recalls/request.pl b/recalls/request.pl >index eec78148f3..3c40c05e73 100755 >--- a/recalls/request.pl >+++ b/recalls/request.pl >@@ -47,7 +47,7 @@ my $error = $input->param('error'); > if ( $op eq 'cancel_multiple_recalls' ) { > foreach my $id ( @recall_ids ) { > my $recall = Koha::Recalls->find( $id )->set_cancelled; >- $biblionumber = $recall->biblionumber; >+ $biblionumber = $input->param('biblionumber'); > } > } > elsif ( $op eq 'patron_select' ) { >@@ -60,12 +60,13 @@ elsif ( $op eq 'patron_select' ) { > if ( !$biblio->can_be_recalled({ patron => $patron }) ) { > $error = 1; > } >- >- $template->param( >- patron => $patron, >- error => $error, >- ); >+ } else { >+ $error = 1; > } >+ $template->param( >+ patron => $patron, >+ error => $error, >+ ); > } else { > print $input->redirect("/cgi-bin/koha/recalls/request.pl?biblionumber=$biblionumber"); > } >-- >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