Browse Source

Bug 11926: Add a cronjob

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
MM-OPAC/theme_dep
Jonathan Druart 10 years ago
committed by Tomas Cohen Arazi
parent
commit
3da1960d21
  1. 610
      C4/UsageStats.pm
  2. 21
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
  3. 98
      misc/cronjobs/share_usage_with_koha_community.pl

610
C4/UsageStats.pm

@ -1,25 +1,23 @@
package UsageStats; package UsageStats;
# Copyright 2000-2003 Katipo Communications
# Copyright 2010 BibLibre
# Parts Copyright 2010 Catalyst IT
#
# This file is part of Koha. # This file is part of Koha.
# #
# Koha is free software; you can redistribute it and/or modify it under the # Copyright 2014 BibLibre
# 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 # Koha is free software; you can redistribute it and/or modify it
# version. # under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# #
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY # Koha is distributed in the hope that it will be useful, but
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # WITHOUT ANY WARRANTY; without even the implied warranty of
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. # 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 # You should have received a copy of the GNU General Public License
# with Koha; if not, write to the Free Software Foundation, Inc., # along with Koha; if not, see <http://www.gnu.org/licenses>.
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict; use Modern::Perl;
use C4::Context; use C4::Context;
use POSIX qw(strftime); use POSIX qw(strftime);
use LWP::UserAgent; use LWP::UserAgent;
@ -35,13 +33,6 @@ hea.koha-community.org is the server that centralize Koha setups informations
Koha libraries are encouraged to provide informations about their collections, Koha libraries are encouraged to provide informations about their collections,
their structure,... their structure,...
This package is normally only called by a cronjob, like
0 3 1 * * export KOHA_CONF=/home/koha/etc/koha-conf.xml; export PERL5LIB=/home/koha/src; perl /home/koha/src/C4/UsageStats.pm
IMPORTANT : please do NOT run the cron on the 1st, but on another day. The idea is to avoid all
Koha libraries sending their data at the same time ! So choose any day between 1 and 28 !
=head2 NeedUpdate =head2 NeedUpdate
$needUpdateYN = C4::UsageStats::NeedUpdate; $needUpdateYN = C4::UsageStats::NeedUpdate;
@ -59,42 +50,15 @@ sub NeedUpdate {
# Need to launch cron. # Need to launch cron.
return 1 if $now - $lastupdated >= 2592000; return 1 if $now - $lastupdated >= 2592000;
# Cron no need to be launched. # Data don't need to be updated
return 0; return 0;
} }
=head2 LaunchCron
LaunchCron();
Compute results and send them to the centralized server
=cut
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();
ReportToCommunity($data);
}
}
=head2 Builreport
BuildReport();
retrieve some database volumety and systempreferences that will be sent to hea server
=cut
sub BuildReport { sub BuildReport {
my $report = { my $report = {
'library' => { library => {
'name' => C4::Context->preference('UsageStatsLibraryName'), name => C4::Context->preference('UsageStatsLibraryName') || q||,
'id' => C4::Context->preference('UsageStatsID') || 0, id => C4::Context->preference('UsageStatsID') || 0,
}, },
}; };
@ -104,257 +68,262 @@ sub BuildReport {
} }
# Get systempreferences. # Get systempreferences.
foreach (qw/ AcqCreateItem foreach (
AcqWarnOnDuplicateInvoice qw/
AcqViewBaskets AcqCreateItem
BasketConfirmations AcqWarnOnDuplicateInvoice
OrderPdfFormat AcqViewBaskets
casAuthentication BasketConfirmations
casLogout OrderPdfFormat
AllowPkiAuth casAuthentication
DebugLevel casLogout
delimiter AllowPkiAuth
noItemTypeImages DebugLevel
virtualshelves delimiter
AutoLocation noItemTypeImages
IndependentBranches virtualshelves
SessionStorage AutoLocation
Persona IndependentBranches
AuthDisplayHierarchy SessionStorage
AutoCreateAuthorities Persona
BiblioAddsAuthorities AuthDisplayHierarchy
dontmerge AutoCreateAuthorities
UseAuthoritiesForTracings BiblioAddsAuthorities
CatalogModuleRelink dontmerge
hide_marc UseAuthoritiesForTracings
IntranetBiblioDefaultView CatalogModuleRelink
LabelMARCView hide_marc
OpacSuppression IntranetBiblioDefaultView
SeparateHoldings LabelMARCView
UseControlNumber OpacSuppression
advancedMARCeditor SeparateHoldings
DefaultClassificationSource UseControlNumber
EasyAnalyticalRecords advancedMARCeditor
autoBarcode DefaultClassificationSource
item-level_itypes EasyAnalyticalRecords
marcflavour autoBarcode
PrefillItem item-level_itypes
z3950NormalizeAuthor marcflavour
SpineLabelAutoPrint PrefillItem
SpineLabelShowPrintOnBibDetails z3950NormalizeAuthor
BlockReturnOfWithdrawnItems SpineLabelAutoPrint
CalculateFinesOnReturn SpineLabelShowPrintOnBibDetails
AgeRestrictionOverride BlockReturnOfWithdrawnItems
AllFinesNeedOverride CalculateFinesOnReturn
AllowFineOverride AgeRestrictionOverride
AllowItemsOnHoldCheckout AllFinesNeedOverride
AllowNotForLoanOverride AllowFineOverride
AllowRenewalLimitOverride AllowItemsOnHoldCheckout
AllowReturnToBranch AllowNotForLoanOverride
AllowTooManyOverride AllowRenewalLimitOverride
AutomaticItemReturn AllowReturnToBranch
AutoRemoveOverduesRestrictions AllowTooManyOverride
CircControl AutomaticItemReturn
HomeOrHoldingBranch AutoRemoveOverduesRestrictions
HomeOrHoldingBranchReturn CircControl
InProcessingToShelvingCart HomeOrHoldingBranch
IssueLostItem HomeOrHoldingBranchReturn
IssuingInProcess InProcessingToShelvingCart
ManInvInNoissuesCharge IssueLostItem
OverduesBlockCirc IssuingInProcess
RenewalPeriodBase ManInvInNoissuesCharge
RenewalSendNotice OverduesBlockCirc
RentalsInNoissuesCharge RenewalPeriodBase
ReturnBeforeExpiry RenewalSendNotice
ReturnToShelvingCart RentalsInNoissuesCharge
TransfersMaxDaysWarning ReturnBeforeExpiry
UseBranchTransferLimits ReturnToShelvingCart
useDaysMode TransfersMaxDaysWarning
UseTransportCostMatrix UseBranchTransferLimits
UseCourseReserves useDaysMode
finesCalendar UseTransportCostMatrix
FinesIncludeGracePeriod UseCourseReserves
finesMode finesCalendar
RefundLostItemFeeOnReturn FinesIncludeGracePeriod
WhenLostChargeReplacementFee finesMode
WhenLostForgiveFine RefundLostItemFeeOnReturn
AllowHoldDateInFuture WhenLostChargeReplacementFee
AllowHoldPolicyOverride WhenLostForgiveFine
AllowHoldsOnDamagedItems AllowHoldDateInFuture
AllowHoldsOnPatronsPossessions AllowHoldPolicyOverride
AllowOnShelfHolds AllowHoldsOnDamagedItems
AutoResumeSuspendedHolds AllowHoldsOnPatronsPossessions
canreservefromotherbranches AllowOnShelfHolds
decreaseLoanHighHolds AutoResumeSuspendedHolds
DisplayMultiPlaceHold canreservefromotherbranches
emailLibrarianWhenHoldIsPlaced decreaseLoanHighHolds
ExpireReservesMaxPickUpDelay DisplayMultiPlaceHold
OPACAllowHoldDateInFuture emailLibrarianWhenHoldIsPlaced
OPACAllowUserToChooseBranch ExpireReservesMaxPickUpDelay
ReservesControlBranch OPACAllowHoldDateInFuture
ReservesNeedReturns OPACAllowUserToChooseBranch
SuspendHoldsIntranet ReservesControlBranch
SuspendHoldsOpac ReservesNeedReturns
TransferWhenCancelAllWaitingHolds SuspendHoldsIntranet
AllowAllMessageDeletion SuspendHoldsOpac
AllowOfflineCirculation TransferWhenCancelAllWaitingHolds
CircAutocompl AllowAllMessageDeletion
CircAutoPrintQuickSlip AllowOfflineCirculation
DisplayClearScreenButton CircAutocompl
FilterBeforeOverdueReport CircAutoPrintQuickSlip
FineNotifyAtCheckin DisplayClearScreenButton
itemBarcodeFallbackSearch FilterBeforeOverdueReport
itemBarcodeInputFilter FineNotifyAtCheckin
previousIssuesDefaultSortOrder itemBarcodeFallbackSearch
RecordLocalUseOnReturn itemBarcodeInputFilter
soundon previousIssuesDefaultSortOrder
SpecifyDueDate RecordLocalUseOnReturn
todaysIssuesDefaultSortOrder soundon
UpdateTotalIssuesOnCirc SpecifyDueDate
UseTablesortForCirc todaysIssuesDefaultSortOrder
WaitingNotifyAtCheckin UpdateTotalIssuesOnCirc
AllowSelfCheckReturns UseTablesortForCirc
AutoSelfCheckAllowed WaitingNotifyAtCheckin
FRBRizeEditions AllowSelfCheckReturns
OPACFRBRizeEditions AutoSelfCheckAllowed
AmazonCoverImages FRBRizeEditions
OPACAmazonCoverImages OPACFRBRizeEditions
Babeltheque AmazonCoverImages
BakerTaylorEnabled OPACAmazonCoverImages
GoogleJackets Babeltheque
HTML5MediaEnabled BakerTaylorEnabled
IDreamBooksReadometer GoogleJackets
IDreamBooksResults HTML5MediaEnabled
IDreamBooksReviews IDreamBooksReadometer
LibraryThingForLibrariesEnabled IDreamBooksResults
LocalCoverImages IDreamBooksReviews
OPACLocalCoverImages LibraryThingForLibrariesEnabled
NovelistSelectEnabled LocalCoverImages
XISBN OPACLocalCoverImages
OpenLibraryCovers NovelistSelectEnabled
UseKohaPlugins XISBN
SyndeticsEnabled OpenLibraryCovers
TagsEnabled UseKohaPlugins
CalendarFirstDayOfWeek SyndeticsEnabled
opaclanguagesdisplay TagsEnabled
AuthoritiesLog CalendarFirstDayOfWeek
BorrowersLog opaclanguagesdisplay
CataloguingLog AuthoritiesLog
FinesLog BorrowersLog
IssueLog CataloguingLog
LetterLog FinesLog
ReturnLog IssueLog
SubscriptionLog LetterLog
AuthorisedValueImages ReturnLog
BiblioDefaultView SubscriptionLog
COinSinOPACResults AuthorisedValueImages
DisplayOPACiconsXSLT BiblioDefaultView
hidelostitems COinSinOPACResults
HighlightOwnItemsOnOPAC DisplayOPACiconsXSLT
OpacAddMastheadLibraryPulldown hidelostitems
OPACDisplay856uAsImage HighlightOwnItemsOnOPAC
OpacHighlightedWords OpacAddMastheadLibraryPulldown
OpacKohaUrl OPACDisplay856uAsImage
OpacMaintenance OpacHighlightedWords
OpacPublic OpacKohaUrl
OpacSeparateHoldings OpacMaintenance
OPACShowBarcode OpacPublic
OPACShowCheckoutName OpacSeparateHoldings
OpacShowFiltersPulldownMobile OPACShowBarcode
OPACShowHoldQueueDetails OPACShowCheckoutName
OpacShowLibrariesPulldownMobile OpacShowFiltersPulldownMobile
OpacShowRecentComments OPACShowHoldQueueDetails
OPACShowUnusedAuthorities OpacShowLibrariesPulldownMobile
OpacStarRatings OpacShowRecentComments
opacthemes OPACShowUnusedAuthorities
OPACURLOpenInNewWindow OpacStarRatings
OpacAuthorities opacthemes
opacbookbag OPACURLOpenInNewWindow
OpacBrowser OpacAuthorities
OpacBrowseResults opacbookbag
OpacCloud OpacBrowser
OPACFinesTab OpacBrowseResults
OpacHoldNotes OpacCloud
OpacItemLocation OPACFinesTab
OpacPasswordChange OpacHoldNotes
OPACPatronDetails OpacItemLocation
OPACpatronimages OpacPasswordChange
OPACPopupAuthorsSearch OPACPatronDetails
OpacTopissue OPACpatronimages
opacuserlogin OPACPopupAuthorsSearch
QuoteOfTheDay OpacTopissue
RequestOnOpac opacuserlogin
reviewson QuoteOfTheDay
ShowReviewer RequestOnOpac
ShowReviewerPhoto reviewson
SocialNetworks ShowReviewer
suggestion ShowReviewerPhoto
AllowPurchaseSuggestionBranchChoice SocialNetworks
OpacAllowPublicListCreation suggestion
OpacAllowSharingPrivateLists AllowPurchaseSuggestionBranchChoice
OPACItemHolds OpacAllowPublicListCreation
OpacRenewalAllowed OpacAllowSharingPrivateLists
OpacRenewalBranch OPACItemHolds
OPACViewOthersSuggestions OpacRenewalAllowed
SearchMyLibraryFirst OpacRenewalBranch
singleBranchMode OPACViewOthersSuggestions
AnonSuggestions SearchMyLibraryFirst
EnableOpacSearchHistory singleBranchMode
OPACPrivacy AnonSuggestions
opacreadinghistory EnableOpacSearchHistory
TrackClicks OPACPrivacy
PatronSelfRegistration opacreadinghistory
OPACShelfBrowser TrackClicks
AddPatronLists PatronSelfRegistration
AutoEmailOpacUser OPACShelfBrowser
AutoEmailPrimaryAddress AddPatronLists
autoMemberNum AutoEmailOpacUser
BorrowerRenewalPeriodBase AutoEmailPrimaryAddress
checkdigit autoMemberNum
EnableBorrowerFiles BorrowerRenewalPeriodBase
EnhancedMessagingPreferences checkdigit
ExtendedPatronAttributes EnableBorrowerFiles
intranetreadinghistory EnhancedMessagingPreferences
memberofinstitution ExtendedPatronAttributes
patronimages intranetreadinghistory
TalkingTechItivaPhoneNotification memberofinstitution
uppercasesurnames patronimages
IncludeSeeFromInSearches TalkingTechItivaPhoneNotification
OpacGroupResults uppercasesurnames
QueryAutoTruncate IncludeSeeFromInSearches
QueryFuzzy OpacGroupResults
QueryStemming QueryAutoTruncate
QueryWeightFields QueryFuzzy
TraceCompleteSubfields QueryStemming
TraceSubjectSubdivisions QueryWeightFields
UseICU TraceCompleteSubfields
UseQueryParser TraceSubjectSubdivisions
defaultSortField UseICU
displayFacetCount UseQueryParser
OPACdefaultSortField defaultSortField
OPACItemsResultsDisplay displayFacetCount
expandedSearchOption OPACdefaultSortField
IntranetNumbersPreferPhrase OPACItemsResultsDisplay
OPACNumbersPreferPhrase expandedSearchOption
opacSerialDefaultTab IntranetNumbersPreferPhrase
RenewSerialAddsSuggestion OPACNumbersPreferPhrase
RoutingListAddReserves opacSerialDefaultTab
RoutingSerials RenewSerialAddsSuggestion
SubscriptionHistory RoutingListAddReserves
Display856uAsImage RoutingSerials
DisplayIconsXSLT SubscriptionHistory
StaffAuthorisedValueImages Display856uAsImage
template DisplayIconsXSLT
yuipath StaffAuthorisedValueImages
HidePatronName template
intranetbookbag yuipath
StaffDetailItemSelection HidePatronName
viewISBD intranetbookbag
viewLabeledMARC StaffDetailItemSelection
viewMARC viewISBD
ILS-DI viewLabeledMARC
OAI-PMH viewMARC
version/) { ILS-DI
OAI-PMH
version
/
)
{
$report->{systempreferences}{$_} = C4::Context->preference($_); $report->{systempreferences}{$_} = C4::Context->preference($_);
} }
return $report; return $report;
@ -369,16 +338,18 @@ Send to hea.koha-community.org database informations
=cut =cut
sub ReportToCommunity { sub ReportToCommunity {
my $data = shift; my $data = shift;
my $json = uri_encode(to_json($data), 1); my $json = uri_encode( to_json($data), 1 );
my $ua = LWP::UserAgent->new; my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => "http://hea.koha-community.org/upload.pl"); my $req =
$req->content_type('application/x-www-form-urlencoded'); HTTP::Request->new( POST => "http://hea.koha-community.org/upload.pl" );
$req->content("data=$json"); $req->content_type('application/x-www-form-urlencoded');
my $res = $ua->request($req); $req->content("data=$json");
my $content = from_json($res->decoded_content); my $res = $ua->request($req);
C4::Context->set_preference('UsageStatsID', $content->{library}{library_id}); my $content = from_json( $res->decoded_content );
C4::Context->set_preference( 'UsageStatsID',
$content->{library}{library_id} );
} }
=head2 _count =head2 _count
@ -390,13 +361,12 @@ Count the number of records in $table tables
=cut =cut
sub _count { sub _count {
my $table = shift; my $table = shift;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT count(*) from $table"); my $sth = $dbh->prepare("SELECT count(*) from $table");
$sth->execute; $sth->execute;
return $sth->fetchrow_array; return $sth->fetchrow_array;
} }
&LaunchCron;
1; 1;

