Skip to content

Commit

Permalink
Correctly handle the case of finding new lastPost information when a …
Browse files Browse the repository at this point in the history
…Post is trashed. Fixes bug #11646.
  • Loading branch information
perlDreamer committed Jun 21, 2010
1 parent 54c5601 commit 05610f7
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -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
Expand Down
34 changes: 19 additions & 15 deletions lib/WebGUI/Asset/Post.pm
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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;
}

#-------------------------------------------------------------------
Expand Down
7 changes: 2 additions & 5 deletions t/Asset/Post/archiving.t
Expand Up @@ -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;
Expand Down
119 changes: 119 additions & 0 deletions 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

0 comments on commit 05610f7

Please sign in to comment.