Bugzilla – Attachment 32464 Details for
Bug 11926
HEA - Report usage statistics to Koha community
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 11926: Render community koha statistic usages
PASSED-QA-Bug-11926-Render-community-koha-statisti.patch (text/plain), 5.13 KB, created by
Katrin Fischer
on 2014-10-16 21:59:59 UTC
(
hide
)
Description:
[PASSED QA] Bug 11926: Render community koha statistic usages
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2014-10-16 21:59:59 UTC
Size:
5.13 KB
patch
obsolete
>From 2430bff5f3e238ebd31b7123f2dd04fe5a56f3b0 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Wed, 12 Mar 2014 09:07:06 +0100 >Subject: [PATCH] [PASSED QA] Bug 11926: Render community koha statistic usages > >Goals: >- Collecting Koha usage statistics >- Rendering stats on a community website >- Having a big bicture of how koha is used > >3 parts in the project: >- this patch in koha >- hea-ws which collects data >- hea-app which renders data > >Installation: >1/ Fill systempreferences: >UsageStatsLastUpdateTime UsageStatsID UsageStatsShare UsageStatsLibraryName >2/ Setup a cron in your crontab (ex: at 3:00 every first of the month): >0 3 1 * * export KOHA_CONF=/home/koha/etc/koha-conf.xml; export PERL5LIB=/home/koha/src; perl /home/koha/src/C4/UsageStats.pm > >Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > C4/UsageStats.pm | 95 ++++++++++++++++++++++ > .../prog/en/modules/admin/preferences/admin.pref | 25 ++++++ > 2 files changed, 120 insertions(+) > create mode 100644 C4/UsageStats.pm > >diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm >new file mode 100644 >index 0000000..5338df9 >--- /dev/null >+++ b/C4/UsageStats.pm >@@ -0,0 +1,95 @@ >+package UsageStats; >+ >+# Copyright 2000-2003 Katipo Communications >+# Copyright 2010 BibLibre >+# Parts Copyright 2010 Catalyst IT >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use C4::Context; >+use POSIX qw(strftime); >+use LWP::UserAgent; >+use JSON; >+ >+sub NeedUpdate { >+ my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0; >+ my $now = strftime("%s", localtime); >+ >+ # Need to launch cron. >+ return 1 if $now - $lastupdated >= 2592000; >+ >+ # Cron no need to be launched. >+ return 0; >+} >+ >+sub LaunchCron { >+ if (!C4::Context->preference('UsageStatsShare')) { >+ die ("UsageStats is not configured"); >+ } >+ if (NeedUpdate) { >+ C4::Context->set_preference('UsageStatsLastUpdateTime', strftime("%s", localtime)); >+ my $data = BuildReport(); >+ ReportToComunity($data); >+ } >+} >+ >+sub BuildReport { >+ my $report = { >+ 'library' => { >+ 'name' => C4::Context->preference('UsageStatsLibraryName'), >+ 'id' => C4::Context->preference('UsageStatsID') || 0, >+ }, >+ }; >+ >+ # Get database volumetry. >+ foreach (qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/) { >+ $report->{volumetry}{$_} = _count($_); >+ } >+ >+ # Get systempreferences. >+ foreach (qw/IntranetBiblioDefaultView marcflavour/) { >+ $report->{systempreferences}{$_} = C4::Context->preference($_); >+ } >+ return $report; >+} >+ >+sub ReportToComunity { >+ my $data = shift; >+ my $json = to_json($data); >+ >+ my $url = C4::Context->config('mebaseurl'); >+ >+ my $ua = LWP::UserAgent->new; >+ my $req = HTTP::Request->new(POST => "$url/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}); >+} >+ >+sub _count { >+ my $table = shift; >+ >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT count(*) from $table"); >+ $sth->execute; >+ return $sth->fetchrow_array; >+} >+ >+&LaunchCron; >+1; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >index c16138c..bbdcc73 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >@@ -105,3 +105,28 @@ Administration: > yes: Allow > no: "Don't Allow" > - Mozilla persona for login >+ Search Engine: >+ - >+ - pref: SearchEngine >+ default: Zebra >+ choices: >+ Solr: Solr >+ Zebra: Zebra >+ - is the search engine used. >+ Usage Stats: >+ - >+ - pref: UsageStatsLastUpdateTime >+ default: 0 >+ - stores the last time when cron were launch >+ - >+ - pref: UsageStatsID >+ default: >+ - >+ - >+ - pref: UsageStatsShare >+ default: >+ - >+ - >+ - pref: UsageStatsLibraryName >+ default: >+ - >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11926
:
26203
|
26346
|
26352
|
31369
|
31370
|
31373
|
32024
|
32025
|
32026
|
32027
|
32028
|
32029
|
32030
|
32262
|
32263
|
32264
|
32265
|
32266
|
32267
|
32268
|
32455
|
32456
|
32457
|
32458
|
32459
|
32460
|
32461
|
32462
|
32463
| 32464 |
32465
|
32466
|
32467
|
32468
|
32469
|
32470
|
32471
|
32472
|
32582