Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Comments and DiscussionID

edited May 2007 in Vanilla 1.0 Help
When I start a new discussion, the database assigns the discussion a DiscussionID. When posting comments, this number is used to let Vanilla know which discussion we're posting comments on. Now when I start a new discussion, the content of the discussion is also the first comment. So when I click the 'Post' button It submits the discussion and the comment simultaneously. My question is how does Vanilla know which DiscussionID is assigned to the discussion when placing the first comment? I know the question is a little bit vague but I'm not very good at describing things, I'm sorry.


  • Options
    edited May 2007
    it doesn't assign a DiscussionID for a new discussion
    the DiscussionID field in the database is autinocrement, So all you have to do is send the query without a DiscussionID and the database will automatically assign a new autoincremented ID.
    Regarding how does it know the FirstCommenID, i do not know that

    you should also look here
    The method is SaveDiscussion.
  • Options
    I know about the auto_increment thing. My formulation was wrong. Anyway Vanilla.Class.DiscussionManager.php has this line right after where it saves the discussion: // Now save the associated Comment if ($Discussion->Comment->DiscussionID > 0) { $CommentManager->SaveComment($Discussion->Comment, 1); // Now update the topic table so that we know what the first comment in the discussion was if ($Discussion->Comment->CommentID > 0 && $NewDiscussion) { $s->Clear(); $s->SetMainTable('Discussion', 'd'); $s->AddFieldNameValue('FirstCommentID', $Discussion->Comment->CommentID); $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '='); $this->Context->Database->Update($s, $this->Name, 'NewDiscussion', 'An error occurred while updating discussion properties.'); But I can't seem to figure out exactly what it does.
  • Options
    edited May 2007
    ok First It saves the discussion so $Discussion->Comment->DiscussionID > 0 Then it saves the comment using $CommentManager->SaveComment($Discussion->Comment, 1); which puts a numerical value in $Discussion->Comment->CommentID Now both Discussion and Comment are saved. Then update the Discussion table's FirstCommentID. the last 5 lines is just one query, using sqlbuilder. this $s->SetMainTable('Discussion', 'd'); says use the LUM_Discussion table this $s->AddFieldNameValue('FirstCommentID', $Discussion->Comment->CommentID); says the value of $Discussion->Comment->CommentID should be added in fieldname FirstCommentID this $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '='); says FirstComment ID of which Discussion. logically the discussion is the one you just created which is $Discussion->Comment->DiscussionID the last code just runs the query you should use a debugger and step in and see what is happening exactly
This discussion has been closed.