Lines 1-4
Link Here
|
1 |
package UsageStats; |
1 |
package C4::UsageStats; |
2 |
|
2 |
|
3 |
# This file is part of Koha. |
3 |
# This file is part of Koha. |
4 |
# |
4 |
# |
Lines 22-28
use C4::Context;
Link Here
|
22 |
use POSIX qw(strftime); |
22 |
use POSIX qw(strftime); |
23 |
use LWP::UserAgent; |
23 |
use LWP::UserAgent; |
24 |
use JSON; |
24 |
use JSON; |
25 |
use URI::Encode qw(uri_encode); |
|
|
26 |
|
25 |
|
27 |
=head1 NAME C4::UsageStats |
26 |
=head1 NAME C4::UsageStats |
28 |
|
27 |
|
Lines 45-51
only once a month !
Link Here
|
45 |
|
44 |
|
46 |
sub NeedUpdate { |
45 |
sub NeedUpdate { |
47 |
my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0; |
46 |
my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0; |
48 |
my $now = strftime("%s", localtime); |
47 |
my $now = strftime( "%s", localtime ); |
49 |
|
48 |
|
50 |
# Need to launch cron. |
49 |
# Need to launch cron. |
51 |
return 1 if $now - $lastupdated >= 2592000; |
50 |
return 1 if $now - $lastupdated >= 2592000; |
Lines 57-69
sub NeedUpdate {
Link Here
|
57 |
sub BuildReport { |
56 |
sub BuildReport { |
58 |
my $report = { |
57 |
my $report = { |
59 |
library => { |
58 |
library => { |
|
|
59 |
id => C4::Context->preference('UsageStatsID') || 0, |
60 |
name => C4::Context->preference('UsageStatsLibraryName') || q||, |
60 |
name => C4::Context->preference('UsageStatsLibraryName') || q||, |
61 |
id => C4::Context->preference('UsageStatsID') || 0, |
61 |
url => C4::Context->preference('UsageStatsLibraryUrl') || q||, |
|
|
62 |
type => C4::Context->preference('UsageStatsLibraryType') || q||, |
63 |
country => C4::Context->preference('UsageStatsCountry') || q||, |
62 |
}, |
64 |
}, |
63 |
}; |
65 |
}; |
64 |
|
66 |
|
65 |
# Get database volumetry. |
67 |
# Get database volumetry. |
66 |
foreach (qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/) { |
68 |
foreach ( |
|
|
69 |
qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/ |
70 |
) |
71 |
{ |
67 |
$report->{volumetry}{$_} = _count($_); |
72 |
$report->{volumetry}{$_} = _count($_); |
68 |
} |
73 |
} |
69 |
|
74 |
|
Lines 338-355
Send to hea.koha-community.org database informations
Link Here
|
338 |
=cut |
343 |
=cut |
339 |
|
344 |
|
340 |
sub ReportToCommunity { |
345 |
sub ReportToCommunity { |
341 |
my $data = shift; |
346 |
my $data = shift; |
342 |
my $json = uri_encode( to_json($data), 1 ); |
347 |
my $json = encode_json($data); |
343 |
|
348 |
|
344 |
my $ua = LWP::UserAgent->new; |
349 |
my $url = "http://hea.koha-community.org/upload.pl"; |
345 |
my $req = |
350 |
my $ua = LWP::UserAgent->new; |
346 |
HTTP::Request->new( POST => "http://hea.koha-community.org/upload.pl" ); |
351 |
my $res = $ua->post( |
347 |
$req->content_type('application/x-www-form-urlencoded'); |
352 |
$url, |
348 |
$req->content("data=$json"); |
353 |
'Content-type' => 'application/json;charset=utf-8', |
349 |
my $res = $ua->request($req); |
354 |
Content => $json, |
350 |
my $content = from_json( $res->decoded_content ); |
355 |
); |
351 |
C4::Context->set_preference( 'UsageStatsID', |
356 |
my $content = decode_json( $res->decoded_content ); |
352 |
$content->{library}{library_id} ); |
357 |
C4::Context->set_preference( 'UsageStatsID', |
|
|
358 |
$content->{library}{id} ); |
353 |
} |
359 |
} |
354 |
|
360 |
|
355 |
=head2 _count |
361 |
=head2 _count |
Lines 361-372
Count the number of records in $table tables
Link Here
|
361 |
=cut |
367 |
=cut |
362 |
|
368 |
|
363 |
sub _count { |
369 |
sub _count { |
364 |
my $table = shift; |
370 |
my $table = shift; |
365 |
|
371 |
|
366 |
my $dbh = C4::Context->dbh; |
372 |
my $dbh = C4::Context->dbh; |
367 |
my $sth = $dbh->prepare("SELECT count(*) from $table"); |
373 |
my $sth = $dbh->prepare("SELECT count(*) from $table"); |
368 |
$sth->execute; |
374 |
$sth->execute; |
369 |
return $sth->fetchrow_array; |
375 |
return $sth->fetchrow_array; |
370 |
} |
376 |
} |
371 |
|
377 |
|
372 |
1; |
378 |
1; |