From 8f8eef0b89ab468c39cf96add9c0fd11d3b7e5bc 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 | 134 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 134 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..ec76e28 --- /dev/null +++ b/misc/modify_hard_due_dates.pl @@ -0,0 +1,134 @@ +#!/usr/bin/perl + +# Copyright 2012 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +modify_hard_due_dates.pl : update hard due dates in multiple issuing rules at once. + +=head1 SYNOPSIS + +modify_hard_due_dates.pl -d 2013-06-10 -t before -c CC1 -c CC2 -i IT1 -i IT2 -b BC1 -b BC2 + +=head1 DESCRIPTION + +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. + +=head1 AUTHOR + +Kyle M Hall + +=cut + +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_codes; +my @itemtypes; +my @branchcodes; +my $help = 0; + +my $result = GetOptions( + 'd|date=s' => \$hardduedate, + 't|type=s' => \$comparison, + 'c|categorycode=s' => \@category_codes, + 'i|itemtype=s' => \@itemtypes, + 'b|branchcode=s' => \@branchcodes, + + '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 (@category_codes) { + push( @limits, " ( " . join( " OR ", ("categorycode = ?") x scalar(@category_codes) ) . " ) " ); + push( @limit_params, @category_codes ); +} + +if (@itemtypes) { + push( @limits, " ( " . join( " OR ", ("itemtype = ?") x scalar(@itemtypes) ) . " ) " ); + push( @limit_params, @itemtypes ); +} + +if (@branchcodes) { + push( @limits, " ( " . join( " OR ", ("branchcode = ?") x scalar(@branchcodes) ) . " ) " ); + push( @limit_params, @branchcodes ); +} + +$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 ( repeatable ) + -i --itemtype affect only rules with this item type ( repeatable ) + -b --branchcode affect only rules with this branchcode ( repeatable ) + + -h --help show this message. +_USAGE_ +} + -- 1.7.2.5