1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: dump_session.coretag,v 1.8 2007-03-30 23:40:54 pajamian Exp $
10 UserTag dump_session Order name
11 UserTag dump_session AddAttr
12 UserTag dump_session Version $Revision: 1.8 $
13 UserTag dump_session Routine <<EOR
16 return $ref unless $key;
17 if ($key eq 'SCALAR') {
19 foreach my $k (keys %$ref) {
20 next if ref $ref->{$k};
21 $newref->{$k} = $ref->{$k};
26 return { $key, $ref->{$key} };
31 my ($name, $opt) = @_;
32 my $joiner = $opt->{joiner} || ' ';
33 return "Cannot dump or find sessions with session type $Vend::Cfg->{SessionType}."
34 if ($Vend::Cfg->{SessionType} ne 'File' && $Vend::Cfg->{SessionType} ne 'DBI');
37 if ($Vend::Cfg->{SessionType} eq 'File') {
40 my $expire = $Vend::Cfg->{SessionExpire};
41 if( int($::Variable->{ACTIVE_SESSION_MINUTES}) ) {
42 $expire = $::Variable->{ACTIVE_SESSION_MINUTES} * 60;
45 $expire = $now - $expire;
49 return if (stat(_))[9] < $expire;
53 File::Find::find($wanted, $Vend::Cfg->{SessionDatabase});
54 return join $joiner, @files;
57 return "dump-session: Nothing to do.";
60 my $fn = Vend::Util::get_filename($name, 2, 1, $Vend::Cfg->{SessionDatabase});
61 return '' unless -f $fn;
62 my $ref = Vend::Util::eval_file($fn);
64 $ref = show_part($ref, $opt->{key}) if $opt->{key};
68 $out = Vend::Util::uneval($ref);
70 return uneval($ref) if $@;
75 if ($Vend::Cfg->{SessionType} eq 'DBI') {
77 my $expire = $Vend::Cfg->{SessionExpire};
78 if( int($::Variable->{ACTIVE_SESSION_MINUTES}) ) {
79 $expire = $::Variable->{ACTIVE_SESSION_MINUTES} * 60;
82 $expire = $now - $expire;
85 my $db = Vend::Data::database_exists_ref($Vend::Cfg->{SessionDB})
86 or return errmsg("Table %s is not available", $Vend::Cfg->{SessionDB});
88 my $tname = $db->name();
89 my $sql = "select code from $tname where UNIX_TIMESTAMP(last_accessed) >= ?";
91 my $sth = $dbh->prepare($sql);
92 $sth->execute($expire) || return $DBI::errstr;
94 $sth->bind_columns( undef, \$code);
97 push @sesscodes, $code;
100 return join $joiner, @sesscodes;
103 return "dump-session: Nothing to do.";
106 my $db = Vend::Data::database_exists_ref($Vend::Cfg->{SessionDB})
107 or return errmsg("Table %s is not available", $Vend::Cfg->{SessionDB});
108 my $dbh = $db->dbh();
109 my $tname = $db->name();
110 my $sql = "select session from $tname where code=?";
112 my $sth = $dbh->prepare($sql);
113 $sth->execute($name);
115 $sth->bind_columns( undef, \$session);
120 my $ref = Vend::Util::evalr($session);
122 ## Allow show of only part
123 $ref = show_part($ref, $opt->{key}) if $opt->{key};
126 $out = Vend::Util::uneval($ref);
128 return uneval($ref) if $@;