| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
5230
|
use utf8; |
|
|
2
|
|
|
|
|
11
|
|
|
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
|
|
package Interchange6::Schema::ResultSet::Session; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Interchange6::Schema::ResultSet::Session |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=cut |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Check for expired sessions and carts. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
97
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
42
|
|
|
17
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
91
|
|
|
18
|
2
|
|
|
2
|
|
12
|
use mro 'c3'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
11
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
63
|
use DateTime; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
59
|
|
|
21
|
2
|
|
|
2
|
|
1071
|
use Time::Duration::Parse; |
|
|
2
|
|
|
|
|
4291
|
|
|
|
2
|
|
|
|
|
16
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
153
|
use parent 'Interchange6::Schema::ResultSet'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
30
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 expire( $expires ) |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Checks for expired sessions where I<$expires> is either in seconds or |
|
28
|
|
|
|
|
|
|
human readable format. Example '2 hours'. If the cart user is |
|
29
|
|
|
|
|
|
|
registered the session will be deleted but and the cart's session_id |
|
30
|
|
|
|
|
|
|
will be made NULL. Anonymous sessions/carts will be deleted. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub expire { |
|
35
|
4
|
|
|
4
|
1
|
129736
|
my ($self, $expires) = @_; |
|
36
|
4
|
|
|
|
|
21
|
my $schema = $self->result_source->schema; |
|
37
|
4
|
|
|
|
|
113
|
my $dtf = $schema->storage->datetime_parser; |
|
38
|
4
|
|
|
|
|
93
|
my $duration; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# converting to seconds |
|
41
|
4
|
100
|
|
|
|
18
|
if (defined $expires) { |
|
42
|
3
|
100
|
|
|
|
27
|
if ($expires =~ /^\d+$/) { |
|
43
|
|
|
|
|
|
|
# already got seconds |
|
44
|
1
|
|
|
|
|
4
|
$duration = $expires; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
2
|
|
|
|
|
11
|
$duration = parse_duration($expires); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
3
|
100
|
|
|
|
52
|
unless ($duration) { |
|
52
|
1
|
|
|
|
|
14
|
die "$0: Session expiration not set.\n"; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
11
|
my $max = DateTime->now->subtract( seconds => $duration ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#find expired sessions |
|
58
|
2
|
|
|
|
|
3729
|
my $session = $self->search( |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
|
|
|
|
|
|
last_modified => { '<=' => $dtf->format_datetime($max) }, |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
568
|
while (my $session_rs = $session->next) { |
|
65
|
|
|
|
|
|
|
# check for payment orders with this session |
|
66
|
3
|
|
|
|
|
6721
|
my $po_rs = $session_rs->search_related('payment_orders'); |
|
67
|
3
|
|
|
|
|
4582
|
while (my $po = $po_rs->next) { |
|
68
|
2
|
|
|
|
|
6946
|
$po->update({ sessions_id => undef }); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
# check for carts with this session |
|
71
|
3
|
|
|
|
|
9561
|
my $cart_rs = $session_rs->search_related('carts'); |
|
72
|
3
|
|
|
|
|
4406
|
while (my $cart = $cart_rs->next) { |
|
73
|
3
|
|
|
|
|
7320
|
my $user_id = $cart->users_id; |
|
74
|
|
|
|
|
|
|
# check for user |
|
75
|
3
|
100
|
|
|
|
53
|
if ($user_id) { |
|
76
|
2
|
|
|
|
|
15
|
$cart->update({ sessions_id => undef }); |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
1
|
|
|
|
|
22
|
$cart->delete; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
3
|
|
|
|
|
12405
|
$session_rs->delete; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |