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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit c26a989c64)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-01-23 14:34:30 +01:00 committed by Paul Derscheid
parent 9285dddcef
commit ccbe38128c
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
3 changed files with 8 additions and 53 deletions

View File

@ -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;

View File

@ -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" });

View File

@ -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;