Bug 20804: Add support for "days" to the timeout syspref

If the timeout syspref did not contain an integer, or was not matching
integer.'d|D', then it "fallback" to 0

We can easily add support for hours and fallback to 600 if the value is
not correct.
It will prevent the session to timeout immediately

Test plan:
0. Do not apply the patches
1. Fill the timeout syspref with "5h"
2. Login
3. Click somewhere
=> Notice that the session timed out
4. Apply the patches, restart_all
5. Login
6. Click somewhere
=> You have 5 hours to enjoy Koha
7. Fill the pref with an incorrect value ("5x" for instance)
8. Logout, login
9. There is a warning in the log, and you have 10 minutes (600 secondes) to enjoy Koha

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2020-07-30 15:15:46 +02:00
parent 3c9c7f4543
commit 97b9eab178
1 changed files with 12 additions and 2 deletions

View File

@ -762,12 +762,22 @@ sub _session_log {
}
sub _timeout_syspref {
my $timeout = C4::Context->preference('timeout') || 600;
my $default_timeout = 600;
my $timeout = C4::Context->preference('timeout') || $default_timeout;
# value in days, convert in seconds
if ( $timeout =~ /(\d+)[dD]/ ) {
if ( $timeout =~ /^(\d+)[dD]$/ ) {
$timeout = $1 * 86400;
}
# value in hours, convert in seconds
elsif ( $timeout =~ /^(\d+)[hH]$/ ) {
$timeout = $1 * 3600;
}
elsif ( $timeout !~ m/^\d+$/ ) {
warn "The value of the system preference 'timeout' is not correct, defaulting to $default_timeout";
$timeout = $default_timeout;
}
return $timeout;
}