Jonathan Druart
63a1adff90
This patch is the Koha part of the Hea v2 project. You can find the (testing) code for the server at hea-ws - https://github.com/joubu/hea-ws/commits/v2 hea-app - https://github.com/joubu/hea-app/commits/v2 They contain the different pull requests made over the last 6 months. More information on Hea at https://wiki.koha-community.org/wiki/KohaUsageStat_RFC The goal of this commit message is to provide an overview of what could be a new version of Hea. Prior to these changes, the Hea database was filled with 1 line per Koha installation. System preferences were filled by the libraries and a cronjob (share_usage_with_koha_community.pl) collected these values to send them to a webservice (hea-ws/upload.pl). With the need to collect more data we would want to collect data at the library level (branch) and not at the installation level. For instance the geolocation, the url or the country can be different from one library to another, even if managed from the same Koha installation. The Hea DB has been upgraded to reflect that change (see hea-app/sql/schema.sql). The hidden goal of this patch is to make Hea sexier and explain better to libraries how it can be useful to share their information with the Koha community. I guess the main problem is the lack of communication and explanations about what we are doing we these data. To fill this gap I'd like to (TODO) 1. Communicate on the ML about this new version of Hea (once it got pushed and backported) 2. Link the Privacy_Policy.md from the Hea interface 3. Get help from a native English speaker to add popup/help/info/whatever on "Home › Administration › Usage statistics", to clearly explain what happens (and what will not happen!) when an option or another is set. You can find screenshot of this whole enhancement on bug 18066, comment 2. What this patch does: - 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 geolocations How does it works: On the new administration page where statistics to share are configured, there are several new things. It is now possible to share information either per Koha installation or libraries. If UsageStatsLibrariesInfo is set, the info at library level (url, name, country, geolocation) will be sent to the Hea webservice. If it is not set, you can decide to fill UsageStatsLibraryUrl, UsageStatsLibraryName, UsageStatsCountry, UsageStatsGeolocation to share these information. Note that even if the data are retrieved at installation level, it's better to fill the prefs as well: On the Hea website the different libraries defined for a given Koha installation could be displayed on the same page. This page is a public page which will be attributed to every installation (with the pref UsageStatsPublicID). On this page all the info available publicly will be displayed. TODO later: - Add a button on the administration page to delete the info shared publicly. It will be easy to show that the info are no longer displayed on the public page. - Add an icon per Koha installation to get a better "public page" - Any suggestions? Test plan: We will need to test hea-ws, hea-app and the Koha-side code to test the whole enhancement. 1/ To start, clone the hea-ws and hea-app project and checkout the 'master' branch (*not* 'v2') 2/ Create the hea database and user CREATE DATABASE hea CREATE USER 'hea'@'localhost' IDENTIFIED BY 'hea'; GRANT ALL PRIVILEGES ON hea.* TO 'hea'@'localhost'; FLUSH PRIVILEGES; 3/ Fill the DB with some data mysql hea < hea-app/sql/schema.sql mysql hea < hea-app/sql/sql/mock-data.sql 4/ Checkout the 'v2' branch for both hea-ws and hea-app 5/ Execute the upgrade DB script % cd hea-app % perl -p -i -e 's/REPLACE_ME/hea/' sql/upgrade.pl # Fill the DB info % perl sql/upgrade.pl Now the DB is using the v2 structure. That means we have 1 installation row per library previously defined. 1 library row has also been created. 5/ Configure hea-ws % echo '192.168.50.1 hea.koha-community.org' >> /etc/hosts <VirtualHost *:80> DocumentRoot "/path/to/hea-ws" ServerName "hea.koha-community.org" <Directory "/"> Options +ExecCGI Require all granted AddHandler cgi-script .pl </Directory> </VirtualHost> And enable it with a2ensite, then restart apache. The copy the database.yml.sample to database.yml and edit it to fill the DB info. 6/ Launch the hea-app % 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 Then hit localhost:3000 You should see a local version of Hea with sample data 7/ Back to Koha side A. We will test that the webservice still works with previous version of Koha (without v2) a. Do not configure Hea % perl misc/cronjobs/share_usage_with_koha_community.pl -f -v Then hit localhost:3000 => Nothing added b. Configure Hea on admin/usage_statistics.pl perl misc/cronjobs/share_usage_with_koha_community.pl -f -v => New library added c. Modify the Hea configuration perl misc/cronjobs/share_usage_with_koha_community.pl -f -v => Info are modified B. Not we will test that it works with the new version (much more fun ;)) % git checkout hea-v2 # koha a. Configure Hea using /admin/usage_statistics.pl perl misc/cronjobs/share_usage_with_koha_community.pl -f -v => Check the result on localhost:3000 b. Share libraries's info perl misc/cronjobs/share_usage_with_koha_community.pl -f -v c. Continue to play a bit and share the info. Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
73 lines
2.8 KiB
Perl
Executable file
73 lines
2.8 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
|
|
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(
|
|
{
|
|
template_name => "admin/usage_statistics.tt",
|
|
query => $query,
|
|
type => "intranet",
|
|
authnotrequired => 0,
|
|
flagsrequired => { parameters => '*' },
|
|
debug => 1,
|
|
}
|
|
);
|
|
|
|
my $op = $query->param('op') || q||;
|
|
|
|
if ( $op eq 'update' ) {
|
|
my $UsageStats = $query->param('UsageStats');
|
|
my $UsageStatsCountry = $query->param('UsageStatsCountry');
|
|
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') ) {
|
|
my $dt = DateTime->from_epoch( epoch => 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;
|