1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-22 14:13:03 +02:00

FIX the database was not updated when a post was deleted

Looks like someone was interrupted during work and than it was merged into the repo?
Anyway, the needed information are stored in $postInfo[] and not in $row[].
This commit is contained in:
phibel
2018-10-05 00:32:33 +02:00
parent 3848560752
commit e2789872a5

View File

@@ -2527,27 +2527,24 @@ class e107forum
* Delete a Post * Delete a Post
* @param $postId integer * @param $postId integer
* @param $updateCounts boolean * @param $updateCounts boolean
* * @return "null" if this post does not exist, "true" if post could deleted, otherwise "false"
*/ */
function postDelete($postId, $updateCounts = true) function postDelete($postId, $updateCounts = true)
{ {
$postId = (int)$postId; $postId = (int)$postId;
$e107 = e107::getInstance();
$sql = e107::getDb(); $sql = e107::getDb();
$deleted = false; $deleted = false;
$postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId); $postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId);
//if(!$sql->select('forum_post', '*', 'post_id = '.$postId))
if(!is_array($postInfo) || empty($postInfo)) if(!is_array($postInfo) || empty($postInfo))
{ {
echo 'NOT FOUND!'; return; return null;
} }
$row = $sql->fetch();
//delete attachments if they exist //delete attachments if they exist
if($row['post_attachments']) if($postInfo['post_attachments'])
{ {
$this->postDeleteAttachments('post', $postId); $this->postDeleteAttachments('post', $postId);
} }
@@ -2563,24 +2560,24 @@ class e107forum
if($updateCounts) if($updateCounts)
{ {
// decrement user post counts // 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 // 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 // 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 // update thread lastpost info
$this->forumUpdateLastpost('thread', $row['post_thread']); $this->forumUpdateLastpost('thread', $postInfo['post_thread']);
// update forum lastpost info // 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;
} }