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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue