@@ -, +, @@ hea-ws - https://github.com/joubu/hea-ws/commits/v2 hea-app - https://github.com/joubu/hea-app/commits/v2 1. Communicate on the ML about this new version of Hea (once it got 2. Link the Privacy_Policy.md from the Hea interface 3. Get help from a native English speaker to add - Create a new branches.geolocation DB field - Add 3 new sysprefs: * UsageStatsGeolocation * UsageStatsLibrariesInfo * UsageStatsPublicID - Integrate the Leaflet JS library to get a fancy map to pick - Add a button on the administration page to delete the info shared - Add an icon per Koha installation to get a better "public page" - Any suggestions? CREATE DATABASE hea CREATE USER 'hea'@'localhost' IDENTIFIED BY 'hea'; GRANT ALL PRIVILEGES ON hea.* TO 'hea'@'localhost'; FLUSH PRIVILEGES; mysql hea < hea-app/sql/schema.sql mysql hea < hea-app/sql/sql/mock-data.sql % cd hea-app % perl -p -i -e 's/REPLACE_ME/hea/' sql/upgrade.pl # Fill the DB info % perl sql/upgrade.pl DocumentRoot "/path/to/hea-ws" ServerName "hea.koha-community.org" Options +ExecCGI Require all granted AddHandler cgi-script .pl % cd hea-app % edit README.md # to install the missing modules % cp environments/config.yml environments/development.yml % edit environments/development.yml # to fill the DB info % perl bin/app.pl % perl misc/cronjobs/share_usage_with_koha_community.pl -f -v --- C4/UsageStats.pm | 26 +++- Koha/Schema/Result/Branch.pm | 12 +- admin/usage_statistics.pl | 17 ++- installer/data/mysql/atomicupdate/bug_18066.perl | 21 +++ installer/data/mysql/sysprefs.sql | 3 + koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 3 + .../prog/en/modules/admin/preferences/admin.pref | 11 ++ .../prog/en/modules/admin/usage_statistics.tt | 163 ++++++++++++++++++++- misc/cronjobs/share_usage_with_koha_community.pl | 2 +- t/db_dependent/UsageStats.t | 15 +- 10 files changed, 257 insertions(+), 16 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18066.perl --- a/C4/UsageStats.pm +++ a/C4/UsageStats.pm @@ -23,6 +23,8 @@ use POSIX qw(strftime); use LWP::UserAgent; use JSON; +use Koha::Libraries; + =head1 NAME C4::UsageStats @@ -56,14 +58,24 @@ sub NeedUpdate { } sub BuildReport { - my $report = { - library => { - id => C4::Context->preference('UsageStatsID') || 0, + my $report; + my @libraries; + if( C4::Context->preference('UsageStatsLibrariesInfo') ) { + my $libraries = Koha::Libraries->search; + while ( my $library = $libraries->next ) { + push @libraries, { name => $library->branchname, url => $library->branchurl, country => $library->branchcountry, geolocation => $library->geolocation, }; + } + } + $report = { + installation => { + koha_id => C4::Context->preference('UsageStatsID') || 0, name => C4::Context->preference('UsageStatsLibraryName') || q||, url => C4::Context->preference('UsageStatsLibraryUrl') || q||, type => C4::Context->preference('UsageStatsLibraryType') || q||, country => C4::Context->preference('UsageStatsCountry') || q||, + geolocation => C4::Context->preference('UsageStatsGeolocation') || q||, }, + libraries => \@libraries, }; # Get database volumetry. @@ -351,8 +363,12 @@ sub ReportToCommunity { Content => $json, ); my $content = decode_json( $res->decoded_content ); - C4::Context->set_preference( 'UsageStatsID', - $content->{library}{id} ); + if ( $content->{koha_id} ) { + C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} ); + } + if ( $content->{id} ) { + C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} ); + } } =head2 _count --- a/Koha/Schema/Result/Branch.pm +++ a/Koha/Schema/Result/Branch.pm @@ -128,6 +128,12 @@ __PACKAGE__->table("branches"); data_type: 'text' is_nullable: 1 +=head2 geolocation + + data_type: 'varchar' + is_nullable: 1 + size: 255 + =cut __PACKAGE__->add_columns( @@ -171,6 +177,8 @@ __PACKAGE__->add_columns( { data_type => "mediumtext", is_nullable => 1 }, "opac_info", { data_type => "text", is_nullable => 1 }, + "geolocation", + { data_type => "varchar", is_nullable => 1, size => 255 }, ); =head1 PRIMARY KEY @@ -543,8 +551,8 @@ Composing rels: L -> categorycode __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-10-24 13:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/9YwsU+GXK+fzc6IX2Tj5g +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-02-06 10:07:25 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aq4mf5Dwbd8ps9ANLy8DuQ # You can replace this text with custom code or comments, and it will be preserved on regeneration --- a/admin/usage_statistics.pl +++ a/admin/usage_statistics.pl @@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Libraries; my $query = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -42,12 +43,21 @@ if ( $op eq 'update' ) { my $UsageStatsLibraryName = $query->param('UsageStatsLibraryName'); my $UsageStatsLibraryType = $query->param('UsageStatsLibraryType'); my $UsageStatsLibraryUrl = $query->param('UsageStatsLibraryUrl'); + my $UsageStatsLibrariesInfo = $query->param('UsageStatsLibrariesInfo'); + my $UsageStatsGeolocation = $query->param('UsageStatsGeolocation'); C4::Context->set_preference('UsageStats', $UsageStats); C4::Context->set_preference('UsageStatsCountry', $UsageStatsCountry); C4::Context->set_preference('UsageStatsLibraryName', $UsageStatsLibraryName); C4::Context->set_preference('UsageStatsLibraryType', $UsageStatsLibraryType); C4::Context->set_preference('UsageStatsLibraryUrl', $UsageStatsLibraryUrl); - + C4::Context->set_preference('UsageStatsLibrariesInfo', $UsageStatsLibrariesInfo); + C4::Context->set_preference('UsageStatsGeolocation', $UsageStatsGeolocation); + my $libraries = Koha::Libraries->search; + while ( my $library = $libraries->next ) { + if ( my $latlng = $query->param('geolocation_' . $library->branchcode) ) { + $library->geolocation( $latlng )->store; + } + } } if ( C4::Context->preference('UsageStatsLastUpdateTime') ) { @@ -55,4 +65,9 @@ if ( C4::Context->preference('UsageStatsLastUpdateTime') ) { $template->param(UsageStatsLastUpdateTime => output_pref($dt) ); } +my $libraries = Koha::Libraries->search; +$template->param( + libraries => $libraries, +); + output_html_with_http_headers $query, $cookie, $template->output; --- a/installer/data/mysql/atomicupdate/bug_18066.perl +++ a/installer/data/mysql/atomicupdate/bug_18066.perl @@ -0,0 +1,21 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + unless( column_exists( 'branches', 'geolocation' ) ) { + $dbh->do(q| + ALTER TABLE branches ADD COLUMN geolocation VARCHAR(255) DEFAULT NULL after opac_info + |); + } + + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsGeolocation', '', NULL, 'Geolocation of the main library', 'Free'); + |); + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsLibrariesInfo', '', NULL, 'Share libraries information', 'YesNo'); + |); + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsPublicID', '', NULL, 'Public ID for Hea website', 'Free'); + |); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18066 - Hea version 2)\n"; +} --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -540,10 +540,13 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UsageStats', 0, NULL, 'Share anonymous usage data on the Hea Koha community website.', 'YesNo'), ('UsageStatsCountry', '', NULL, 'The country where your library is located, to be shown on the Hea Koha community website', 'Choice'), ('UsageStatsID', '', NULL, 'This preference is part of Koha but it should not be deleted or updated manually.', 'Free'), +('UsageStatsGeolocation', '', NULL, 'Geolocation of the main library.', 'Free'), ('UsageStatsLastUpdateTime', '', NULL, 'This preference is part of Koha but it should not be deleted or updated manually.', 'Free'), +('UsageStatsLibrariesInfo', '', NULL, 'Share libraries information', 'YesNo'), ('UsageStatsLibraryName', '', NULL, 'The library name to be shown on Hea Koha community website', 'Free'), ('UsageStatsLibraryType', '', 'public|school|academic|research|private|societyAssociation|corporate|government|religiousOrg|subscription', 'The library type to be shown on the Hea Koha community website', 'Choice'), ('UsageStatsLibraryUrl', '', NULL, 'The library URL to be shown on Hea Koha community website', 'Free'), +('UsageStatsPublicID', '', NULL, 'Public ID for Hea website', 'Free'), ('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'), ('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'), ('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -820,6 +820,9 @@

