From 426fbcdf52c5c552236a2df75968371e5b8308e0 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 30 Oct 2012 07:42:23 -0400 Subject: [PATCH] Bug 8985 - Add script to batch modify issuing rule hard due dates. Content-Type: text/plain; charset="utf-8" --- misc/modify_hard_due_dates.pl | 95 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 95 insertions(+), 0 deletions(-) create mode 100755 misc/modify_hard_due_dates.pl diff --git a/misc/modify_hard_due_dates.pl b/misc/modify_hard_due_dates.pl new file mode 100755 index 0000000..641a490 --- /dev/null +++ b/misc/modify_hard_due_dates.pl @@ -0,0 +1,95 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/kohalib.pl" }; +} + +use C4::Context; + +use Getopt::Long; + +$| = 1; + +# command-line parameters +my $hardduedate = undef; +my $comparison = undef; +my $category_code = undef; +my $itemtype = undef; +my $branchcode = undef; +my $help = 0; + +my $result = GetOptions( + 'd|date=s' => \$hardduedate, + 't|type=s' => \$comparison, + 'c|categorycode=s' => \$category_code, + 'i|itemtype=s' => \$itemtype, + 'b|branchcode=s' => \$branchcode, + + 'h|help' => \$help +); + +my $hardduedatecompare = undef; +$hardduedatecompare = '-1' if ( $comparison eq 'before' ); +$hardduedatecompare = '0' if ( $comparison eq 'exactly_on' ); +$hardduedatecompare = '1' if ( $comparison eq 'after' ); + +if ( $help || !( $hardduedate =~ m /^[0-9]{4}-[0-9]{2}-[0-9]{2}/ ) || !defined($hardduedatecompare) ) { + print_usage(); + exit 0; +} + +my $dbh = C4::Context->dbh; + +my $query = "UPDATE issuingrules SET hardduedate = ?, hardduedatecompare = ?"; + +my @limits; +my @limit_params; + +if ( defined($category_code) ) { + push( @limits, "categorycode = ?" ); + push( @limit_params, $category_code ); +} + +if ( defined($itemtype) ) { + push( @limits, "itemtype = ?" ); + push( @limit_params, $itemtype ); +} + +if ( defined($branchcode) ) { + push( @limits, "branchcode = ?" ); + push( @limit_params, $branchcode ); +} + +$query .= " WHERE " . join( ' AND ', @limits ) if (@limits); + +my $rows_affected = $dbh->do( $query, undef, ( $hardduedate, $hardduedatecompare, @limit_params ) ); + +print "\nUpdate complete!\nRules updated: $rows_affected\n\n"; + +sub print_usage { + print <<_USAGE_; +$0: update hard due dates in multiple issuing rules at once. + +This script will allow you to update the hard due dates in multiple +issuing rules at once. Setting only --date and --type will affect *all* +issuing rules. To further limit, use -c, -i and/or -b. Note, using -c * or +-i * will not affect all rules, but only rules where the wildcard is set. + +Parameters: + -d --date the hard due date in ISO format, YYYY-MM-DD ( required ) + -t --type must be 'before', 'exactly_on', or 'after' ( required ) + + -c --categorycode affect only rules with this patron category code + -i --itemtype affect only rules with this item type + -b --branchcode affect only rules with this branchcode + + -h --help show this message. +_USAGE_ +} -- 1.7.2.5