diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7c517c2d6..f0ac4b9d4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.10.18 - fixed #12141: Macro_RenderThingData (bad tags) nothing to translate + - fixed #12142: Copy fails on imported threads 7.10.17 - fixed: Forced to use a PayDriver even with a balance of 0 in the cart. diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 0a764964f..3b3bfb40d 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -265,14 +265,18 @@ Extends the base method to handle creating a new subscription group. =cut sub duplicate { - my $self = shift; - my $session = $self->session; - my $copy = $self->SUPER::duplicate(@_); - if ($self->get('subscriptionGroupId')) { - my $group = WebGUI::Group->new($session, $self->get('subscriptionGroupId')); - my $copied_group = WebGUI::Group->new($session, 'new'); - $copied_group->addUsers($group->getUsers('withoutExpired')); - $copy->update({subscriptionGroupId => $copied_group->getId}); + my $self = shift; + my $session = $self->session; + my $copy = $self->SUPER::duplicate(@_); + my $oldGroupId = $self->get('subscriptionGroupId'); + + if ($oldGroupId) { + my $newGroup = WebGUI::Group->new($session, 'new'); + my $oldGroup = WebGUI::Group->new($session, $oldGroupId); + if ($oldGroup) { + $newGroup->addUsers($oldGroup->getUsers('withoutExpired')); + } + $copy->update({subscriptionGroupId => $newGroup->getId}); } return $copy; } diff --git a/t/Asset/Post/Thread/bug_12142_duplicate.t b/t/Asset/Post/Thread/bug_12142_duplicate.t new file mode 100644 index 000000000..9149aa110 --- /dev/null +++ b/t/Asset/Post/Thread/bug_12142_duplicate.t @@ -0,0 +1,48 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------ + +=head1 BUG DESCRIPTION + +Thread's duplicate method fails if the subscriptionGroupId isn't a valid group +(for instance, if it was imported from another site). It should just not copy +the group in that case. + +=cut + +use warnings; +use strict; + +use Test::More tests => 4; +use Test::Exception; +use FindBin; + +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; +use WebGUI::Asset; + +my $session = WebGUI::Test->session; +my $thread = WebGUI::Asset->getImportNode($session)->addChild( + { + className => 'WebGUI::Asset::Post::Thread', + subscriptionGroupId => $session->id->generate(), + } +); +WebGUI::Test->addToCleanup($thread); + +SKIP: { + my $copy; + skip('duplicate died', 3) unless + lives_ok { $copy = $thread->duplicate() } q"duplicate() doesn't die"; + my $groupId = $copy->get('subscriptionGroupId'); + ok $groupId, 'Copy has a group id'; + isnt $groupId, $thread->get('subscriptionGroupId'), '...a different one'; + ok(WebGUI::Group->new($session, $groupId), '...and it instantiates'); +}; diff --git a/t/_bug.skeleton b/t/_bug.skeleton new file mode 100644 index 000000000..90f129230 --- /dev/null +++ b/t/_bug.skeleton @@ -0,0 +1,32 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------ + +=head1 BUG DESCRIPTION + +Blah blah blah, whatever the bug poster said in the initial post plus any +relevant clarification from the discussion thread. + +=cut + +use warnings; +use strict; + +use Test::More tests => 0; +use FindBin; + +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; + +my $session = WebGUI::Test->session; + +# A bug test should test the bug it is named for and be placed in an +# appropriate place in the test tree. For example, if bug #34721 was a Snippet +# bug, it would go in t/Asset/Snippet/bug_34721_short_description.t.