From 6d2d950f52f7b942fef9388b3de294d70a8f3e99 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 9 Jun 2010 11:28:00 -0700 Subject: [PATCH] Fix the delete expired events workflow (again). Fixes bug #11619 --- docs/changelog/7.x.x.txt | 1 + .../Workflow/Activity/TrashExpiredEvents.pm | 8 +- t/Workflow/Activity/TrashExpiredEvents.t | 103 ++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 t/Workflow/Activity/TrashExpiredEvents.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index cfe3152d3..5f764feda 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - fixed #11606: Syndicated Content feed returns a relative link - fixed #11614: Forums: Sort Fields - fixed #11616: No access to /root + - fixed #11619: Trash Expired Events not trashing events 7.9.6 - new checkbox in the asset manager for clearing the package flag on import diff --git a/lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm b/lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm index 79fd18ab6..d1ddf12fe 100644 --- a/lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm +++ b/lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm @@ -75,11 +75,13 @@ See WebGUI::Workflow::Activity::execute() for details. =cut sub execute { - my $self = shift; - my $sth = $self->session->db->read( "select assetId from Event where endDate < ?", [ time() - $self->get("trashAfter") ]); + my $self = shift; + my $session = $self->session; my $finishTime = time() + $self->getTTL; + my $date = WebGUI::DateTime->new($session, time() - $self->get("trashAfter") ); + my $sth = $session->db->read( "select Event.assetId, revisionDate from Event join assetData using (assetId, revisionDate) where endDate < ? and revisionDate = (select max(revisionDate) from assetData where assetData.assetId=Event.assetId);", [ $date->toDatabaseDate ]); EVENT: while ( my ($id) = $sth->array ) { - my $asset = WebGUI::Asset::Event->new( $self->session, $id ); + my $asset = WebGUI::Asset::Event->new( $session, $id ); if ( defined $asset ) { $asset->trash; } diff --git a/t/Workflow/Activity/TrashExpiredEvents.t b/t/Workflow/Activity/TrashExpiredEvents.t new file mode 100644 index 000000000..04ce3c844 --- /dev/null +++ b/t/Workflow/Activity/TrashExpiredEvents.t @@ -0,0 +1,103 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; + +use WebGUI::Test; +use WebGUI::Session; +use WebGUI::Utility; +use WebGUI::Workflow::Activity::TrashExpiredEvents; +use WebGUI::Asset; + +use Test::More; +use Test::Deep; + +plan tests => 5; # increment this value for each test you create + +my $session = WebGUI::Test->session; +$session->user({userId => 3}); + +my $bday = WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday)->cloneToUserTimeZone; +my $now = WebGUI::DateTime->new($session, time())->cloneToUserTimeZone; +my $tz = $session->datetime->getTimeZone(); + +my $root = WebGUI::Asset->getRoot($session); +my $calendar = $root->addChild({ + className => 'WebGUI::Asset::Wobject::Calendar', + title => 'Test Calendar', +}); +my $wgBday = $calendar->addChild({ + className => 'WebGUI::Asset::Event', + title => 'WebGUI Birthday', + startDate => $bday->toDatabaseDate, + endDate => $bday->toDatabaseDate, + timeZone => $tz, +}, undef, undef, {skipAutoCommitWorkflows => 1}); + +my $wrongBday = $calendar->addChild({ + className => 'WebGUI::Asset::Event', + title => 'Wrong Birthday', + startDate => $bday->toDatabaseDate, + endDate => $bday->toDatabaseDate, + timeZone => $tz, +}, undef, time()-5, {skipAutoCommitWorkflows => 1}); + +$wrongBday->addRevision({ + startDate => $now->toDatabaseDate, + endDate => $now->toDatabaseDate, +}, undef, undef, {skipAutoCommitWorkflows => 1}); + +my $nowEvent = $calendar->addChild({ + className => 'WebGUI::Asset::Event', + title => 'WebGUI Birthday', + startDate => $now->toDatabaseDate, + endDate => $now->toDatabaseDate, + timeZone => $tz, +}, undef, undef, {skipAutoCommitWorkflows => 1}); + +my $tag = WebGUI::VersionTag->getWorking($session); +$tag->commit; +WebGUI::Test->tagsToRollback($tag); + +my $workflow = WebGUI::Workflow->create($session, + { + enabled => 1, + objectType => 'None', + mode => 'realtime', + }, +); +WebGUI::Test->addToCleanup($workflow); +my $eventNuker = $workflow->addActivity('WebGUI::Workflow::Activity::TrashExpiredEvents'); +$eventNuker->set('trashAfter', 3600); + +my $instance1 = WebGUI::Workflow::Instance->create($session, + { + workflowId => $workflow->getId, + skipSpectreNotification => 1, + } +); + +my $retVal; + +$retVal = $instance1->run(); +is($retVal, 'complete', 'cleanup: activity complete'); +$retVal = $instance1->run(); +is($retVal, 'done', 'cleanup: activity is done'); +$instance1->delete('skipNotify'); + +my $wgBdayCopy = $wgBday->cloneFromDb; +my $nowEventCopy = $nowEvent->cloneFromDb; +my $wrongBdayCopy = $wrongBday->cloneFromDb; + +is $wgBdayCopy->get('state'), 'trash', 'old event was trashed'; +is $nowEventCopy->get('state'), 'published', 'recent event was left alone'; +is $wrongBdayCopy->get('state'), 'published', 'revisioned event was left alone';