Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2012 ByWater Solutions |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 2 of the License, or (at your option) any later |
10 |
# version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
=head1 NAME |
21 |
|
22 |
modify_hard_due_dates.pl : update hard due dates in multiple issuing rules at once. |
23 |
|
24 |
=head1 SYNOPSIS |
25 |
|
26 |
modify_hard_due_dates.pl -d 2013-06-10 -t before -c CC1 -c CC2 -i IT1 -i IT2 -b BC1 -b BC2 |
27 |
|
28 |
=head1 DESCRIPTION |
29 |
|
30 |
This script will allow you to update the hard due dates in multiple |
31 |
issuing rules at once. Setting only --date and --type will affect *all* |
32 |
issuing rules. To further limit, use -c, -i and/or -b. Note, using -c '*' or |
33 |
-i '*' will not affect all rules, but only rules where the wildcard is set. |
34 |
|
35 |
=head1 AUTHOR |
36 |
|
37 |
Kyle M Hall <kyle@bywatersolutions.com> |
38 |
|
39 |
=cut |
40 |
|
41 |
use strict; |
42 |
use warnings; |
43 |
|
44 |
BEGIN { |
45 |
|
46 |
# find Koha's Perl modules |
47 |
# test carefully before changing this |
48 |
use FindBin; |
49 |
eval { require "$FindBin::Bin/kohalib.pl" }; |
50 |
} |
51 |
|
52 |
use C4::Context; |
53 |
|
54 |
use Getopt::Long; |
55 |
|
56 |
$| = 1; |
57 |
|
58 |
# command-line parameters |
59 |
my $hardduedate = undef; |
60 |
my $comparison = undef; |
61 |
my @category_codes; |
62 |
my @itemtypes; |
63 |
my @branchcodes; |
64 |
my $help = 0; |
65 |
|
66 |
my $result = GetOptions( |
67 |
'd|date=s' => \$hardduedate, |
68 |
't|type=s' => \$comparison, |
69 |
'c|categorycode=s' => \@category_codes, |
70 |
'i|itemtype=s' => \@itemtypes, |
71 |
'b|branchcode=s' => \@branchcodes, |
72 |
|
73 |
'h|help' => \$help |
74 |
); |
75 |
|
76 |
my $hardduedatecompare = undef; |
77 |
$hardduedatecompare = '-1' if ( $comparison eq 'before' ); |
78 |
$hardduedatecompare = '0' if ( $comparison eq 'exactly_on' ); |
79 |
$hardduedatecompare = '1' if ( $comparison eq 'after' ); |
80 |
|
81 |
if ( $help || !( $hardduedate =~ m /^[0-9]{4}-[0-9]{2}-[0-9]{2}/ ) || !defined($hardduedatecompare) ) { |
82 |
print_usage(); |
83 |
exit 0; |
84 |
} |
85 |
|
86 |
my $dbh = C4::Context->dbh; |
87 |
|
88 |
my $query = "UPDATE issuingrules SET hardduedate = ?, hardduedatecompare = ?"; |
89 |
|
90 |
my @limits; |
91 |
my @limit_params; |
92 |
|
93 |
if (@category_codes) { |
94 |
push( @limits, " ( " . join( " OR ", ("categorycode = ?") x scalar(@category_codes) ) . " ) " ); |
95 |
push( @limit_params, @category_codes ); |
96 |
} |
97 |
|
98 |
if (@itemtypes) { |
99 |
push( @limits, " ( " . join( " OR ", ("itemtype = ?") x scalar(@itemtypes) ) . " ) " ); |
100 |
push( @limit_params, @itemtypes ); |
101 |
} |
102 |
|
103 |
if (@branchcodes) { |
104 |
push( @limits, " ( " . join( " OR ", ("branchcode = ?") x scalar(@branchcodes) ) . " ) " ); |
105 |
push( @limit_params, @branchcodes ); |
106 |
} |
107 |
|
108 |
$query .= " WHERE " . join( ' AND ', @limits ) if (@limits); |
109 |
|
110 |
my $rows_affected = $dbh->do( $query, undef, ( $hardduedate, $hardduedatecompare, @limit_params ) ); |
111 |
|
112 |
print "\nUpdate complete!\nRules updated: $rows_affected\n\n"; |
113 |
|
114 |
sub print_usage { |
115 |
print <<_USAGE_; |
116 |
$0: update hard due dates in multiple issuing rules at once. |
117 |
|
118 |
This script will allow you to update the hard due dates in multiple |
119 |
issuing rules at once. Setting only --date and --type will affect *all* |
120 |
issuing rules. To further limit, use -c, -i and/or -b. Note, using -c '*' or |
121 |
-i '*' will not affect all rules, but only rules where the wildcard is set. |
122 |
|
123 |
Parameters: |
124 |
-d --date the hard due date in ISO format, YYYY-MM-DD ( required ) |
125 |
-t --type must be 'before', 'exactly_on', or 'after' ( required ) |
126 |
|
127 |
-c --categorycode affect only rules with this patron category code ( repeatable ) |
128 |
-i --itemtype affect only rules with this item type ( repeatable ) |
129 |
-b --branchcode affect only rules with this branchcode ( repeatable ) |
130 |
|
131 |
-h --help show this message. |
132 |
_USAGE_ |
133 |
} |
134 |
|