@ -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/s rc /C4/ UsageStats . pm
IMPORTANT : please do NOT run the cron on the 1 st , 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 ;