7042 Improving cleanup_database.pl: handling quotes in a_session and interpreting...
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 17 Oct 2011 09:32:50 +0000 (11:32 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Thu, 20 Oct 2011 15:39:24 +0000 (04:39 +1300)
Improving the cleanup_database.pl script in two aspects:
1) In some cases CGI::Session seems to place quotes around the atime and ctime
data in the a_session field. Two regexps now take this into account.
2) If the --sessdays parameter is used, the --sessions parameter is now
implicitly enabled too.

With thanks to Ian Bays and Tom Hanstra.

Signed-off-by: Ian Bays <ian.bays@ptfs-europe.com>
Signed-off-by: Ian Walls <ian.walls@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
misc/cronjobs/cleanup_database.pl

index 2b0cf90..12aa12b 100755 (executable)
@@ -44,7 +44,7 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu
                       other options
    --sessions         purge the sessions table.  If you use this while users 
                       are logged into Koha, they will have to reconnect.
-   --sessdays DAYS    purge only sessions older than DAYS days (use together with sessions parameter).
+   --sessdays DAYS    purge only sessions older than DAYS days.
    -v --verbose       will cause the script to give you a bit more information
                       about the run.
    --zebraqueue DAYS  purge completed entries from the zebraqueue from 
@@ -66,6 +66,7 @@ GetOptions(
     'zebraqueue:i' => \$zebraqueue_days,
     'merged'       => \$purge_merged,
 ) || usage(1);
+$sessions=1 if $sess_days && $sess_days>0;
 
 if ($help) {
     usage(0);
@@ -158,9 +159,9 @@ sub RemoveOldSessions {
 
     while ( $sth->fetch ) {
         $lasttime = 0;
-        if ( $a_session =~ /lasttime:\s+(\d+)/ ) {
+        if ( $a_session =~ /lasttime:\s+'?(\d+)/ ) {
             $lasttime = $1;
-        } elsif ( $a_session =~ /(ATIME|CTIME):\s+(\d+)/ ) {
+        } elsif ( $a_session =~ /(ATIME|CTIME):\s+'?(\d+)/ ) {
             $lasttime = $2;
         }
         if ( $lasttime && $lasttime < $limit ) {