jquery.tablednd.js

The TableDnD plug-in for jQuery by Denis Howlett is licensed under the MIT License.

+ +

Leaflet

+

The Leaflet JavaScript library by Vladimir Agafonkinis licensed under the BSD License.

--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -394,6 +394,17 @@ Administration: religiousOrg: "religious organization" subscription: "subscription" - Note that this value has no effect if the UsageStats system preference is set to "Don't share" + - + - pref: UsageStatsLibrariesInfo + choices: + yes: "Share" + no: "Do not Share" + - "libraries information (name, url, country)" + - Note that this value has no effect if the UsageStats system preference is set to "Don't share" + - + - Geolocation of the main library: + - pref: UsageStatsGeolocation + - Note that this value has no effect if the UsageStats system preference is set to "Don't share" Search Engine: - - "Use following search engine: " --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt @@ -5,6 +5,36 @@ Koha › Administration › Koha usage statistics [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'calendar.inc' %] + + + + @@ -48,7 +78,7 @@

Modify the statistics you share with the Koha community

-
    +
    1. +
    2. @@ -159,8 +189,58 @@ Your data have never been shared [% END %]
    3. +
    4. + + + +
    5. +
    6. + + +
    7. + +
    8. +
      + Libraries +
        + [% FOR l IN libraries %] +
      1. + +
        +
        Country: [% l.branchcountry %]
        +
        Url: [% l.branchurl %]
        +
        + Geolocation: + +
        +
        +
      2. + [% END %] +
      +
      +
    9. +
    10. + + [% IF Koha.Preference('UsageStatsPublicID') %] + [% SET my_url = 'http://hea.koha-community.org/libraries/' _ Koha.Preference('UsageStatsPublicID') %] + [% my_url %] + [% ELSE %] + You do not have anything public yet. + [% END %] +
    11. +
    -
