Fixed bug #11096. Deleting a thread causes a WebGUI error.
Checked to make sure that anything is returned from getLineage before calculating the rating. When the thread is in the trash or clipboard, then getLineage will not return anything.
This commit is contained in:
parent
c34da3f615
commit
5fc2a1f248
4 changed files with 80 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
7.8.2
|
||||
- fixed #11098: Leaving a version tag makes everyone leave
|
||||
- fixed #11096: Error on deleting FAQ(CS)-item
|
||||
|
||||
7.8.1
|
||||
- mark $session->datetime->time as deprecated and remove its use from core code
|
||||
|
|
|
|||
|
|
@ -1222,19 +1222,20 @@ An integer indicating either thumbss up (+1) or thumbs down (-1)
|
|||
=cut
|
||||
|
||||
sub rate {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my $rating = shift;
|
||||
return undef unless ($rating == -1 || $rating == 1);
|
||||
return undef if $self->hasRated;
|
||||
my $session = $self->session;
|
||||
$self->insertUserPostRating($rating);
|
||||
$self->recalculatePostRating();
|
||||
my $thread = $self->getThread;
|
||||
$thread->updateThreadRating();
|
||||
if ($self->session->setting->get("useKarma")
|
||||
&& $self->session->user->karma > $thread->getParent->get('karmaSpentToRate')) {
|
||||
$self->session->user->karma(-$self->getThread->getParent->get("karmaSpentToRate"), "Rated Post ".$self->getId, "Rated a CS Post.");
|
||||
my $u = WebGUI::User->new($self->session, $self->get("ownerUserId"));
|
||||
$u->karma($self->getThread->getParent->get("karmaRatingMultiplier"), "Post ".$self->getId." Rated by ".$self->session->user->userId, "Had post rated.");
|
||||
if ($session->setting->get("useKarma")
|
||||
&& $session->user->karma > $thread->getParent->get('karmaSpentToRate')) {
|
||||
$session->user->karma(-$thread->getParent->get("karmaSpentToRate"), "Rated Post ".$self->getId, "Rated a CS Post.");
|
||||
my $u = WebGUI::User->new($session, $self->get("ownerUserId"));
|
||||
$u->karma($thread->getParent->get("karmaRatingMultiplier"), "Post ".$self->getId." Rated by ".$session->user->userId, "Had post rated.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -974,15 +974,17 @@ sub updateThreadRating {
|
|||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $calcRating = 0;
|
||||
my $postIds = $self->getLineage(["descendants","self"], {
|
||||
includeOnlyClasses => ["WebGUI::Asset::Post","WebGUI::Asset::Post::Thread"],
|
||||
includeArchived => 1,
|
||||
});
|
||||
|
||||
$calcRating += $session->db->quickScalar(
|
||||
"SELECT SUM(rating) FROM Post_rating WHERE assetId IN (".$session->db->quoteAndJoin($postIds).")"
|
||||
);
|
||||
my $calcRating = 0;
|
||||
if (scalar @{ $postIds }) {
|
||||
$calcRating += $session->db->quickScalar(
|
||||
"SELECT SUM(rating) FROM Post_rating WHERE assetId IN (".$session->db->quoteAndJoin($postIds).")"
|
||||
);
|
||||
}
|
||||
|
||||
$self->update({
|
||||
threadRating => $calcRating
|
||||
|
|
@ -991,7 +993,8 @@ sub updateThreadRating {
|
|||
my $parent = $self->getParent;
|
||||
if (defined $parent) {
|
||||
$parent->recalculateRating;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$self->session->errorHandler->error("Couldn't get parent for thread ".$self->getId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
64
t/Asset/Post/Thread.t
Normal file
64
t/Asset/Post/Thread.t
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 2; # increment this value for each test you create
|
||||
use Test::MockObject::Extends;
|
||||
use WebGUI::Asset::Wobject::Collaboration;
|
||||
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"});
|
||||
addToCleanup($versionTag);
|
||||
|
||||
# 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', editTimeout => '1'}, @addArgs);
|
||||
|
||||
|
||||
# finally, add the post to the collaboration system
|
||||
my $props = {
|
||||
className => 'WebGUI::Asset::Post::Thread',
|
||||
content => 'hello, world!',
|
||||
ownerUserId => 1,
|
||||
};
|
||||
|
||||
my $thread = $collab->addChild($props, @addArgs);
|
||||
|
||||
$versionTag->commit();
|
||||
|
||||
# Test for a sane object type
|
||||
isa_ok($thread, 'WebGUI::Asset::Post::Thread');
|
||||
|
||||
my $env = $session->env;
|
||||
$env = Test::MockObject::Extends->new($env);
|
||||
|
||||
my %mockEnv = (
|
||||
REMOTE_ADDR => '192.168.0.2',
|
||||
);
|
||||
|
||||
$env->mock('get', sub { return $mockEnv{$_[1]}});
|
||||
|
||||
$session->user({userId => 3});
|
||||
$thread->rate(1);
|
||||
$thread->trash;
|
||||
is($thread->get('threadRating'), 0, 'trash does not die, and updates the threadRating to 0');
|
||||
|
||||
# vim: syntax=perl filetype=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue