Bug 31459: (follow-up) Preserve budget period display
[koha.git] / misc / cronjobs / share_usage_with_koha_community.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Pod::Usage qw( pod2usage );
6 use Getopt::Long qw( GetOptions );
7
8 use Koha::Script -cron;
9 use C4::Context;
10 use C4::UsageStats;
11 use C4::Log qw( cronlogaction );
12 use POSIX qw( strftime );
13
14 my $command_line_options = join(" ",@ARGV);
15
16 my ( $help, $verbose, $force, $quiet );
17 GetOptions(
18     'h|help'    => \$help,
19     'v|verbose' => \$verbose,
20     'f|force'   => \$force,
21     'q|quiet'   => \$quiet,
22 ) || pod2usage(1);
23
24 if ($help) {
25     pod2usage(0);
26 }
27
28 unless ( C4::Context->preference('UsageStats') ) {
29     $quiet && exit;
30     pod2usage(
31 q|
32 The UsageStats system preference is not set.
33 If your library wants to share their usage statistics with the Koha community, you have to switch on this system preference
34
35 Setting the quiet flag will silence this message.
36 |
37     );
38     exit 1;
39 }
40
41 cronlogaction({ info => $command_line_options });
42
43 my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() );
44
45 if ($need_update) {
46     say "Data need to be updated" if $verbose;
47     my $report = C4::UsageStats::BuildReport();
48     C4::UsageStats::ReportToCommunity($report);
49     C4::Context->set_preference( 'UsageStatsLastUpdateTime',
50         strftime( "%s", localtime ) );
51 }
52 elsif ($verbose) {
53     say "Data don't need to be updated";
54 }
55
56 cronlogaction({ action => 'End', info => "COMPLETED" });
57
58 =head1 NAME
59
60 share_usage_with_koha_community.pl - Share your library's usage with the Koha community
61
62 =head1 SYNOPSIS
63
64 share_usage_with_koha_community.pl [-h|--help] [-v|--verbose] [-f|--force] [-q|--quiet]
65
66 If the UsageStats system preference is set, you can launch this script to share your usage data
67 anonymously with the Koha community.
68
69 Collecting Koha usage statistics will help developers to know how Koha is used across the world.
70
71 This script will send the usage data for the bibliographic and authority records, checkouts, holds, orders,
72 and subscriptions.
73
74 Only the total number is retrieved. In no case will private data be shared!
75
76 In order to know which parts of Koha modules are used, this script will collect some system preference values.
77
78 If you want to tell us who you are, you can fill the UsageStatsLibraryName system preference with your library name, UsageStatsLibraryUrl, UsageStatsLibraryType and/or UsageStatsCountry, UsageStatsLibrariesInfo.
79
80 All these data will be analyzed on the http://hea.koha-community.org Koha community website.
81
82 IMPORTANT : please do NOT run the cron on the 1st, but on another day. The idea is to avoid all
83 Koha libraries sending their data at the same time ! So choose any day between 1 and 28 !
84
85 =head1 OPTIONS
86
87 =over
88
89 =item B<-h|--help>
90
91 Print a brief help message
92
93 =item B<-v|--verbose>
94
95 Verbose mode
96
97 =item B<-f|--force>
98
99 Force the update
100
101 =item B<-q|--quiet>
102
103 Do not emit "The UsageStats system preference is not set" message
104
105 =back
106
107 =head1 AUTHOR
108
109 Alex Arnaud <alex.arnaud@biblibre.com>
110
111 Jonathan Druart <jonathan.druart@biblibre.com>
112
113 =head1 COPYRIGHT
114
115 Copyright 2014 BibLibre
116
117 =head1 LICENSE
118
119 This file is part of Koha.
120
121 # Koha is free software; you can redistribute it and/or modify it
122 # under the terms of the GNU General Public License as published by
123 # the Free Software Foundation; either version 3 of the License, or
124 # (at your option) any later version.
125 #
126 # Koha is distributed in the hope that it will be useful, but
127 # WITHOUT ANY WARRANTY; without even the implied warranty of
128 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129 # GNU General Public License for more details.
130 #
131 # You should have received a copy of the GNU General Public License
132 # along with Koha; if not, see <http://www.gnu.org/licenses>.
133
134 =cut