Skip to content

Commit 07bd545

Browse files
committedApr 3, 2012
Remove cookie jar files left by the HttpProxy asset. Finishes the fix for bug #12327.
1 parent 604887f commit 07bd545

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
 

‎docs/upgrades/upgrade_7.10.24-7.10.25.pl

+16
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@ BEGIN
3131
my $session = start(); # this line required
3232

3333
# upgrade functions go here
34+
installCleanCookieJars($session);
3435

3536
finish($session); # this line required
3637

3738

39+
#----------------------------------------------------------------------------
40+
# Describe what our function does
41+
sub installCleanCookieJars {
42+
my $session = shift;
43+
print "\tInstall the new CleanCookieJars workflow activity... " unless $quiet;
44+
# and here's our code
45+
$session->config->addToArray('workflowActivities/None', 'WebGUI::Workflow::Activity::CleanCookieJars');
46+
my $workflow = WebGUI::Workflow->new($session, 'pbworkflow000000000001');
47+
my $cleaner = $workflow->addActivity('WebGUI::Workflow::Activity::CleanCookieJars');
48+
$cleaner->set('title', 'Clean HttpProxy Cookie jars');
49+
$cleaner->set('description', 'Removes cookie jar files from the HttpProxy asset that are older than 1 day');
50+
print "DONE!\n" unless $quiet;
51+
}
52+
53+
3854
#----------------------------------------------------------------------------
3955
# Describe what our function does
4056
#sub exampleFunction {

‎etc/WebGUI.conf.original

+1
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@
897897
"WebGUI::Workflow::Activity::ArchiveOldStories",
898898
"WebGUI::Workflow::Activity::ArchiveOldThreads",
899899
"WebGUI::Workflow::Activity::CalendarUpdateFeeds",
900+
"WebGUI::Workflow::Activity::CleanCookieJars",
900901
"WebGUI::Workflow::Activity::CleanDatabaseCache",
901902
"WebGUI::Workflow::Activity::CleanFileCache",
902903
"WebGUI::Workflow::Activity::CleanLoginHistory",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package WebGUI::Workflow::Activity::CleanCookieJars;
2+
3+
4+
=head1 LEGAL
5+
6+
-------------------------------------------------------------------
7+
WebGUI is Copyright 2001-2012 Plain Black Corporation.
8+
-------------------------------------------------------------------
9+
Please read the legal notices (docs/legal.txt) and the license
10+
(docs/license.txt) that came with this distribution before using
11+
this software.
12+
-------------------------------------------------------------------
13+
http://www.plainblack.com info@plainblack.com
14+
-------------------------------------------------------------------
15+
16+
=cut
17+
18+
use strict;
19+
use base 'WebGUI::Workflow::Activity';
20+
use WebGUI::International;
21+
use WebGUI::Storage;
22+
use File::Basename ();
23+
use File::Spec;
24+
25+
=head1 NAME
26+
27+
Package WebGUI::Workflow::Activity::CleanCookieJars
28+
29+
=head1 DESCRIPTION
30+
31+
Cleans up stale cookie jars
32+
33+
=head1 SYNOPSIS
34+
35+
See WebGUI::Workflow::Activity for details on how to use any activity.
36+
37+
=head1 METHODS
38+
39+
These methods are available from this class:
40+
41+
=cut
42+
43+
44+
#-------------------------------------------------------------------
45+
46+
=head2 definition ( session, definition )
47+
48+
See WebGUI::Workflow::Activity::defintion() for details.
49+
50+
=cut
51+
52+
sub definition {
53+
my $class = shift;
54+
my $session = shift;
55+
my $definition = shift;
56+
my $i18n = WebGUI::International->new( $session, "Workflow_Activity_CleanCookieJars" );
57+
push(@{$definition}, {
58+
name => $i18n->get("activity cleanup cookie jars"),
59+
properties => {}
60+
});
61+
return $class->SUPER::definition($session,$definition);
62+
}
63+
64+
65+
#-------------------------------------------------------------------
66+
67+
=head2 execute ( )
68+
69+
See WebGUI::Workflow::Activity::execute() for details.
70+
71+
=cut
72+
73+
sub execute {
74+
my $self = shift;
75+
my $session = $self->session;
76+
# keep track of how much time it's taking
77+
my $stop_time = time + $self->getTTL;
78+
79+
my $get_proxy = $session->db->read('select assetId, revisionDate, cookieJarStorageId from HttpProxy');
80+
STORAGEID: while (1) {
81+
my ($assetId, $revisionDate, $storageId,) = $get_proxy->array();
82+
last STORAGEID unless $storageId;
83+
my $storage = WebGUI::Storage->get($session, $storageId);
84+
next unless $storage;
85+
opendir my $directory, $storage->getPath;
86+
FILE: while (my $file = readdir($directory)) {
87+
next FILE if $file =~ /^\./;
88+
my $whole_file = $storage->getPath($file);
89+
if (-M $whole_file >=1) {
90+
unlink $whole_file;
91+
}
92+
last STORAGEID if time > $stop_time;
93+
}
94+
}
95+
return $self->WAITING(1) if time > $stop_time;
96+
return $self->COMPLETE;
97+
}
98+
99+
1;
100+
101+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package WebGUI::i18n::English::Workflow_Activity_CleanCookieJars;
2+
use strict;
3+
4+
our $I18N = {
5+
'activity cleanup cookie jars' => {
6+
message => q|Clean Stale Cookie-Jar Files|,
7+
context => q|The name of this workflow activity.|,
8+
lastUpdated => 0,
9+
},
10+
};
11+
12+
1;

0 commit comments

Comments
 (0)