From 3d32259482b525f68c4689e7ac73fd17b01346f0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 14 Jun 2021 17:44:30 -0300 Subject: [PATCH] Bug 28565: Move the sysprefs to a reusable sub This patch moves the big sysprefs list to a sub. Behavior shouldn't change. To test: 1. Run: $ kshell k$ prove t/db_dependent/UsageStats.t => SUCCESS: Things work as expected, no changes. 2. Sign off :-D Signed-off-by: David Nind Signed-off-by: David Nind --- C4/UsageStats.pm | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm index 3c4ec3dafc..f83cd11fde 100644 --- a/C4/UsageStats.pm +++ b/C4/UsageStats.pm @@ -87,8 +87,52 @@ sub BuildReport { } # Get systempreferences. - foreach ( - qw/ + foreach ( @{ _shared_preferences() } ) + { + $report->{systempreferences}{$_} = C4::Context->preference($_); + } + return $report; +} + +=head2 ReportToCommunity + + ReportToCommunity; + +Send to hea.koha-community.org database informations + +=cut + +sub ReportToCommunity { + my $data = shift; + my $json = encode_json($data); + + 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 _shared_preferences + + my $preferences = C4::UsageStats::_shared_preferences + +Returns an I with the system preferences to be shared. + +=cut + +sub _shared_preferences { + + my @preferences = qw/ AcqCreateItem AcqWarnOnDuplicateInvoice AcqViewBaskets @@ -325,40 +369,9 @@ sub BuildReport { ILS-DI OAI-PMH version - / - ) - { - $report->{systempreferences}{$_} = C4::Context->preference($_); - } - return $report; -} - -=head2 ReportToCommunity - - ReportToCommunity; - -Send to hea.koha-community.org database informations - -=cut + /; -sub ReportToCommunity { - my $data = shift; - my $json = encode_json($data); - - 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} ); - } + return \@preferences; } =head2 _count -- 2.20.1