+
+
+
@@ -169,6 +249,83 @@
+ +
--- a/misc/cronjobs/share_usage_with_koha_community.pl +++ a/misc/cronjobs/share_usage_with_koha_community.pl @@ -70,7 +70,7 @@ Only the total number is retrieved. In no case will private data be shared! In order to know which parts of Koha modules are used, this script will collect some system preference values. -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. +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. All these data will be analyzed on the http://hea.koha-community.org Koha community website. --- a/t/db_dependent/UsageStats.t +++ a/t/db_dependent/UsageStats.t @@ -15,11 +15,13 @@ # with Koha; if not, see . use Modern::Perl; -use Test::More tests => 57; +use Test::More tests => 59; use t::lib::Mocks qw(mock_preference); use POSIX qw(strftime); use Data::Dumper; +use Koha::Libraries; + BEGIN { use_ok('C4::UsageStats'); use_ok('C4::Context'); @@ -78,20 +80,22 @@ is( $update, 0, "Last update just be done, no update needed " ); #mock to 0 t::lib::Mocks::mock_preference( "UsageStatsID", 0 ); t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 0 ); -t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); +t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 0 ); t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 0 ); t::lib::Mocks::mock_preference( "UsageStatsCountry", 0 ); +t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); my $report = C4::UsageStats->BuildReport(); isa_ok( $report, 'HASH', '$report is a HASH' ); isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' ); -is( scalar( keys %{$report->{library}} ), 5, "There are 5 fields in $report->{library}" ); +is( scalar( keys %{$report->{library}} ), 6, "There are 6 fields in $report->{library}" ); is( $report->{library}->{id}, 0, "UsageStatsID is good" ); is( $report->{library}->{name}, '', "UsageStatsLibraryName is good" ); is( $report->{library}->{url}, '', "UsageStatsLibraryUrl is good" ); is( $report->{library}->{type}, '', "UsageStatsLibraryType is good" ); is( $report->{library}->{country}, '', "UsageStatsCountry is good" ); +is( $report->{library}->{number_of_libraries}, undef, "UsageStatsLibrariesInfo is good" ); #mock with values t::lib::Mocks::mock_preference( "UsageStatsID", 1 ); @@ -99,17 +103,20 @@ t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 'NAME' ); t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 'URL' ); t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' ); t::lib::Mocks::mock_preference( "UsageStatsCountry", 'COUNTRY' ); +t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 ); $report = C4::UsageStats->BuildReport(); isa_ok( $report, 'HASH', '$report is a HASH' ); isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' ); -is( scalar( keys %{$report->{library}} ), 5, "There are 5 fields in $report->{library}" ); +is( scalar( keys %{$report->{library}} ), 6, "There are 6 fields in $report->{library}" ); is( $report->{library}->{id}, 1, "UsageStatsID is good" ); is( $report->{library}->{name}, 'NAME', "UsageStatsLibraryName is good" ); is( $report->{library}->{url}, 'URL', "UsageStatsLibraryUrl is good" ); is( $report->{library}->{type}, 'TYPE', "UsageStatsLibraryType is good" ); is( $report->{library}->{country}, 'COUNTRY', "UsageStatsCountry is good" ); +my $nb_of_libraries = Koha::Libraries->count; +is( $report->{library}->{number_of_libraries}, $nb_of_libraries, "UsageStatsLibrariesInfo is good" ); #Test report->volumetry --------------- #with original values --