-package UsageStats;
+package C4::UsageStats;
# This file is part of Koha.
#
use POSIX qw(strftime);
use LWP::UserAgent;
use JSON;
-use URI::Encode qw(uri_encode);
-=head1 NAME C4::UsageStats
+=head1 NAME
+
+C4::UsageStats
=head1 DESCRIPTION
sub NeedUpdate {
my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
- my $now = strftime("%s", localtime);
+ my $now = strftime( "%s", localtime );
# Need to launch cron.
return 1 if $now - $lastupdated >= 2592000;
sub BuildReport {
my $report = {
library => {
+ id => C4::Context->preference('UsageStatsID') || 0,
name => C4::Context->preference('UsageStatsLibraryName') || q||,
- id => C4::Context->preference('UsageStatsID') || 0,
+ url => C4::Context->preference('UsageStatsLibraryUrl') || q||,
+ type => C4::Context->preference('UsageStatsLibraryType') || q||,
+ country => C4::Context->preference('UsageStatsCountry') || q||,
},
};
# Get database volumetry.
- foreach (qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/) {
+ foreach (
+ qw/biblio items auth_header old_issues old_reserves borrowers aqorders subscription/
+ )
+ {
$report->{volumetry}{$_} = _count($_);
}
AutoRemoveOverduesRestrictions
CircControl
HomeOrHoldingBranch
- HomeOrHoldingBranchReturn
InProcessingToShelvingCart
IssueLostItem
IssuingInProcess
AllowHoldPolicyOverride
AllowHoldsOnDamagedItems
AllowHoldsOnPatronsPossessions
- AllowOnShelfHolds
AutoResumeSuspendedHolds
canreservefromotherbranches
decreaseLoanHighHolds
itemBarcodeInputFilter
previousIssuesDefaultSortOrder
RecordLocalUseOnReturn
- soundon
+ AudioAlerts
SpecifyDueDate
todaysIssuesDefaultSortOrder
UpdateTotalIssuesOnCirc
AllowPurchaseSuggestionBranchChoice
OpacAllowPublicListCreation
OpacAllowSharingPrivateLists
- OPACItemHolds
OpacRenewalAllowed
OpacRenewalBranch
OPACViewOthersSuggestions
TrackClicks
PatronSelfRegistration
OPACShelfBrowser
- AddPatronLists
AutoEmailOpacUser
AutoEmailPrimaryAddress
autoMemberNum
=cut
sub ReportToCommunity {
- my $data = shift;
- my $json = uri_encode( to_json($data), 1 );
+ my $data = shift;
+ my $json = encode_json($data);
- my $ua = LWP::UserAgent->new;
- my $req =
- HTTP::Request->new( POST => "http://hea.koha-community.org/upload.pl" );
- $req->content_type('application/x-www-form-urlencoded');
- $req->content("data=$json");
- my $res = $ua->request($req);
- my $content = from_json( $res->decoded_content );
- C4::Context->set_preference( 'UsageStatsID',
- $content->{library}{library_id} );
+ my $url = "http://hea.koha-community.org/upload.pl";
+ my $ua = LWP::UserAgent->new;
+ my $res = $ua->post(
+ $url,
+ 'Content-type' => 'application/json;charset=utf-8',
+ Content => $json,
+ );
+ my $content = decode_json( $res->decoded_content );
+ C4::Context->set_preference( 'UsageStatsID',
+ $content->{library}{id} );
}
=head2 _count
=cut
sub _count {
- my $table = shift;
+ my $table = shift;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT count(*) from $table");
- $sth->execute;
- return $sth->fetchrow_array;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("SELECT count(*) from $table");
+ $sth->execute;
+ return $sth->fetchrow_array;
}
1;