bug 3481: Allow Item Temporary Locations for Processing and Shelving.
[koha.git] / misc / cronjobs / cart_to_shelf.pl
1 #!/usr/bin/perl
2 #-----------------------------------
3 # Copyright 2009 PTFS Inc.
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19 #-----------------------------------
20
21 =head1 NAME
22
23 cart_to_shelf.pl  cron script to set items with location of CART to original shelving location after X hours.
24                   Execute without options for help.
25
26 =cut
27
28 use strict;
29 use warnings;
30
31 BEGIN {
32
33     # find Koha's Perl modules
34     # test carefully before changing this
35     use FindBin;
36     eval { require "$FindBin::Bin/../kohalib.pl" };
37 }
38 use C4::Context;
39 use Getopt::Long;
40
41 my $hours = 0;
42
43 GetOptions( 'h|hours=s' => \$hours, );
44
45 my $usage = << 'ENDUSAGE';
46 longoverdue.pl : This cron script will set any item of the location CART ( Shelving Cart ) to it's original shelving location
47                  after the given numer of hours has passed.
48
49 This script takes the following parameters :
50
51     --hours | -h         The number of hours that need to pass before the location is updated.
52
53   examples :
54   $PERL5LIB/misc/cronjobs/cart_to_shelf.pl --hours 24
55     Would make any item that has a location of CART for more than 24 hours change to it's original shelving location.
56
57 ENDUSAGE
58
59 unless ($hours) {
60     print $usage;
61     die "ERROR: No --hours (-h) option defined";
62 }
63
64 my $query =
65 "UPDATE items SET location = permanent_location WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?";
66
67 my $dbh = C4::Context->dbh;
68 my $sth = $dbh->prepare($query);
69 $sth->execute($hours);