Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix forum #3490

Merged
merged 6 commits into from
Oct 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions e107_plugins/forum/forum_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2527,27 +2527,24 @@ function threadDelete($threadId, $updateForumLastpost = true)
* Delete a Post
* @param $postId integer
* @param $updateCounts boolean
*
* @return "null" if this post does not exist, "true" if post could deleted, otherwise "false"
*/
function postDelete($postId, $updateCounts = true)
{
$postId = (int)$postId;
$e107 = e107::getInstance();

$sql = e107::getDb();
$deleted = false;

$postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId);
//if(!$sql->select('forum_post', '*', 'post_id = '.$postId))

if(!is_array($postInfo) || empty($postInfo))
{
echo 'NOT FOUND!'; return;
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the return here to "null" and adapted the description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}


$row = $sql->fetch();

//delete attachments if they exist
if($row['post_attachments'])
if($postInfo['post_attachments'])
{
$this->postDeleteAttachments('post', $postId);
}
Expand All @@ -2563,24 +2560,24 @@ function postDelete($postId, $updateCounts = true)
if($updateCounts)
{
// decrement user post counts
if ($row['post_user'])
if ($postInfo['post_user'])
{
$sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_id='.$row['post_user']);
$sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_id='.$postInfo['post_user']);
}

// update thread with correct reply counts
$sql->update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']);
$sql->update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$postInfo['post_thread']);

// update forum with correct thread/reply counts
$sql->update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']);
$sql->update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$postInfo['post_forum']);

// update thread lastpost info
$this->forumUpdateLastpost('thread', $row['post_thread']);
$this->forumUpdateLastpost('thread', $postInfo['post_thread']);

// update forum lastpost info
$this->forumUpdateLastpost('forum', $row['post_forum']);
$this->forumUpdateLastpost('forum', $postInfo['post_forum']);
}
return $deleted; // return boolean. $threadInfo['thread_total_replies'];
return $deleted;
}


Expand Down