Skip to content

Commit

Permalink
FIX the database was not updated when a post was deleted
Browse files Browse the repository at this point in the history
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[].

I am quite not sure about this line (which I removed):

 echo 'NOT FOUND!';

I can not see a reason for this echo, and why an empty return in the next step? Most calls of
this function postDelete() expect true/false or they dont care. There is only one function that
does something with the return value, it is the function forumDeletePost() in the
forum_mod.php. It builds a string with the returned value, which leads to:
"CANCEL and <return value> Forum Options".

So the return could be:
"CANCEL and true Forum Options"
"CANCEL and false Forum Options"
"CANCEL and Forum Options"

Not one of the three lines makes sense to me. Any suggestions?
  • Loading branch information
phibel committed Oct 4, 2018
1 parent 8abe2eb commit 39f42fd
Showing 1 changed file with 12 additions and 15 deletions.
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 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 $deleted;

This comment has been minimized.

Copy link
@CaMer0n

CaMer0n Oct 4, 2018

Member

Perhaps return null if the record does not exist, true if found and could be deleted, and false if found but could not be deleted.

This comment has been minimized.

Copy link
@phibel

phibel Oct 5, 2018

Author Contributor

Ok, that sounds good to me, I will change it like that. But then I still have to rework the forumDeletePost() function in forum_mod.php. Can you tell me where the message from forum_mod.php are displayed? I could not find it yet.

This comment has been minimized.

Copy link
@CaMer0n

CaMer0n Oct 10, 2018

Member

Appears to be forum_viewtopic.php Line 152

if(MODERATOR && isset($_POST['mod']))
{
	require_once(e_PLUGIN."forum/forum_mod.php");
	$thread->message = forum_thread_moderate($_POST);
	$thread->threadInfo = $forum->threadGet($thread->threadId);
}

This comment has been minimized.

Copy link
@phibel

phibel Oct 13, 2018

Author Contributor

Yes, but what do I have to do to trigger this message? I want to see the message on my e107-webpage! I think the messages in forum/forum_mod.php line 65 and 73 needs some rewording to be helpful to the user...

EDIT:
I looked a little further into the code and it seems that this message could no longer be displayed. Because the shortcode {MODOPTIONS} in forum/templates/forum_viewtopic_template.php is never called. The whole template specified by $FORUMSTART, $FORUMTHREADSTYLE, $FORUMEND, $FORUMREPLYSTYLE, $FORUMDELETEDSTYLE is dead? The template is defined in the array $FORUM_VIEWTOPIC_TEMPLATE['start'], which never calls the {MODOPTIONS} and nothing can trigger the messages in forum/forum_mod.php. Am I right?

This comment has been minimized.

Copy link
@CaMer0n

CaMer0n Oct 15, 2018

Member

Yes, the $FORUMSTART etc is deprecated and the array is what is being used. Normally messages will be displayed by the {ALERTS} shortcode in the theme. (and it is auto-added if not found) So, all that is required is e107::getMessage()->addSucess() etc.

}


$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

0 comments on commit 39f42fd

Please sign in to comment.