Bug 11401: QA followup
[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
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
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 use C4::Items qw/ CartToShelf /;
32
33 BEGIN {
34
35     # find Koha's Perl modules
36     # test carefully before changing this
37     use FindBin;
38     eval { require "$FindBin::Bin/../kohalib.pl" };
39 }
40 use C4::Context;
41 use Getopt::Long;
42
43 my $hours = 0;
44
45 GetOptions( 'h|hours=s' => \$hours, );
46
47 my $usage = << 'ENDUSAGE';
48 cart_to_shelf.pl: This cron script will set any item of the location CART ( Shelving Cart ) to it's original shelving location
49                  after the given numer of hours has passed.
50
51 This script takes the following parameters :
52
53     --hours | -h         The number of hours that need to pass before the location is updated.
54
55   examples :
56   {Koha script directory}/cronjobs/cart_to_shelf.pl --hours 24
57     Would make any item that has a location of CART for more than 24 hours change to it's original shelving location.
58
59 ENDUSAGE
60
61 unless ($hours) {
62     print $usage;
63     die "ERROR: No --hours (-h) option defined";
64 }
65
66 my $query = "SELECT itemnumber FROM items WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?";
67 my $sth = C4::Context->dbh->prepare($query);
68 $sth->execute($hours);
69 while (my ($itemnumber) = $sth->fetchrow_array) {
70     CartToShelf($itemnumber);
71 }