View | Details | Raw Unified | Return to bug 38104
Collapse All | Expand All

(-)a/C4/UsageStats.pm (-19 lines)
Lines 36-62 hea.koha-community.org is the server that centralize Koha setups informations Link Here
36
Koha libraries are encouraged to provide informations about their collections,
36
Koha libraries are encouraged to provide informations about their collections,
37
their structure,...
37
their structure,...
38
38
39
=head2 NeedUpdate
40
41
  $needUpdateYN = C4::UsageStats::NeedUpdate;
42
43
Returns Y (1) if the last update is more than 1 month old
44
This way, even if the cronjob is run every minute, the webservice will be called
45
only once a month !
46
47
=cut
39
=cut
48
40
49
sub NeedUpdate {
50
    my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
51
    my $now = strftime( "%s", localtime );
52
53
    # Need to launch cron.
54
    return 1 if $now - $lastupdated >= 2592000;
55
56
    # Data don't need to be updated
57
    return 0;
58
}
59
60
sub BuildReport {
41
sub BuildReport {
61
    my $report;
42
    my $report;
62
    my @libraries;
43
    my @libraries;
(-)a/misc/cronjobs/share_usage_with_koha_community.pl (-12 / +6 lines)
Lines 39-56 Setting the quiet flag will silence this message. Link Here
39
    exit 1;
39
    exit 1;
40
}
40
}
41
41
42
my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() );
42
my $report = C4::UsageStats::BuildReport();
43
43
C4::UsageStats::ReportToCommunity($report);
44
if ($need_update) {
44
C4::Context->set_preference(
45
    say "Data need to be updated" if $verbose;
45
    'UsageStatsLastUpdateTime',
46
    my $report = C4::UsageStats::BuildReport();
46
    strftime( "%s", localtime )
47
    C4::UsageStats::ReportToCommunity($report);
47
);
48
    C4::Context->set_preference( 'UsageStatsLastUpdateTime',
49
        strftime( "%s", localtime ) );
50
}
51
elsif ($verbose) {
52
    say "Data don't need to be updated";
53
}
54
48
55
cronlogaction({ action => 'End', info => "COMPLETED" });
49
cronlogaction({ action => 'End', info => "COMPLETED" });
56
50
(-)a/t/db_dependent/UsageStats.t (-23 / +2 lines)
Lines 16-22 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 4;
19
use Test::More tests => 3;
20
20
21
use t::lib::Mocks qw(mock_preference);
21
use t::lib::Mocks qw(mock_preference);
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
Lines 33-44 use Koha::Old::Holds; Link Here
33
use Koha::Patrons;
33
use Koha::Patrons;
34
34
35
BEGIN {
35
BEGIN {
36
    use_ok('C4::UsageStats', qw( NeedUpdate BuildReport ReportToCommunity _count ));
36
    use_ok('C4::UsageStats', qw( BuildReport ReportToCommunity _count ));
37
}
37
}
38
38
39
can_ok(
39
can_ok(
40
    'C4::UsageStats', qw(
40
    'C4::UsageStats', qw(
41
      NeedUpdate
42
      BuildReport
41
      BuildReport
43
      ReportToCommunity
42
      ReportToCommunity
44
      _count )
43
      _count )
Lines 47-71 can_ok( Link Here
47
my $builder = t::lib::TestBuilder->new;
46
my $builder = t::lib::TestBuilder->new;
48
my $schema  = Koha::Database->new->schema;
47
my $schema  = Koha::Database->new->schema;
49
48
50
subtest 'NeedUpdate() tests' => sub {
51
52
    plan tests => 2;
53
54
    #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to 0
55
    my $now = strftime( "%s", localtime );
56
    t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", 0 );
57
58
    my $update = C4::UsageStats->NeedUpdate;
59
    is( $update, 1, "There is no last update, update needed" );
60
61
    #Mocking C4::Context->preference("UsageStatsLastUpdateTime") to now
62
    $now = strftime( "%s", localtime );
63
    t::lib::Mocks::mock_preference( "UsageStatsLastUpdateTime", $now );
64
65
    $update = C4::UsageStats->NeedUpdate;
66
    is( $update, 0, "Last update just be done, no update needed " );
67
};
68
69
subtest 'BuildReport() tests' => sub {
49
subtest 'BuildReport() tests' => sub {
70
50
71
    plan tests => 30;
51
    plan tests => 30;
72
- 

Return to bug 38104