Quote:
Originally Posted by Simon I think it must be happening in the store_basic() function - I'm using beta 9.6 code, give or take a couple of SVN versions. Whenever a story is voted on, the comment count is put back to zero, and this happens every time. Does anyone (Ash, I'm looking at you here!) know why its being reset to zero, instead of just being updated with its current value?
Shouldnt the line - $link_comments = $this->comments; - be taking care of the comment count, as long as it is preceded by a read() function? |
Thanks for posting this. I've been looking into this for a while, I think I see what's happening now.
Here's what I suspect is happening:
1) In vote.php, it calls $link->read_basic();
2) If you look at the read_basic() function, it sets a lot of the values, but not the comment count.
if(($link = $db->get_row("SELECT link_author, link_status, link_randkey, link_category, link_date, link_votes, link_karma, link_published_date FROM " . table_links . " WHERE link_id = $id"))) {
$this->author=$link->link_author;
$this->votes=$link->link_votes;
$this->karma=$link->link_karma;
$this->status=$link->link_status;
$this->randkey=$link->link_randkey;
$this->category=$link->link_category;
3) vote.php later calls insert_vote
$link->insert_vote($current_user->user_id, $value);
4) At the end of the insert_vote function, it calls store_basic:
$this->store_basic();
5) It looks like store_basic updates the comment count in the link record, but the link->comments values hadn't been read in read_basic();
$link_comments = $this->comments;
$sql = "UPDATE " . table_links . " set `link_reports`=$link_reports, `link_comments`=$link_comments, link_author=$link_author, link_status='$link_status', link_randkey=$link_randkey, link_category=$link_category, link_modified=NULL, link_date=FROM_UNIXTIME($link_date), link_published_date=FROM_UNIXTIME($link_published_ date), link_votes=$link_votes, link_karma=$link_karma WHERE link_id=$this->id";
If this is indeed the culprit, the simplest solution is probably to add setting the comment count in the read_basic() function.