From ccbe38128cfb90a1538841d2cff78c3d2706414d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 23 Jan 2025 14:34:30 +0100 Subject: [PATCH] Bug 38104: Always update when hea cronjob is run If the cronjob is configured to run every month we don't need to add another test on the delay in the script itself. Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit c26a989c64bff83d3702c73174b4ead6bf5c0388) Signed-off-by: Paul Derscheid --- C4/UsageStats.pm | 19 --------------- .../share_usage_with_koha_community.pl | 18 +++++--------- t/db_dependent/UsageStats.t | 24 ++----------------- 3 files changed, 8 insertions(+), 53 deletions(-) diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm index 37b4a76ec4..8f55c261bd 100644 --- a/C4/UsageStats.pm +++ b/C4/UsageStats.pm @@ -36,27 +36,8 @@ hea.koha-community.org is the server that centralize Koha setups informations Koha libraries are encouraged to provide informations about their collections, their structure,... -=head2 NeedUpdate - - $needUpdateYN = C4::UsageStats::NeedUpdate; - -Returns Y (1) if the last update is more than 1 month old -This way, even if the cronjob is run every minute, the webservice will be called -only once a month ! - =cut -sub NeedUpdate { - my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0; - my $now = strftime( "%s", localtime ); - - # Need to launch cron. - return 1 if $now - $lastupdated >= 2592000; - - # Data don't need to be updated - return 0; -} - sub BuildReport { my $report; my @libraries; diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl index c534bdb1e7..be68035646 100755 --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ b/misc/cronjobs/share_usage_with_koha_community.pl @@ -39,18 +39,12 @@ Setting the quiet flag will silence this message. exit 1; } -my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() ); - -if ($need_update) { - say "Data need to be updated" if $verbose; - my $report = C4::UsageStats::BuildReport(); - C4::UsageStats::ReportToCommunity($report); - C4::Context->set_preference( 'UsageStatsLastUpdateTime', - strftime( "%s", localtime ) ); -} -elsif ($verbose) { - say "Data don't need to be updated"; -} +my $report = C4::UsageStats::BuildReport(); +C4::UsageStats::ReportToCommunity($report); +C4::Context->set_preference( + 'UsageStatsLastUpdateTime', + strftime( "%s", localtime ) +); cronlogaction({ action => 'End', info => "COMPLETED" }); diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t index 90bd7e1078..2d72af35d5 100755 --- a/t/db_dependent/UsageStats.t +++ b/t/db_dependent/UsageStats.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 3; use t::lib::Mocks qw(mock_preference); use t::lib::TestBuilder; @@ -33,12 +33,11 @@ use Koha::Old::Holds; use Koha::Patrons; BEGIN { - use_ok('C4::UsageStats', qw( NeedUpdate BuildReport ReportToCommunity _count )); + use_ok('C4::UsageStats', qw( BuildReport ReportToCommunity _count )); } can_ok( 'C4::UsageStats', qw( - NeedUpdate BuildReport ReportToCommunity _count ) @@ -47,25 +46,6 @@ can_ok( my $builder = t::lib::TestBuilder->new; my $schema = Koha::Database->new->schema; -subtest 'NeedUpdate() tests' => sub { - - plan tests => 2; - - #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to 0 - my $now = strftime( "%s", localtime ); - t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", 0 ); - - my $update = C4::UsageStats->NeedUpdate; - is( $update, 1, "There is no last update, update needed" ); - - #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to now - $now = strftime( "%s", localtime ); - t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", $now ); - - $update = C4::UsageStats->NeedUpdate; - is( $update, 0, "Last update just be done, no update needed " ); -}; - subtest 'BuildReport() tests' => sub { plan tests => 30;