From 6e0983a67ba93f2abd87087d815f6001a251d890 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 11 Jan 2010 11:54:59 -0800 Subject: [PATCH] Update the number of threads in the CS when a thread is archived. Fixes bug #11341. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Post/Thread.pm | 4 +- lib/WebGUI/i18n/English/Asset_MessageBoard.pm | 4 +- t/Asset/Wobject/Collaboration.t | 51 ++++++++++++------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 659daf78d..99b8d6582 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.8.10 - fixed #11332: Pagination in webgui.org forum urls + - fixed #11341: tmpl_var forum.threads 7.8.9 - fixed #11235: wiki search diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 9fb5c3d2a..5c86e5337 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -41,7 +41,7 @@ sub addRevision { =head2 archive -Archives all posts under this thread. +Archives all posts under this thread. Update the thread count in the parent CS. =cut @@ -50,6 +50,8 @@ sub archive { foreach my $post (@{$self->getPosts}) { $post->setStatusArchived; } + my $cs = $self->getParent; + $cs->incrementThreads($cs->get("lastPostId"), $cs->get("lastPostDate")); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/English/Asset_MessageBoard.pm b/lib/WebGUI/i18n/English/Asset_MessageBoard.pm index c89e928ea..39a796725 100644 --- a/lib/WebGUI/i18n/English/Asset_MessageBoard.pm +++ b/lib/WebGUI/i18n/English/Asset_MessageBoard.pm @@ -93,8 +93,8 @@ our $I18N = { }, 'forum.threads' => { - message => q|The total number of threads in this forum.|, - lastUpdated => 1149632734, + message => q|The total number of threads in this forum. This does not include those that have been archived.|, + lastUpdated => 1263239637, }, 'forum.url' => { diff --git a/t/Asset/Wobject/Collaboration.t b/t/Asset/Wobject/Collaboration.t index 7fcf3f79d..49547fd43 100644 --- a/t/Asset/Wobject/Collaboration.t +++ b/t/Asset/Wobject/Collaboration.t @@ -19,9 +19,15 @@ use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Post; use WebGUI::Asset::Wobject::Layout; use Data::Dumper; -use Test::More tests => 13; # increment this value for each test you create +use Test::More tests => 16; # increment this value for each test you create my $session = WebGUI::Test->session; +my @addChildCoda = (undef, undef, + { + skipAutoCommitWorkflows => 1, + skipNotification => 1, + } +); # Do our work in the import node my $node = WebGUI::Asset->getImportNode($session); @@ -62,26 +68,23 @@ my $props = { className => 'WebGUI::Asset::Post::Thread', content => 'hello, world!', }; -my $post = $collab->addChild($props, - undef, - undef, - { - skipAutoCommitWorkflows => 1, - }); +my $thread = $collab->addChild($props, @addChildCoda); +my $tag1 = WebGUI::VersionTag->getWorking($session); +$tag1->commit; +addToCleanup($tag1); # Test for a sane object type -isa_ok($post, 'WebGUI::Asset::Post::Thread'); +isa_ok($thread, 'WebGUI::Asset::Post::Thread'); $props = { className => 'WebGUI::Asset::Post::Thread', content => 'jello, world!', }; -$post = $collab->addChild($props, - undef, - undef, - { - skipAutoCommitWorkflows => 1, - }); + +my $thread2 = $collab->addChild($props, @addChildCoda); +my $tag2 = WebGUI::VersionTag->getWorking($session); +$tag2->commit; +addToCleanup($tag2); my $rssitems = $collab->getRssFeedItems(); is(scalar @{ $rssitems }, 2, 'rssitems set to number of posts added'); @@ -97,7 +100,19 @@ addToCleanup(WebGUI::VersionTag->new($session, $dupedCollab->get('tagId'))); ok($dupedCollab->get('getMailCronId'), 'Duplicated CS has a cron job'); isnt($dupedCollab->get('getMailCronId'), $collab->get('getMailCronId'), '... and it is different from its source asset'); -TODO: { - local $TODO = "Tests to make later"; - ok(0, 'A whole lot more work to do here'); -} +note "Thread and Post count tests"; +$collab = $collab->cloneFromDb; +is $collab->get('threads'), 2, 'CS has 2 thread'; +is $collab->get('replies'), 0, '... and no replies (posts)'; + +$thread2->archive(); +$collab = $collab->cloneFromDb; +is $collab->get('threads'), 1, 'CS lost 1 thread due to archiving'; + +my $thread3 = $collab->addChild($props, @addChildCoda); +my $tag3 = WebGUI::VersionTag->getWorking($session); +$tag3->commit; +addToCleanup($tag3); +$collab = $collab->cloneFromDb; +is $collab->get('threads'), 2, '... added 1 thread'; +