From b7c955c95009c1e272b64e7d17190a0db3719424 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 Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- C4/UsageStats.pm | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm index be49a53b08..400709b59b 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.39.5