From 0cab4157c854dfc0d9eb94302904377949263102 Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Wed, 24 Aug 2016 15:45:54 +0200
Subject: [PATCH] Bug 17187: Lower the timeout preference from 139 days to 1
 day

Default timeout is now 12000000 seconds == almost 139 days !
Surely, your session will be shorter. But we should lower this
value.
Balancing usability and security, I propose 1d (1 day) now.
Current pref value will be affected only if it is NULL or equal
to the old default.

Test plan:
Check your current value. Optionally change to NULL or 12000000.
Run the dbrev and see what happens.
Beware of cached values while testing or flush the cache.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 .../data/mysql/atomicupdate/Bug_17187_dbrev.perl   | 30 ++++++++++++++++++++++
 installer/data/mysql/sysprefs.sql                  |  2 +-
 .../prog/en/modules/admin/preferences/admin.pref   |  1 -
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/Bug_17187_dbrev.perl

diff --git a/installer/data/mysql/atomicupdate/Bug_17187_dbrev.perl b/installer/data/mysql/atomicupdate/Bug_17187_dbrev.perl
new file mode 100644
index 0000000..0edffcf
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/Bug_17187_dbrev.perl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+use C4::Context;
+
+my $dbh = C4::Context->dbh;
+my $DBversion = 'XXX';
+
+# @RM: Copy from here
+
+#if ( CheckVersion($DBversion) ) {
+if ( 1 ) { #FIXME
+    my $pref = C4::Context->preference('timeout');
+    if( !$pref || $pref eq '12000000' ) {
+        # update if pref is null or equals old default value
+        $dbh->do(q|
+UPDATE systempreferences SET value = '1d', type = 'Free'
+WHERE variable = 'timeout'
+        |);
+        print "Upgrade to $DBversion done (Bug 17187)\nNote: Pref value for timeout has been adjusted.\n";
+    } else {
+        # only update pref type
+        $dbh->do(q|
+UPDATE systempreferences SET type = 'Free'
+WHERE variable = 'timeout'
+        |);
+        print "Upgrade to $DBversion done (Bug 17187)\nNote: Pref value for timeout has not been adjusted.\n";
+    }
+    #SetVersion($DBversion); #FIXME
+}
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index ac6f852..9d5b085 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -499,7 +499,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('template','prog','','Define the preferred staff interface template','Themes'),
 ('ThingISBN','0','','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo'),
 ('TimeFormat','24hr','12hr|24hr','Defines the global time format for visual output.','Choice'),
-('timeout','12000000',NULL,'Inactivity timeout for cookies authentication (in seconds)','Integer'),
+('timeout','1d',NULL,'Inactivity timeout for cookies authentication','Free'),
 ('todaysIssuesDefaultSortOrder','desc','asc|desc','Specify the sort order of Todays Issues on the circulation page','Choice'),
 ('TraceCompleteSubfields','0','0','Force subject tracings to only match complete subfields.','YesNo'),
 ('TraceSubjectSubdivisions','0','1','Create searches on all subdivisions for subject tracings.','YesNo'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
index 03e23ac..daaddf8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
@@ -75,7 +75,6 @@ Administration:
         -
             - Automatically log out users after
             - pref: timeout
-              class: integer
             - seconds of inactivity. Adding d will specify it in days, e.g. 1d is timeout of one day.
         -
             - pref: AutoLocation
-- 
2.8.1