Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-16 20:16:51

ebullient
New Member
Registered: 2005-01-11
Posts: 7
Website

Deleting a comment doesn't update the parent's comment count

In Textpattern · 4.0.1 deleting a comment does not correctly update the comment count of the parent.

In txp_misc.php :

<pre>
function update_comments_count($id)
{ $thecount = safe_field(‘count(*)’,‘txp_discuss’,‘parentid=’.doSlash($id).’ and visible=1’);

$updated = safe_update(“textpattern”,“comments_count=’”.doSlash($thecount).”’”,“ID=’”.doSlash($id).”’”); return ($updated) ? true : false; } </pre>

This means that the $id passed in is the parent id…

In txp_discuss, however:

<pre>
function discuss_delete()
{ $discussid = ps(‘discussid’); safe_delete(“txp_discuss”,“discussid = $discussid”); update_comments_count($discussid); discuss_list(messenger(‘message’,$discussid,‘deleted’));
}
</pre>

The comment id is passed to update_comments_count – which wouldn’t correctly update the parent’s comment count.
It should be something like this:

<pre>
function discuss_delete()
{ $discussid = ps(‘discussid’);

// get parent id before deleting the comment $parentid = safe_field(‘parentid’,‘txp_discuss’, “discussid = $discussid”); // delete the comment safe_delete(“txp_discuss”,“discussid = $discussid”); // update the parent’s comment count update_comments_count($parentid); discuss_list(messenger(‘message’,$discussid,‘deleted’)); } </pre>

Last edited by ebullient (2005-10-16 20:18:25)


‘Waste of a good apple.’ – Samwise Gamgee

Offline

#2 2005-10-17 06:11:12

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Deleting a comment doesn't update the parent's comment count

function discuss_delete()

This is never called in the current code, IIRC.
The only way to delete comments is via multi-edit.

Can you describe how to reproduce the bug you were encountering. Does it happen on a clean install?

Offline

#3 2005-10-23 22:41:40

ebullient
New Member
Registered: 2005-01-11
Posts: 7
Website

Re: Deleting a comment doesn't update the parent's comment count

It wasn’t a bug.. I was digging in there trying to understand how something else worked, and having _save and _delete using different IDs was not what I expected.

Consider it a code review comment.


‘Waste of a good apple.’ – Samwise Gamgee

Offline

#4 2005-10-24 15:38:10

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Deleting a comment doesn't update the parent's comment count

Ok, thanks. We have removed the function now so as to not cause further confusion.

Offline

Board footer

Powered by FluxBB