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

(-)a/C4/UsageStats.pm (-21 / +27 lines)
Lines 1-4 Link Here
1
package UsageStats;
1
package C4::UsageStats;
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
Lines 22-28 use C4::Context; Link Here
22
use POSIX qw(strftime);
22
use POSIX qw(strftime);
23
use LWP::UserAgent;
23
use LWP::UserAgent;
24
use JSON;
24
use JSON;
25
use URI::Encode qw(uri_encode);
26
25
27
=head1 NAME C4::UsageStats
26
=head1 NAME C4::UsageStats
28
27
Lines 45-51 only once a month ! Link Here
45
44
46
sub NeedUpdate {
45
sub NeedUpdate {
47
    my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
46
    my $lastupdated = C4::Context->preference('UsageStatsLastUpdateTime') || 0;
48
    my $now = strftime("%s", localtime);
47
    my $now = strftime( "%s", localtime );
49
48
50
    # Need to launch cron.
49
    # Need to launch cron.
51
    return 1 if $now - $lastupdated >= 2592000;
50
    return 1 if $now - $lastupdated >= 2592000;
Lines 57-69 sub NeedUpdate { Link Here
57
sub BuildReport {
56
sub BuildReport {
58
    my $report = {
57
    my $report = {
59
        library => {
58
        library => {
59
            id   => C4::Context->preference('UsageStatsID')          || 0,
60
            name => C4::Context->preference('UsageStatsLibraryName') || q||,
60
            name => C4::Context->preference('UsageStatsLibraryName') || q||,
61
            id => C4::Context->preference('UsageStatsID') || 0,
61
            url => C4::Context->preference('UsageStatsLibraryUrl')   || q||,
62
            type => C4::Context->preference('UsageStatsLibraryType') || q||,
63
            country => C4::Context->preference('UsageStatsCountry') || q||,
62
        },
64
        },
63
    };
65
    };
64
66
65
    # Get database volumetry.
67
    # Get database volumetry.
66
    foreach (qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/) {
68
    foreach (
69
        qw/biblio auth_header old_issues old_reserves borrowers aqorders subscription/
70
      )
71
    {
67
        $report->{volumetry}{$_} = _count($_);
72
        $report->{volumetry}{$_} = _count($_);
68
    }
73
    }
69
74
Lines 338-355 Send to hea.koha-community.org database informations Link Here
338
=cut
343
=cut
339
344
340
sub ReportToCommunity {
345
sub ReportToCommunity {
341
      my $data = shift;
346
    my $data = shift;
342
      my $json = uri_encode( to_json($data), 1 );
347
    my $json = encode_json($data);
343
348
344
      my $ua = LWP::UserAgent->new;
349
    my $url = "http://hea.koha-community.org/upload.pl";
345
      my $req =
350
    my $ua = LWP::UserAgent->new;
346
        HTTP::Request->new( POST => "http://hea.koha-community.org/upload.pl" );
351
    my $res = $ua->post(
347
      $req->content_type('application/x-www-form-urlencoded');
352
        $url,
348
      $req->content("data=$json");
353
        'Content-type' => 'application/json;charset=utf-8',
349
      my $res     = $ua->request($req);
354
        Content => $json,
350
      my $content = from_json( $res->decoded_content );
355
    );
351
      C4::Context->set_preference( 'UsageStatsID',
356
    my $content = decode_json( $res->decoded_content );
352
          $content->{library}{library_id} );
357
    C4::Context->set_preference( 'UsageStatsID',
358
        $content->{library}{id} );
353
}
359
}
354
360
355
=head2 _count
361
=head2 _count
Lines 361-372 Count the number of records in $table tables Link Here
361
=cut
367
=cut
362
368
363
sub _count {
369
sub _count {
364
      my $table = shift;
370
    my $table = shift;
365
371
366
      my $dbh = C4::Context->dbh;
372
    my $dbh = C4::Context->dbh;
367
      my $sth = $dbh->prepare("SELECT count(*) from $table");
373
    my $sth = $dbh->prepare("SELECT count(*) from $table");
368
      $sth->execute;
374
    $sth->execute;
369
      return $sth->fetchrow_array;
375
    return $sth->fetchrow_array;
370
}
376
}
371
377
372
1;
378
1;
(-)a/installer/data/mysql/sysprefs.sql (-1 / +4 lines)
Lines 419-427 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
419
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
419
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
420
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
420
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
421
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
421
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
422
('UsageStatsCountry', '', 'The country where your library is to show on hea Koha community website', NULL, 'YesNo'),
422
('UsageStatsID', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
423
('UsageStatsID', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
423
('UsageStatsLastUpdateTime', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
424
('UsageStatsLastUpdateTime', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
424
('UsageStatsLibraryName', '', 'The library name to show on hea Koha community website', NULL, 'YesNo'),
425
('UsageStatsLibraryName', '', 'The library name to show on hea Koha community website', NULL, 'Free'),
426
('UsageStatsLibraryType', 'public', 'public|university', 'The library type to show on hea Koha community website', NULL, 'Choice'),
427
('UsageStatsLibraryUrl', '', 'The library url to show on hea Koha community website', NULL, 'Free'),
425
('UsageStatsShare', 0, 'Share data volumetry with Koha community (HEA).', NULL, 'YesNo'),
428
('UsageStatsShare', 0, 'Share data volumetry with Koha community (HEA).', NULL, 'YesNo'),
426
('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'),
429
('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'),
427
('UseBranchTransferLimits','0','','If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.','YesNo'),
430
('UseBranchTransferLimits','0','','If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (-10 / +14 lines)
Lines 8707-8722 if ( CheckVersion($DBversion) ) { Link Here
8707
8707
8708
$DBversion = "3.17.00.XXX";
8708
$DBversion = "3.17.00.XXX";
8709
if ( CheckVersion($DBversion) ) {
8709
if ( CheckVersion($DBversion) ) {
8710
   $dbh->do(q|
8710
    $dbh->do(
8711
       INSERT INTO systempreferences (variable, value, explanation, options, type )
8711
        q{
8712
       VALUES 
8712
       INSERT INTO systempreferences (variable, value, options, explanation, type )
8713
       ('UsageStatsID', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
8713
       VALUES
8714
       ('UsageStatsLastUpdateTime', '', 'This pref is part of Koha but it should not be deleted or updated manually.', '', 'Free'),
8714
        ('UsageStatsCountry', '', NULL, 'The country where your library is to show on hea Koha community website', 'YesNo'),
8715
       ('UsageStatsLibraryName', '', 'The library name to show on hea Koha community website', NULL, 'YesNo'),
8715
        ('UsageStatsID', '', NULL, 'This pref is part of Koha but it should not be deleted or updated manually.',  'Free'),
8716
       ('UsageStatsShare', 0, 'Share data volumetry with Koha community (HEA).', NULL, 'YesNo')
8716
        ('UsageStatsLastUpdateTime', '', NULL, 'This pref is part of Koha but it should not be deleted or updated manually.', 'Free'),
8717
    |);
8717
        ('UsageStatsLibraryName', '', NULL, 'The library name to show on hea Koha community website', 'Free'),
8718
   print "Upgrade to $DBversion done (Bug 11926: Add UsageStats systempreferences (HEA))\n";
8718
        ('UsageStatsLibraryType', 'public', 'public|university', 'The library type to show on hea Koha community website', 'Choice'),
8719
   SetVersion ($DBversion);
8719
        ('UsageStatsLibraryUrl', '', NULL, 'The library url to show on hea Koha community website', 'Free'),
8720
        ('UsageStatsShare', 0, NULL, 'Share data volumetry with Koha community (HEA).', 'YesNo')
8721
    });
8722
    print "Upgrade to $DBversion done (Bug 11926: Add UsageStats systempreferences (HEA))\n";
8723
    SetVersion($DBversion);
8720
}
8724
}
8721
8725
8722
=head1 FUNCTIONS
8726
=head1 FUNCTIONS
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+20 lines)
Lines 127-129 Administration: Link Here
127
            - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
127
            - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
128
            - If this name is empty, you will sent data anonymously
128
            - If this name is empty, you will sent data anonymously
129
            - Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"
129
            - Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"
130
        -
131
            - The country where your library is
132
            - pref: UsageStatsCountry
133
            - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
134
            - Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"
135
        -
136
            - The library url
137
            - pref: UsageStatsLibraryUrl
138
            - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
139
            - Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"
140
141
        -
142
            - The library type
143
            - pref: UsageStatsLibraryType
144
              default: public
145
              choices:
146
                  public: "public"
147
                  university: "university"
148
            - will be shown on <a href="http://hea.koha-community.org">Hea Koha community website</a>.
149
            - Note that this value has no effect if UsageStatsShare system preference is set to "Don't share"
(-)a/misc/cronjobs/share_usage_with_koha_community.pl (-13 / +24 lines)
Lines 7-37 use Getopt::Long; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
use C4::UsageStats;
9
use C4::UsageStats;
10
use POSIX qw(strftime);
10
11
11
12
my ( $help, $verbose, $force );
12
my ( $help, $verbose );
13
GetOptions(
13
GetOptions(
14
    'h|help'                 => \$help,
14
    'h|help'    => \$help,
15
    'v|verbose'              => \$verbose,
15
    'v|verbose' => \$verbose,
16
    'f|force'   => \$force,
16
) || pod2usage(1);
17
) || pod2usage(1);
17
18
18
if ($help) {
19
if ($help) {
19
    pod2usage(1);
20
    pod2usage(1);
20
}
21
}
21
22
22
unless( C4::Context->preference('UsageStatsShare') ) {
23
unless ( C4::Context->preference('UsageStatsShare') ) {
23
  pod2usage (q|The UsageStats system preference is not set. If your library  wants to share their usage statistics with the Koha community, you have to switch on this system preference|);
24
    pod2usage(
24
  exit 1;
25
q|
26
The UsageStats system preference is not set.
27
If your library wants to share their usage statistics with the Koha community, you have to switch on this system preference
28
|
29
    );
30
    exit 1;
25
}
31
}
26
32
27
my $need_update = C4::UsageStats::NeedUpdate();
33
my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() );
28
34
29
if ( $need_update ) {
35
if ($need_update) {
30
    say "Data need to be updated" if $verbose;
36
    say "Data need to be updated" if $verbose;
31
    my $report = C4::UsageStats::BuildReport();
37
    my $report = C4::UsageStats::BuildReport();
32
    C4::UsageStats::ReportToCommunity($report);
38
    C4::UsageStats::ReportToCommunity($report);
33
    C4::Context->set_preference('UsageStatsLastUpdateTime', strftime("%s", localtime));
39
    C4::Context->set_preference( 'UsageStatsLastUpdateTime',
34
} elsif( $verbose ) {
40
        strftime( "%s", localtime ) );
41
}
42
elsif ($verbose) {
35
    say "Data don't need to be updated";
43
    say "Data don't need to be updated";
36
}
44
}
37
45
Lines 53-59 Only the total number is retrieved. In no case private data will be shared! Link Here
53
61
54
In order to know which parts of Koha modules are used, this script will collect some system preference values.
62
In order to know which parts of Koha modules are used, this script will collect some system preference values.
55
63
56
If you want to tell us who you are, you can fill the UsageStatsLibraryName system preference with your library name.
64
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.
57
65
58
All these data will be analysed on the http://hea.koha-community.org Koha community website.
66
All these data will be analysed on the http://hea.koha-community.org Koha community website.
59
67
Lines 72-77 Print a brief help message Link Here
72
80
73
Verbose mode.
81
Verbose mode.
74
82
83
=item B<-f|--force>
84
85
Force the update.
86
75
=back
87
=back
76
88
77
=head1 AUTHOR
89
=head1 AUTHOR
78
- 

Return to bug 11926