Lines 21-37
use strict;
Link Here
|
21 |
use warnings; |
21 |
use warnings; |
22 |
|
22 |
|
23 |
use Getopt::Long qw( GetOptions ); |
23 |
use Getopt::Long qw( GetOptions ); |
24 |
use Pod::Usage qw( pod2usage ); |
24 |
use Pod::Usage qw( pod2usage ); |
25 |
|
25 |
|
26 |
use Koha::Script -cron; |
26 |
use Koha::Script -cron; |
27 |
use Koha::DateUtils qw( dt_from_string ); |
27 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
use C4::Context; |
28 |
use C4::Context; |
29 |
use C4::Biblio qw( UpdateTotalIssues ); |
29 |
use C4::Biblio qw( UpdateTotalIssues ); |
30 |
use C4::Log qw( cronlogaction ); |
30 |
use C4::Log qw( cronlogaction ); |
31 |
use DateTime; |
31 |
use DateTime; |
32 |
use DateTime::Format::MySQL; |
32 |
use DateTime::Format::MySQL; |
33 |
use Time::HiRes qw( time ); |
33 |
use Time::HiRes qw( time ); |
34 |
use POSIX qw( ceil strftime ); |
34 |
use POSIX qw( ceil strftime ); |
35 |
|
35 |
|
36 |
sub usage { |
36 |
sub usage { |
37 |
pod2usage( -verbose => 2 ); |
37 |
pod2usage( -verbose => 2 ); |
Lines 49-58
my $interval;
Link Here
|
49 |
my $usestats = 0; |
49 |
my $usestats = 0; |
50 |
my $useitems = 0; |
50 |
my $useitems = 0; |
51 |
my $incremental = 0; |
51 |
my $incremental = 0; |
52 |
my $progress = 100; |
52 |
my $progress = 100; |
53 |
my $unit; |
53 |
my $unit; |
54 |
|
54 |
|
55 |
my $command_line_options = join(" ",@ARGV); |
55 |
my $command_line_options = join( " ", @ARGV ); |
56 |
|
56 |
|
57 |
my $result = GetOptions( |
57 |
my $result = GetOptions( |
58 |
'v|verbose' => \$verbose, |
58 |
'v|verbose' => \$verbose, |
Lines 62-68
my $result = GetOptions(
Link Here
|
62 |
'use-stats' => \$usestats, |
62 |
'use-stats' => \$usestats, |
63 |
'use-items' => \$useitems, |
63 |
'use-items' => \$useitems, |
64 |
'incremental' => \$incremental, |
64 |
'incremental' => \$incremental, |
65 |
'p|progress=i' => \$progress, |
65 |
'p|progress=i' => \$progress, |
66 |
'h|help' => \$want_help |
66 |
'h|help' => \$want_help |
67 |
); |
67 |
); |
68 |
|
68 |
|
Lines 74-81
if ( defined $since && defined $interval ) {
Link Here
|
74 |
} |
74 |
} |
75 |
|
75 |
|
76 |
if ( $useitems && $incremental ) { |
76 |
if ( $useitems && $incremental ) { |
77 |
print |
77 |
print "The --use-items and --incremental options are mutually exclusive.\n\n"; |
78 |
"The --use-items and --incremental options are mutually exclusive.\n\n"; |
|
|
79 |
$want_help = 1; |
78 |
$want_help = 1; |
80 |
} |
79 |
} |
81 |
|
80 |
|
Lines 90-96
unless ( $usestats || $useitems ) {
Link Here
|
90 |
|
89 |
|
91 |
usage() if $want_help; |
90 |
usage() if $want_help; |
92 |
|
91 |
|
93 |
cronlogaction({ info => $command_line_options }); |
92 |
cronlogaction( { info => $command_line_options } ); |
94 |
|
93 |
|
95 |
my $dbh = C4::Context->dbh; |
94 |
my $dbh = C4::Context->dbh; |
96 |
|
95 |
|
Lines 105-117
process_stats() if $usestats;
Link Here
|
105 |
|
104 |
|
106 |
report(); |
105 |
report(); |
107 |
|
106 |
|
108 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
107 |
cronlogaction( { action => 'End', info => "COMPLETED" } ); |
109 |
|
108 |
|
110 |
exit 0; |
109 |
exit 0; |
111 |
|
110 |
|
112 |
sub process_items { |
111 |
sub process_items { |
113 |
my $query = |
112 |
my $query = "SELECT items.biblionumber, SUM(items.issues) FROM items GROUP BY items.biblionumber;"; |
114 |
"SELECT items.biblionumber, SUM(items.issues) FROM items GROUP BY items.biblionumber;"; |
|
|
115 |
process_query($query); |
113 |
process_query($query); |
116 |
} |
114 |
} |
117 |
|
115 |
|
Lines 128-142
sub process_stats {
Link Here
|
128 |
); |
126 |
); |
129 |
|
127 |
|
130 |
$interval =~ m/([0-9]*)([hdwmy]?)$/; |
128 |
$interval =~ m/([0-9]*)([hdwmy]?)$/; |
131 |
$unit = $2 || 'd'; |
129 |
$unit = $2 || 'd'; |
132 |
$since = DateTime::Format::MySQL->format_datetime( |
130 |
$since = DateTime::Format::MySQL->format_datetime( $dt->subtract( $units{$unit} => $1 ) ); |
133 |
$dt->subtract( $units{$unit} => $1 ) ); |
|
|
134 |
} |
131 |
} |
135 |
my $limit = ''; |
132 |
my $limit = ''; |
136 |
$limit = " WHERE statistics.datetime >= ?" if ( $interval || $since ); |
133 |
$limit = " WHERE statistics.datetime >= ?" if ( $interval || $since ); |
137 |
|
134 |
|
138 |
my $query = |
135 |
my $query = "SELECT biblio.biblionumber, COUNT(statistics.itemnumber) FROM biblio\ |
139 |
"SELECT biblio.biblionumber, COUNT(statistics.itemnumber) FROM biblio\ |
|
|
140 |
LEFT JOIN items ON (biblio.biblionumber=items.biblionumber)\ |
136 |
LEFT JOIN items ON (biblio.biblionumber=items.biblionumber)\ |
141 |
LEFT JOIN statistics ON (items.itemnumber=statistics.itemnumber AND statistics.type = 'issue') |
137 |
LEFT JOIN statistics ON (items.itemnumber=statistics.itemnumber AND statistics.type = 'issue') |
142 |
$limit\ |
138 |
$limit\ |
Lines 152-159
sub process_query {
Link Here
|
152 |
|
148 |
|
153 |
if ( $since && $uselimit ) { |
149 |
if ( $since && $uselimit ) { |
154 |
$sth->execute($since); |
150 |
$sth->execute($since); |
155 |
} |
151 |
} else { |
156 |
else { |
|
|
157 |
$sth->execute(); |
152 |
$sth->execute(); |
158 |
} |
153 |
} |
159 |
|
154 |
|
Lines 161-167
sub process_query {
Link Here
|
161 |
$num_bibs_processed++; |
156 |
$num_bibs_processed++; |
162 |
$totalissues = 0 unless $totalissues; |
157 |
$totalissues = 0 unless $totalissues; |
163 |
print "Processing bib $biblionumber ($totalissues issues)\n" |
158 |
print "Processing bib $biblionumber ($totalissues issues)\n" |
164 |
if $verbose; |
159 |
if $verbose; |
165 |
if ( not $test_only ) { |
160 |
if ( not $test_only ) { |
166 |
my $ret; |
161 |
my $ret; |
167 |
if ( $incremental && $totalissues > 0 ) { |
162 |
if ( $incremental && $totalissues > 0 ) { |
Lines 184-190
sub process_query {
Link Here
|
184 |
} |
179 |
} |
185 |
|
180 |
|
186 |
sub report { |
181 |
sub report { |
187 |
my $endtime = time(); |
182 |
my $endtime = time(); |
188 |
my $totaltime = ceil( ( $endtime - $starttime ) * 1000 ); |
183 |
my $totaltime = ceil( ( $endtime - $starttime ) * 1000 ); |
189 |
$starttime = strftime( '%D %T', localtime($starttime) ); |
184 |
$starttime = strftime( '%D %T', localtime($starttime) ); |
190 |
$endtime = strftime( '%D %T', localtime($endtime) ); |
185 |
$endtime = strftime( '%D %T', localtime($endtime) ); |
Lines 269-275
processing the last twenty-four hours.
Link Here
|
269 |
|
264 |
|
270 |
=item B<--progress=N> |
265 |
=item B<--progress=N> |
271 |
|
266 |
|
272 |
Print the progress to standart output after every N records are processed. |
267 |
Print the progress to standard output after every N records are processed. |
273 |
|
268 |
|
274 |
=item B<--test> |
269 |
=item B<--test> |
275 |
|
270 |
|
276 |
- |
|
|