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

(-)a/misc/modify_hard_due_dates.pl (-1 / +95 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
6
BEGIN {
7
8
    # find Koha's Perl modules
9
    # test carefully before changing this
10
    use FindBin;
11
    eval { require "$FindBin::Bin/kohalib.pl" };
12
}
13
14
use C4::Context;
15
16
use Getopt::Long;
17
18
$| = 1;
19
20
# command-line parameters
21
my $hardduedate   = undef;
22
my $comparison    = undef;
23
my $category_code = undef;
24
my $itemtype      = undef;
25
my $branchcode    = undef;
26
my $help          = 0;
27
28
my $result = GetOptions(
29
    'd|date=s'         => \$hardduedate,
30
    't|type=s'         => \$comparison,
31
    'c|categorycode=s' => \$category_code,
32
    'i|itemtype=s'     => \$itemtype,
33
    'b|branchcode=s'   => \$branchcode,
34
35
    'h|help' => \$help
36
);
37
38
my $hardduedatecompare = undef;
39
$hardduedatecompare = '-1' if ( $comparison eq 'before' );
40
$hardduedatecompare = '0'  if ( $comparison eq 'exactly_on' );
41
$hardduedatecompare = '1'  if ( $comparison eq 'after' );
42
43
if ( $help || !( $hardduedate =~ m /^[0-9]{4}-[0-9]{2}-[0-9]{2}/ ) || !defined($hardduedatecompare) ) {
44
    print_usage();
45
    exit 0;
46
}
47
48
my $dbh = C4::Context->dbh;
49
50
my $query = "UPDATE issuingrules SET hardduedate = ?, hardduedatecompare = ?";
51
52
my @limits;
53
my @limit_params;
54
55
if ( defined($category_code) ) {
56
    push( @limits,       "categorycode = ?" );
57
    push( @limit_params, $category_code );
58
}
59
60
if ( defined($itemtype) ) {
61
    push( @limits,       "itemtype = ?" );
62
    push( @limit_params, $itemtype );
63
}
64
65
if ( defined($branchcode) ) {
66
    push( @limits,       "branchcode = ?" );
67
    push( @limit_params, $branchcode );
68
}
69
70
$query .= " WHERE " . join( ' AND ', @limits ) if (@limits);
71
72
my $rows_affected = $dbh->do( $query, undef, ( $hardduedate, $hardduedatecompare, @limit_params ) );
73
74
print "\nUpdate complete!\nRules updated: $rows_affected\n\n";
75
76
sub print_usage {
77
    print <<_USAGE_;
78
$0: update hard due dates in multiple issuing rules at once.
79
80
This script will allow you to update the hard due dates in multiple
81
issuing rules at once. Setting only --date and --type will affect *all*
82
issuing rules. To further limit, use -c, -i and/or -b. Note, using -c * or
83
-i * will not affect all rules, but only rules where the wildcard is set.
84
85
Parameters:
86
    -d --date            the hard due date in ISO format, YYYY-MM-DD ( required )
87
    -t --type            must be 'before', 'exactly_on', or 'after' ( required )
88
    
89
    -c --categorycode    affect only rules with this patron category code
90
    -i --itemtype        affect only rules with this item type
91
    -b --branchcode      affect only rules with this branchcode
92
93
    -h --help            show this message.
94
_USAGE_
95
}

Return to bug 8985