Get thread ID when using the thread datawriter?

Jarvis

Member
Is there a way for me to get the thread ID of the thread created using a datawriter?

For example, I want to automatically generate a post for a thread when I create it.

PHP:
// Create thread datawriter
// Create thread

// Create post 
// in thread where ID = thread created
 
The answer is in the source code :)
PHP:
   protected function _discussionPostSave()
   {
     $threadId = $this->get('thread_id');
     ...
   }

Btw, don't forget to check if it's actually a new thread!
 
The answer is in the source code :)
PHP:
   protected function _discussionPostSave()
   {
     $threadId = $this->get('thread_id');
     ...
   }

Btw, don't forget to check if it's actually a new thread!

Here is my function to create the new thread:

PHP:
public function actionCreateThread($forumID, $title, $message)
{
    $poster = $this->getRRDBot();
    $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $writer->set('user_id', $poster['userID']);
    $writer->set('username', $poster['username']);
    $writer->set('title', $title);
    $postWriter = $writer->getFirstMessageDw();
    $postWriter->set('message', $message);
    $writer->set('node_id', $forumID);
    $writer->preSave();
    $writer->save();
    return $writer->getMergedData();
}

How do I incorporate the function you sent me?

I noticed:

PHP:
/**
* Gets the current value of the discussion ID for this discussion.
*
* @return integer
*/
public function getDiscussionId()
{
   return $this->get($this->getDiscussionKeyName());
}

In the XF discussion datawriter, but not sure how to utilize it.
 
I got it:

PHP:
public function actionCreateThread($forumID, $title, $message)
{
    $poster = $this->getRRDBot();
    $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $writer->set('user_id', $poster['userID']);
    $writer->set('username', $poster['username']);
    $writer->set('title', $title);
    $postWriter = $writer->getFirstMessageDw();
    $postWriter->set('message', $message);
    $writer->set('node_id', $forumID);
    $writer->preSave();
    $writer->save();
    return $writer->getDiscussionId();
}
 
Back
Top Bottom