Bug 18072: (QA follow-up) Remove warning from tests
[koha.git] / C4 / UsageStats.pm
index 0187f86..18ae593 100644 (file)
@@ -1,4 +1,4 @@
-package UsageStats;
+package C4::UsageStats;
 
 # This file is part of Koha.
 #
@@ -22,9 +22,12 @@ use C4::Context;
 use POSIX qw(strftime);
 use LWP::UserAgent;
 use JSON;
-use URI::Encode qw(uri_encode);
 
-=head1 NAME C4::UsageStats
+use Koha::Libraries;
+
+=head1 NAME
+
+C4::UsageStats
 
 =head1 DESCRIPTION
 
@@ -45,7 +48,7 @@ only once a month !
 
 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;
@@ -55,15 +58,31 @@ sub NeedUpdate {
 }
 
 sub BuildReport {
-    my $report = {
-        library => {
-            name => C4::Context->preference('UsageStatsLibraryName') || q||,
-            id => C4::Context->preference('UsageStatsID') || 0,
+    my $report;
+    my @libraries;
+    if( C4::Context->preference('UsageStatsLibrariesInfo') ) {
+        my $libraries = Koha::Libraries->search;
+        while ( my $library = $libraries->next ) {
+            push @libraries, { name => $library->branchname, url => $library->branchurl, country => $library->branchcountry, geolocation => $library->geolocation, };
+        }
+    }
+    $report = {
+        installation => {
+            koha_id => C4::Context->preference('UsageStatsID')          || 0,
+            name    => C4::Context->preference('UsageStatsLibraryName') || q||,
+            url     => C4::Context->preference('UsageStatsLibraryUrl')  || q||,
+            type    => C4::Context->preference('UsageStatsLibraryType') || q||,
+            country => C4::Context->preference('UsageStatsCountry')     || q||,
+            geolocation => C4::Context->preference('UsageStatsGeolocation') || q||,
         },
+        libraries => \@libraries,
     };
 
     # 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($_);
     }
 
@@ -77,7 +96,7 @@ sub BuildReport {
         OrderPdfFormat
         casAuthentication
         casLogout
-        AllowPkiAuth
+        AllowPKIAuth
         DebugLevel
         delimiter
         noItemTypeImages
@@ -89,7 +108,8 @@ sub BuildReport {
         AuthDisplayHierarchy
         AutoCreateAuthorities
         BiblioAddsAuthorities
-        dontmerge
+        AuthorityMergeLimit
+        AuthorityMergeMode
         UseAuthoritiesForTracings
         CatalogModuleRelink
         hide_marc
@@ -108,12 +128,14 @@ sub BuildReport {
         z3950NormalizeAuthor
         SpineLabelAutoPrint
         SpineLabelShowPrintOnBibDetails
+        BlockReturnOfLostItems
         BlockReturnOfWithdrawnItems
         CalculateFinesOnReturn
         AgeRestrictionOverride
         AllFinesNeedOverride
         AllowFineOverride
         AllowItemsOnHoldCheckout
+        AllowItemsOnHoldCheckoutSCO
         AllowNotForLoanOverride
         AllowRenewalLimitOverride
         AllowReturnToBranch
@@ -122,7 +144,6 @@ sub BuildReport {
         AutoRemoveOverduesRestrictions
         CircControl
         HomeOrHoldingBranch
-        HomeOrHoldingBranchReturn
         InProcessingToShelvingCart
         IssueLostItem
         IssuingInProcess
@@ -141,14 +162,13 @@ sub BuildReport {
         finesCalendar
         FinesIncludeGracePeriod
         finesMode
-        RefundLostItemFeeOnReturn
+        RefundLostOnReturnControl
         WhenLostChargeReplacementFee
         WhenLostForgiveFine
         AllowHoldDateInFuture
         AllowHoldPolicyOverride
         AllowHoldsOnDamagedItems
         AllowHoldsOnPatronsPossessions
-        AllowOnShelfHolds
         AutoResumeSuspendedHolds
         canreservefromotherbranches
         decreaseLoanHighHolds
@@ -173,7 +193,7 @@ sub BuildReport {
         itemBarcodeInputFilter
         previousIssuesDefaultSortOrder
         RecordLocalUseOnReturn
-        soundon
+        AudioAlerts
         SpecifyDueDate
         todaysIssuesDefaultSortOrder
         UpdateTotalIssuesOnCirc
@@ -198,6 +218,7 @@ sub BuildReport {
         NovelistSelectEnabled
         XISBN
         OpenLibraryCovers
+        OpenLibrarySearch
         UseKohaPlugins
         SyndeticsEnabled
         TagsEnabled
@@ -211,7 +232,6 @@ sub BuildReport {
         LetterLog
         ReturnLog
         SubscriptionLog
-        AuthorisedValueImages
         BiblioDefaultView
         COinSinOPACResults
         DisplayOPACiconsXSLT
@@ -224,11 +244,9 @@ sub BuildReport {
         OpacMaintenance
         OpacPublic
         OpacSeparateHoldings
-        OPACShowBarcode
         OPACShowCheckoutName
         OpacShowFiltersPulldownMobile
         OPACShowHoldQueueDetails
-        OpacShowLibrariesPulldownMobile
         OpacShowRecentComments
         OPACShowUnusedAuthorities
         OpacStarRatings
@@ -258,12 +276,10 @@ sub BuildReport {
         AllowPurchaseSuggestionBranchChoice
         OpacAllowPublicListCreation
         OpacAllowSharingPrivateLists
-        OPACItemHolds
         OpacRenewalAllowed
         OpacRenewalBranch
         OPACViewOthersSuggestions
         SearchMyLibraryFirst
-        singleBranchMode
         AnonSuggestions
         EnableOpacSearchHistory
         OPACPrivacy
@@ -271,17 +287,14 @@ sub BuildReport {
         TrackClicks
         PatronSelfRegistration
         OPACShelfBrowser
-        AddPatronLists
         AutoEmailOpacUser
         AutoEmailPrimaryAddress
         autoMemberNum
         BorrowerRenewalPeriodBase
-        checkdigit
         EnableBorrowerFiles
         EnhancedMessagingPreferences
         ExtendedPatronAttributes
         intranetreadinghistory
-        memberofinstitution
         patronimages
         TalkingTechItivaPhoneNotification
         uppercasesurnames
@@ -309,7 +322,6 @@ sub BuildReport {
         SubscriptionHistory
         Display856uAsImage
         DisplayIconsXSLT
-        StaffAuthorisedValueImages
         template
         yuipath
         HidePatronName
@@ -338,18 +350,23 @@ Send to hea.koha-community.org database informations
 =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 = "https://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 );
+    if ( $content->{koha_id} ) {
+        C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} );
+    }
+    if ( $content->{id} ) {
+        C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} );
+    }
 }
 
 =head2 _count
@@ -361,12 +378,12 @@ Count the number of records in $table tables
 =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;