Bug 32565: (follow-up) Tidy
[koha.git] / misc / cronjobs / holds / build_holds_queue.pl
1 #!/usr/bin/perl 
2 #-----------------------------------
3 # Script Name: build_holds_queue.pl
4 # Description: builds a holds queue in the tmp_holdsqueue table
5 #-----------------------------------
6 # FIXME: add command-line options for verbosity and summary
7 # FIXME: expand perldoc, explain intended logic
8
9 use Modern::Perl;
10
11 use Getopt::Long qw( GetOptions );
12 use Pod::Usage qw( pod2usage );
13
14 use C4::Context;
15 use C4::HoldsQueue qw(CreateQueue);
16 use C4::Log qw( cronlogaction );
17 use Koha::Script -cron;
18
19 =head1 NAME
20
21 build_holds_queue.pl - Rebuild the holds queue
22
23 =head1 SYNOPSIS
24
25 build_holds_queue.pl [-f]
26
27  Options:
28    -h --help        Brief help message
29    -m --man         Full documentation
30    -f --force    Run holds queue builder even if RealTimeHoldsQueue is enabled
31
32 =head1 OPTIONS
33
34 =over 8
35
36 =item B<--help>
37
38 Print a brief help message and exits.
39
40 =item B<--man>
41
42 Prints the manual page and exits.
43
44 =item b<--force>
45
46 allows this script to rebuild the entire holds queue even if the realtimeholdsqueue system preference is enabled.
47
48 =item b<--unallocated>
49
50 prevents deletion of current queue and allows the script to only deal with holds not currently in the queue.
51 This is useful when using the realtimeholdsqueue and skipping closed libraries, or allowing holds in the future
52 This allows the script to catch holds that may have become active without triggering a real time update.
53
54 =back
55
56 =head1 DESCRIPTION
57
58 This script builds or rebuilds the entire holds queue.
59
60 =cut
61
62 my $help        = 0;
63 my $man         = 0;
64 my $force       = 0;
65 my $unallocated = 0;
66
67 my $command_line_options = join( " ", @ARGV );
68
69 GetOptions(
70     'h|help'        => \$help,
71     'm|man'         => \$man,
72     'f|force'       => \$force,
73     'u|unallocated' => \$unallocated
74 );
75 pod2usage(1)                              if $help;
76 pod2usage( -exitval => 0, -verbose => 2 ) if $man;
77
78 my $rthq = C4::Context->preference('RealTimeHoldsQueue');
79
80 if ( $rthq && !$force ) {
81     say "RealTimeHoldsQueue system preference is enabled, holds queue not built.";
82     say "Use --force to force building the holds queue.";
83     exit(1);
84 }
85
86 cronlogaction( { info => $command_line_options } );
87
88 CreateQueue( { unallocated => $unallocated } );
89
90 cronlogaction( { action => 'End', info => "COMPLETED" } );