1 package C4::UsageStats;
3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use POSIX qw( strftime );
24 use JSON qw( decode_json encode_json );
34 This package contains what is needed to report Koha statistics to hea
35 hea.koha-community.org is the server that centralize Koha setups informations
36 Koha libraries are encouraged to provide informations about their collections,
41 $needUpdateYN = C4::UsageStats::NeedUpdate;
43 Returns Y (1) if the last update is more than 1 month old
44 This way, even if the cronjob is run every minute, the webservice will be called
50 my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
51 my $now = strftime( "%s", localtime );
53 # Need to launch cron.
54 return 1 if $now - $lastupdated >= 2592000;
56 # Data don't need to be updated
63 if( C4::Context->preference('UsageStatsLibrariesInfo') ) {
64 my $libraries = Koha::Libraries->search;
65 while ( my $library = $libraries->next ) {
66 push @libraries, { name => $library->branchname, url => $library->branchurl, country => $library->branchcountry, geolocation => $library->geolocation, };
71 koha_id => C4::Context->preference('UsageStatsID') || 0,
72 name => C4::Context->preference('UsageStatsLibraryName') || q||,
73 url => C4::Context->preference('UsageStatsLibraryUrl') || q||,
74 type => C4::Context->preference('UsageStatsLibraryType') || q||,
75 country => C4::Context->preference('UsageStatsCountry') || q||,
76 geolocation => C4::Context->preference('UsageStatsGeolocation') || q||,
78 libraries => \@libraries,
81 # Get database volumetry.
83 qw/biblio items auth_header old_issues old_reserves borrowers aqorders subscription/
86 $report->{volumetry}{$_} = _count($_);
89 # Get systempreferences.
90 foreach ( @{ _shared_preferences() } )
92 $report->{systempreferences}{$_} = C4::Context->preference($_);
97 =head2 ReportToCommunity
101 Send to hea.koha-community.org database informations
105 sub ReportToCommunity {
107 my $json = encode_json($data);
109 my $url = "https://hea.koha-community.org/upload.pl";
110 my $ua = LWP::UserAgent->new;
113 'Content-type' => 'application/json;charset=utf-8',
116 my $content = decode_json( $res->decoded_content );
117 if ( $content->{koha_id} ) {
118 C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} );
120 if ( $content->{id} ) {
121 C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} );
125 =head2 _shared_preferences
127 my $preferences = C4::UsageStats::_shared_preferences
129 Returns an I<arreyref> with the system preferences to be shared.
133 sub _shared_preferences {
135 my @preferences = qw/
137 AcqWarnOnDuplicateInvoice
154 AutoCreateAuthorities
156 RequireChoosingExistingAuthority
159 UseAuthoritiesForTracings
162 IntranetBiblioDefaultView
168 DefaultClassificationSource
169 EasyAnalyticalRecords
176 SpineLabelShowPrintOnBibDetails
177 BlockReturnOfLostItems
178 BlockReturnOfWithdrawnItems
179 CalculateFinesOnReturn
180 AgeRestrictionOverride
183 AllowItemsOnHoldCheckoutSIP
184 AllowItemsOnHoldCheckoutSCO
185 AllowNotForLoanOverride
186 AllowRenewalLimitOverride
190 AutoRemoveOverduesRestrictions
199 TransfersMaxDaysWarning
200 UseBranchTransferLimits
201 UseTransportCostMatrix
204 FinesIncludeGracePeriod
206 RefundLostOnReturnControl
207 WhenLostChargeReplacementFee
209 AllowHoldDateInFuture
210 AllowHoldItemTypeSelection
211 AllowHoldPolicyOverride
212 AllowHoldsOnDamagedItems
213 AllowHoldsOnPatronsPossessions
214 AutoResumeSuspendedHolds
215 canreservefromotherbranches
216 decreaseLoanHighHolds
217 DisplayMultiPlaceHold
218 emailLibrarianWhenHoldIsPlaced
219 ExpireReservesMaxPickUpDelay
220 OPACAllowHoldDateInFuture
221 OPACAllowUserToChooseBranch
222 ReservesControlBranch
226 TransferWhenCancelAllWaitingHolds
227 AllowAllMessageDeletion
228 AllowOfflineCirculation
230 CircAutoPrintQuickSlip
231 DisplayClearScreenButton
232 FilterBeforeOverdueReport
234 itemBarcodeFallbackSearch
235 itemBarcodeInputFilter
236 previousIssuesDefaultSortOrder
237 RecordLocalUseOnReturn
240 todaysIssuesDefaultSortOrder
241 UpdateTotalIssuesOnCirc
243 WaitingNotifyAtCheckin
249 OPACAmazonCoverImages
254 LibraryThingForLibrariesEnabled
257 NovelistSelectEnabled
262 CalendarFirstDayOfWeek
277 OpacAddMastheadLibraryPulldown
278 OPACDisplay856uAsImage
285 OpacShowFiltersPulldownMobile
286 OPACShowHoldQueueDetails
287 OpacShowRecentComments
288 OPACShowUnusedAuthorities
291 OPACURLOpenInNewWindow
303 OPACPopupAuthorsSearch
313 OpacAllowPublicListCreation
314 OpacAllowSharingPrivateLists
317 OPACViewOthersSuggestions
320 EnableOpacSearchHistory
324 PatronSelfRegistration
329 BorrowerRenewalPeriodBase
331 EnhancedMessagingPreferences
332 ExtendedPatronAttributes
333 intranetreadinghistory
335 TalkingTechItivaPhoneNotification
337 IncludeSeeFromInSearches
342 TraceCompleteSubfields
343 TraceSubjectSubdivisions
349 IntranetNumbersPreferPhrase
350 OPACNumbersPreferPhrase
352 RenewSerialAddsSuggestion
353 RoutingListAddReserves
362 StaffDetailItemSelection
371 return \@preferences;
376 $data = _count($table);
378 Count the number of records in $table tables
385 my $dbh = C4::Context->dbh;
386 my $sth = $dbh->prepare("SELECT count(*) from $table");
388 return $sth->fetchrow_array;