Bugzilla – Attachment 15709 Details for
Bug 9712
Add command line script to recalculate existing due dates based on current issuing rules and retroactively update the issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9712 - Add command line script to recalculate existing due dates based on current issuing rules and retroactively update the issues
Bug-9712---Add-command-line-script-to-recalculate-.patch (text/plain), 6.35 KB, created by
Kyle M Hall (khall)
on 2013-02-26 17:43:07 UTC
(
hide
)
Description:
Bug 9712 - Add command line script to recalculate existing due dates based on current issuing rules and retroactively update the issues
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-02-26 17:43:07 UTC
Size:
6.35 KB
patch
obsolete
>From 50fc758b8ca161d8c66b87ee11bfe2253ec405a5 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 26 Feb 2013 11:48:57 -0500 >Subject: [PATCH] Bug 9712 - Add command line script to recalculate existing due dates based on current issuing rules and retroactively update the issues > >This script can take existing issues and check to see of the due dates >match up with the current issuing rules. If can optionally update the >due dates based on the current issuing rules. > >Test Plan: >1) Set an issuing rule >2) Check out an item to a patron where that issuing rules applies >3) Modify the issuing rule's issue length >4) Run migration_tools/recalculate_due_dates.pl -t >5) You should see it list your issue has having a changed due date >6) run migration_tools/recalculate_due_dates.pl -c >7) You should see the due date updated in the database for this issue >--- > misc/migration_tools/recalculate_due_dates.pl | 170 +++++++++++++++++++++++++ > 1 files changed, 170 insertions(+), 0 deletions(-) > create mode 100755 misc/migration_tools/recalculate_due_dates.pl > >diff --git a/misc/migration_tools/recalculate_due_dates.pl b/misc/migration_tools/recalculate_due_dates.pl >new file mode 100755 >index 0000000..4133686 >--- /dev/null >+++ b/misc/migration_tools/recalculate_due_dates.pl >@@ -0,0 +1,170 @@ >+#!/usr/bin/perl >+ >+# Copyright 2013 ByWater Solutions >+ >+# 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, >+# Suite 330, Boston, MA 02111-1307 USA >+# >+ >+use Modern::Perl; >+ >+use DBI; >+use Getopt::Long; >+use Pod::Usage; >+use List::MoreUtils qw( any ); >+use DateTime::Format::MySQL; >+ >+use C4::Context; >+use C4::Items qw( GetItem ); >+use C4::Members qw( GetMember ); >+use C4::Circulation; # qw( CalcDateDue ); >+ >+my $verbose = 0; >+my $help = 0; >+my $man = 0; >+my $commit = 0; >+my $due_in = 0; >+my @exclude_categories; >+my @exclude_itemtypes; >+ >+GetOptions( >+ 'v|verbose' => \$verbose, >+ 'h|help' => \$help, >+ 'm|man' => \$man, >+ 'c|commit' => \$commit, >+ 'd|due-in=s' => \$due_in, >+ 'exclude-category=s' => \@exclude_categories, >+ 'exclude-itemtype=s' => \@exclude_itemtypes, >+) or pod2usage(2); >+ >+pod2usage(1) if ($help); >+pod2usage( -verbose => 2 ) if $man; >+ >+my $dbh = C4::Context->dbh; >+my $sql = 'SELECT * FROM issues WHERE DATE( date_due ) >= DATE_ADD( CURRENT_DATE(), INTERVAL ? DAY )'; >+my $sth = $dbh->prepare($sql); >+$sth->execute($due_in); >+ >+my $count_total = 0; >+my $count_updated = 0; >+while ( my $issue = $sth->fetchrow_hashref() ) { >+ >+ my $borrower = GetMember( 'borrowernumber' => $issue->{'borrowernumber'} ); >+ next if any { ( $_ eq $borrower->{'categorycode'} ) } @exclude_categories; >+ >+ my $item = GetItem( $issue->{'itemnumber'} ); >+ next if any { ( $_ eq $item->{'itype'} ) } @exclude_itemtypes; >+ >+ my $date_due = DateTime::Format::MySQL->format_datetime( C4::Circulation::CalcDateDue( $issue->{'issuedate'}, $item->{'itype'}, $issue->{'branchcode'}, $borrower ) ); >+ >+ unless ( $issue->{'date_due'} eq $date_due ) { >+ print "\n"; >+ print "DUE DATE ALTERED\n"; >+ print "ITEM NUMBER: $item->{'itemnumber'}\n"; >+ print "BORROWER: $borrower->{'borrowernumber'}\n"; >+ print "ITEM TYPE: $item->{'itype'}\n"; >+ print "BORROWER CATEGORY: $borrower->{'categorycode'}\n"; >+ print "ISSUE DATE: $issue->{'issuedate'}\n"; >+ print "OLD DATE DUE: $issue->{'date_due'}\n"; >+ print "NEW DATE DUE: $date_due\n"; >+ >+ if ($commit) { >+ $dbh->do( "UPDATE issues SET date_due = ? WHERE borrowernumber = ? AND itemnumber = ?", {}, ( $date_due, $borrower->{'borrowernumber'}, $item->{'itemnumber'} ) ); >+ print "*** NEW DATE DUE COMMITED TO DATABASE ***\n"; >+ } else { >+ print "*** TEST MODE, DATE DUE NOT UPDATED IN DATABASE ***\n"; >+ } >+ >+ $count_updated++; >+ } >+ >+ $count_total++; >+} >+ >+print "\nUPDATED $count_updated OF $count_total ISSUES\n"; >+ >+1; >+__END__ >+ >+=head1 NAME >+ >+recalculate_due_dates.pl - recalculate and update due dates for issued items based on current circ rules >+ >+=head1 SYNOPSIS >+ >+recalculate_due_dates.pl >+ >+ Options: >+ -c --commit calculate and update due dates, runs in test mode if not supplied >+ >+ -d --due-in integer, select only issues that are due in this many dates or more >+ default is all issues >+ >+ --exclude-category ignore all items issued to patrons of this category, repeatable >+ --exclude-itemtype ignore all items issued with this itemtype, repeatable >+ >+ -h --help brief help message >+ -m --man full documentation >+ >+=head1 OPTIONS >+ >+=over 8 >+ >+=item B<-help> >+ >+Print a brief help message and exits. >+ >+=item B<-man> >+ >+Prints the manual page and exits. >+ >+=item B<-commit> >+ >+Calculates the new due dates and writes them to the database. >+ >+=item B<-exclude-category> >+ >+Skip issues to patrons of the category code. Repeatable. >+ >+=item B<-exclude-itemtype> >+ >+Skip issues of items having this item type. Repeatable. >+ >+=item B<-due-in> >+ >+Select only issues that are due in this many dates or more. >+If not supplied, the script will update all current issues. >+ >+For example, recalculate_due_dates.pl -c -d 1 will recalculate >+all issues that are due tomorrow or later. >+ >+=back >+ >+=head1 DESCRIPTION >+ >+This script can be used to retroactively change the due dates >+on currently issued items based on the current issuing rules. >+ >+CAVEAT: This script will overwrite any manually set due dates >+with the due date that Koha would have automatically calculated >+manually. >+ >+=head1 AUTHOR >+ >+Kyle M Hall <kyle@bywatersolutions.com> >+ >+=cut >+ >+ >-- >1.7.2.5
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 9712
:
15706
|
15707
|
15708
| 15709