From 13d65d8b4a06d2b6eebc54e9703654f48fee4fe9 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 19 Aug 2010 11:45:18 -0700 Subject: [PATCH] purgeCache also cleans up internally cached objects, _parent, _thread --- lib/WebGUI/Asset.pm | 3 +- lib/WebGUI/Asset/Post.pm | 10 ++---- t/Asset/Post/committing.t | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 t/Asset/Post/committing.t diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 413e8e1f6..e6e388b21 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2350,7 +2350,7 @@ sub publish { =head2 purgeCache ( ) -Purges all cache entries associated with this asset. +Purges all cache entries associated with this asset, CHI, Session->stow and object caches =cut @@ -2361,6 +2361,7 @@ sub purgeCache { $stow->delete('assetClass'); $stow->delete('assetRevision'); $self->session->cache->remove("asset".$self->getId.$self->revisionDate); + $self->{_parent}; } diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index a6dddeffe..402858b9e 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -293,30 +293,23 @@ the parent thread. =cut override cut => sub { - warn "post's cut"; my $self = shift; # Fetch the Thread and CS before cutting the asset. my $thread = $self->getThread; - warn "got thread"; my $cs = $thread->getParent; - warn "got cs"; # Cut the asset my $result = super(); - warn "called super"; # If a post is being cut update the thread reply count first if ($thread->getId ne $self->getId) { - warn "calling _fixReplyCount on thread"; $self->_fixReplyCount( $thread ); } # Update the CS reply count. This step is also necessary when a Post is cut since the Thread's incrementReplies # also calls the CS's incrementReplies, possibly with the wrong last post Id. - warn "calling _fixReplyCount on cs"; $self->_fixReplyCount( $cs ); - warn "all should be well...?"; return $result; }; @@ -790,6 +783,8 @@ sub getThread { } $self->{_thread} = WebGUI::Asset::Post::Thread->newById($self->session, $threadId); } + else { + } return $self->{_thread}; } @@ -1202,6 +1197,7 @@ override purgeCache => sub { my $self = shift; $self->session->cache->remove("view_".$self->getThread->getId) if ($self->getThread); super(); + delete $self->{_thread}; }; #------------------------------------------------------------------- diff --git a/t/Asset/Post/committing.t b/t/Asset/Post/committing.t new file mode 100644 index 000000000..11084abdb --- /dev/null +++ b/t/Asset/Post/committing.t @@ -0,0 +1,75 @@ +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +## Test that committing a post works, and doesn't affect the parent thread. + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use WebGUI::Test; +use WebGUI::Session; +use WebGUI::Asset::Wobject::Collaboration; +use WebGUI::Asset::Post; +use WebGUI::Asset::Post::Thread; + +my $session = WebGUI::Test->session; + +# Do our work in the import node +my $node = WebGUI::Asset->getImportNode($session); + +# Grab a named version tag +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Collab setup"}); + +# Need to create a Collaboration system in which the post lives. +my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1, skipNotification => 1 } ); + +my $collab = $node->addChild( + { + className => 'WebGUI::Asset::Wobject::Collaboration', + title => 'Test Collaboration', + }, + @addArgs +); + +# finally, add posts and threads to the collaboration system + +my $first_thread = $collab->addChild( + { + className => 'WebGUI::Asset::Post::Thread', + title => 'Test Thread', + }, + @addArgs +); + +##Thread 1, Post 1 => t1p1 +my $t1p1 = $first_thread->addChild( + { + className => 'WebGUI::Asset::Post', + title => 'Test Post', + }, + @addArgs +); + +$versionTag->commit(); +WebGUI::Test->addToCleanup($versionTag); + +foreach my $asset ($collab, $t1p1, $first_thread, ) { + $asset = $asset->cloneFromDb; +} + +is $collab->getChildCount, 1, 'collab has correct number of children'; +is $first_thread->status, 'approved', 'thread is approved'; +is $t1p1->status, 'approved', 'post is approved'; + +done_testing; + +#vim:ft=perl