|
| 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 | + |
0 commit comments