21
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref

@ -114,19 +114,16 @@ Administration:
Zebra: Zebra Zebra: Zebra
- is the search engine used. - is the search engine used.
Usage Stats: Usage Stats:
-
- pref: UsageStatsLastUpdateTime
default: 0
- stores the last time when cron were launch
-
- pref: UsageStatsID
default:
-
- -
- pref: UsageStatsShare - pref: UsageStatsShare
default: default: 0
- choices:
yes: Share
no: "Don't share"
- data volumetry with Koha community. You can see the data on the <a href="http://hea.koha-community.org">Hea Koha community website</a>.
- -
- The library name
- pref: UsageStatsLibraryName - pref: UsageStatsLibraryName
default: - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
- - If this name is empty, you will sent data anonymously
- Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"

98
misc/cronjobs/share_usage_with_koha_community.pl

@ -0,0 +1,98 @@
#!/usr/bin/perl
use Modern::Perl;
use Pod::Usage;
use Getopt::Long;
use C4::Context;
use C4::UsageStats;
my ( $help, $verbose );
GetOptions(
'h|help' => \$help,
'v|verbose' => \$verbose,
) || pod2usage(1);
if ($help) {
pod2usage(1);
}
unless( C4::Context->preference('UsageStatsShare') ) {
pod2usage (q|The UsageStats system preference is not set. If your library wants to share their usage statistics with the Koha community, you have to switch on this system preference|);
exit 1;
}
my $need_update = C4::UsageStats::NeedUpdate();
if ( $need_update ) {
say "Data need to be updated" if $verbose;
my $report = C4::UsageStats::BuildReport();
C4::UsageStats::ReportToCommunity($report);
C4::Context->set_preference('UsageStatsLastUpdateTime', strftime("%s", localtime));
} elsif( $verbose ) {
say "Data don't need to be updated";
}
=head1 NAME
share_usage_with_koha_community.pl - Share your library's usage with the Koha community
=head1 SYNOPSIS
share_usage_with_koha_community.pl [-h|--help] [-v|--verbose]
If the UsageStatsShare system preference is set, you can launch this script to share your usage with the Koha community.
Collecting Koha usage statistics will help developpers to know how Koha is used across the world.
This script will sent the volumetry for the biblio and authority records, issues, reserves, orders and subscription.
Only the total number is retrieved. In no case private data will be shared!
In order to know which parts of Koha modules are used, this script will collect some system preference values.
If you want to tell us who you are, you can fill the UsageStatsLibraryName system preference with your library name.
All these data will be analysed on the http://hea.koha-community.org Koha community website.
IMPORTANT : please do NOT run the cron on the 1st, but on another day. The idea is to avoid all
Koha libraries sending their data at the same time ! So choose any day between 1 and 28 !
=head1 OPTIONS
=over
=item B<-h|--help>
Print a brief help message
=item B<-v|--verbose>
Verbose mode.
=back
=head1 AUTHOR
Alex Arnaud <alex.arnaud@biblibre.com>
Jonathan Druart <jonathan.druart@biblibre.com>
=head1 COPYRIGHT
Copyright 2014 BibLibre
=head1 LICENSE
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 3 of the License, or (at your option) any later version.
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.
=cut
Loading…
Cancel
Save