View | Details | Raw Unified | Return to bug 8985
Collapse All | Expand All

(-)a/misc/modify_hard_due_dates.pl (-1 / +143 lines)
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 $remove      = undef;
62
my @category_codes;
63
my @itemtypes;
64
my @branchcodes;
65
my $help = 0;
66
67
my $result = GetOptions(
68
    'd|date=s'         => \$hardduedate,
69
    't|type=s'         => \$comparison,
70
    'r|remove'         => \$remove,
71
    'c|categorycode=s' => \@category_codes,
72
    'i|itemtype=s'     => \@itemtypes,
73
    'b|branchcode=s'   => \@branchcodes,
74
75
    'h|help' => \$help
76
);
77
78
my $hardduedatecompare = undef;
79
if ( defined($comparison) ) {
80
    $hardduedatecompare = '-1' if ( $comparison eq 'before' );
81
    $hardduedatecompare = '0'  if ( $comparison eq 'exactly_on' );
82
    $hardduedatecompare = '1'  if ( $comparison eq 'after' );
83
}
84
85
if ($help
86
    || ( defined($hardduedate) && !( $hardduedate =~ m /^[0-9]{4}-[0-9]{2}-[0-9]{2}/ ) )    ## date set but not in ISO
87
    || ( !$remove && !( $hardduedate && $hardduedatecompare ) )                             ## we need either ( -d and -t ) or just -r
88
    || ( $remove && ( $hardduedate || $hardduedatecompare ) )                               ## but not -r and ( -d or -t )
89
  ) {
90
    print_usage();
91
    exit 0;
92
}
93
94
my $dbh = C4::Context->dbh;
95
96
my $query = "UPDATE issuingrules SET hardduedate = ?, hardduedatecompare = ?";
97
98
my @limits;
99
my @limit_params;
100
101
if (@category_codes) {
102
    push( @limits, " ( " . join( " OR ", ("categorycode = ?") x scalar(@category_codes) ) . " ) " );
103
    push( @limit_params, @category_codes );
104
}
105
106
if (@itemtypes) {
107
    push( @limits, " ( " . join( " OR ", ("itemtype = ?") x scalar(@itemtypes) ) . " ) " );
108
    push( @limit_params, @itemtypes );
109
}
110
111
if (@branchcodes) {
112
    push( @limits, " ( " . join( " OR ", ("branchcode = ?") x scalar(@branchcodes) ) . " ) " );
113
    push( @limit_params, @branchcodes );
114
}
115
116
$query .= " WHERE " . join( ' AND ', @limits ) if (@limits);
117
118
my $rows_affected = $dbh->do( $query, undef, ( $hardduedate, $hardduedatecompare, @limit_params ) );
119
120
print "\nUpdate complete!\nRules updated: $rows_affected\n\n";
121
122
sub print_usage {
123
    print <<_USAGE_;
124
$0: update hard due dates in multiple issuing rules at once.
125
126
This script will allow you to update the hard due dates in multiple
127
issuing rules at once. Setting only --date and --type will affect *all*
128
issuing rules. To further limit, use -c, -i and/or -b. Note, using -c '*' or
129
-i '*' will not affect all rules, but only rules where the wildcard is set.
130
131
Parameters:
132
    -d --date            the hard due date in ISO format, YYYY-MM-DD ( required unless -r )
133
    -t --type            must be 'before', 'exactly_on', or 'after' ( required unless -r )
134
    -r --remove          remove the hard due date from a rule ( forbidden if -d and -t )
135
    
136
    -c --categorycode    affect only rules with this patron category code ( repeatable )
137
    -i --itemtype        affect only rules with this item type ( repeatable )
138
    -b --branchcode      affect only rules with this branchcode ( repeatable )
139
140
    -h --help            show this message.
141
_USAGE_
142
}
143

Return to bug 8985