From 05610f7621356a661f0bc41bc25472d46bc0fdef Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 21 Jun 2010 16:02:29 -0700 Subject: [PATCH] Correctly handle the case of finding new lastPost information when a Post is trashed. Fixes bug #11646. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Post.pm | 34 ++++++----- t/Asset/Post/archiving.t | 7 +-- t/Asset/Post/trashing.t | 119 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 20 deletions(-) create mode 100644 t/Asset/Post/trashing.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index e3850bd76..38c6a3884 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #11662: yahooapis.com sourced links - fixed #11658: tmpl var message missing in template help for the cart - fixed #11628: Message Board: Last Post doesn't show up in CS Thread List + - fixed #11646: Post and Thread Last Post 7.9.7 - added #11571: Allow return from photo edit view to gallery edit view diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index e5a8b2b72..f18360159 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1189,6 +1189,22 @@ sub postProcess { #------------------------------------------------------------------- +=head2 publish + +Extend the base method to handle updating last post information in the parent Thread +and CS. + +=cut + +sub publish { + my $self = shift; + $self->next::method(@_); + $self->qualifyAsLastPost; + return 1; +} + +#------------------------------------------------------------------- + =head2 purge Extend the base method to handle cleaning up storage locations. @@ -1398,7 +1414,8 @@ sub setStatusUnarchived { =head2 trash ( ) -Moves post to the trash, updates reply counter on thread and recalculates the thread rating. +Moves post to the trash, updates reply counter on thread, recalculates the thread rating, +and updates any lastPost information in the parent Thread, and CS. =cut @@ -1407,20 +1424,7 @@ sub trash { $self->next::method; $self->getThread->sumReplies if ($self->isReply); $self->getThread->updateThreadRating; - if ($self->getThread->get("lastPostId") eq $self->getId) { - my $threadLineage = $self->getThread->get("lineage"); - my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where - lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%' - order by creationDate desc",[$threadLineage.'%', $self->getId]); - $self->getThread->update({lastPostId=>$id, lastPostDate=>$date}); - } - if ($self->getThread->getParent->get("lastPostId") eq $self->getId) { - my $forumLineage = $self->getThread->getParent->get("lineage"); - my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where - lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%' - order by creationDate desc",[$forumLineage.'%', $self->getId]); - $self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date}); - } + $self->disqualifyAsLastPost; } #------------------------------------------------------------------- diff --git a/t/Asset/Post/archiving.t b/t/Asset/Post/archiving.t index 013a4c25b..327c70c27 100644 --- a/t/Asset/Post/archiving.t +++ b/t/Asset/Post/archiving.t @@ -8,11 +8,8 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# 1. The basic framework for a test suite for the Post Asset. -# Includes setup, cleanup, boilerplate, etc. Basically the really boring, -# repetitive parts of the test that you don't want to write yourself. -# 2. The tests for the features I've implemented; namely, functionality and -# general access controls on who can edit a post. +## Test that archiving a post works, and checking side effects like updating +## lastPost information in the Thread, and CS. use FindBin; use strict; diff --git a/t/Asset/Post/trashing.t b/t/Asset/Post/trashing.t new file mode 100644 index 000000000..f45473a2b --- /dev/null +++ b/t/Asset/Post/trashing.t @@ -0,0 +1,119 @@ +#------------------------------------------------------------------- +# 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 trashing a post works, and checking side effects like updating +## lastPost information in the Thread, and CS. + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use WebGUI::Test; +use WebGUI::Session; +use Test::More tests => 13; # increment this value for each test you create +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'}, @addArgs); + +# finally, add posts and threads to the collaboration system + +my $first_thread = $collab->addChild( + { className => 'WebGUI::Asset::Post::Thread', }, + undef, + WebGUI::Test->webguiBirthday, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +my $second_thread = $collab->addChild( + { className => 'WebGUI::Asset::Post::Thread', }, + undef, + WebGUI::Test->webguiBirthday, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +##Thread 1, Post 1 => t1p1 +my $t1p1 = $first_thread->addChild( + { className => 'WebGUI::Asset::Post', }, + undef, + WebGUI::Test->webguiBirthday, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +my $t1p2 = $first_thread->addChild( + { className => 'WebGUI::Asset::Post', }, + undef, + WebGUI::Test->webguiBirthday + 1, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +my $past = time()-15; + +my $t2p1 = $second_thread->addChild( + { className => 'WebGUI::Asset::Post', }, + undef, + $past, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +my $t2p2 = $second_thread->addChild( + { className => 'WebGUI::Asset::Post', }, + undef, + undef, + { skipAutoCommitWorkflows => 1, skipNotification => 1 } +); + +$versionTag->commit(); +WebGUI::Test->addToCleanup($versionTag); + +foreach my $asset ($collab, $t1p1, $t1p2, $t2p1, $t2p2, $first_thread, $second_thread, ) { + $asset = $asset->cloneFromDb; +} + +is $collab->getChildCount, 2, 'collab has correct number of children'; + +is $collab->get('lastPostId'), $t2p2->getId, 'lastPostId set in collab'; +is $collab->get('lastPostDate'), $t2p2->get('creationDate'), 'lastPostDate, too'; + +$t2p2->trash; +is $t2p2->get('state'), 'trash', 'cut set the post to be in the clipboard'; + +$second_thread = $second_thread->cloneFromDb; +is $second_thread->get('lastPostId'), $t2p1->getId, '.. updated lastPostId in the thread'; +is $second_thread->get('lastPostDate'), $t2p1->get('creationDate'), '... lastPostDate, too'; + +$collab = $collab->cloneFromDb; +is $collab->get('lastPostId'), $t2p1->getId, '.. updated lastPostId in the CS'; +is $collab->get('lastPostDate'), $t2p1->get('creationDate'), '... lastPostDate, too'; + +$t2p2->restore; +is $t2p2->get('state'), 'published', 'publish sets the post normal'; + +$second_thread = $second_thread->cloneFromDb; +is $second_thread->get('lastPostId'), $t2p2->getId, '.. updated lastPostId in the thread'; +is $second_thread->get('lastPostDate'), $t2p2->get('creationDate'), '... lastPostDate, too'; + +$collab = $collab->cloneFromDb; +is $collab->get('lastPostId'), $t2p2->getId, '.. updated lastPostId in the CS'; +is $collab->get('lastPostDate'), $t2p2->get('creationDate'), '... lastPostDate, too'; + +#vim:ft=perl