1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Set node_id in xf_thread

Discussion in 'XenForo Development Discussions' started by LPH, Apr 19, 2015.

  1. LPH

    LPH Well-Known Member

    The following works:

    PHP:
    $node_id XenWord::getForumIdForPost$post->ID );
    $thread_id $thread['thread_id'];
    $update "UPDATE `xf_thread` SET `node_id` = ? WHERE `thread_id` = {$thread_id}";
    XenForo_Application::getDb()->fetchOne($update$node_id);
    But I wanted to simply use the datawriter and cannot seem to get it to work.

    PHP:
    $node_idXenWord::getForumIdForPost$post->ID );
    $writer->set'node_id'$node_id );
    I've also tried setExistingData. Am I missing an easy way to change the node_id in xf_thread?
     
  2. Liam W

    Liam W Well-Known Member

    This should work:

    PHP:
    $dw XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($threadId);
    $dw->set('node_id'$forumId);
    $dw->save();
    Make sure you're setting the existing data, and calling save.

    Liam
     
  3. LPH

    LPH Well-Known Member

    Right, except that doesn't work and it's my fault for not posting all of the lines of code.

    This works.
    PHP:
            $writer XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
            
    $writer->setExistingData$post_id );
            
    $writer->set'message'$body );
            
    $writer->preSave();

            if ( ! 
    $writer->hasErrors() ) {

                
    $writer->save();
                
    $node_id XenWord::getForumIdForPost$post->ID );
                
    $thread_id $thread['thread_id'];
                
    $update "UPDATE `xf_thread` SET `node_id` = ? WHERE `thread_id` = {$thread_id}";
                
    XenForo_Application::getDb()->fetchOne($update$node_id);

            }
    This fails to change the node_id but does not register an error.
    PHP:
            $node_id XenWord::getForumIdForPost$post->ID );

            
    $writer XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
            
    $writer->setExistingData$post_id );
            
    $writer->set'node_id'$node_id );
            
    $writer->set'message'$body );
            
    $writer->preSave();

            if ( ! 
    $writer->hasErrors() ) {

                
    $writer->save();
    This fails and gives the error "An exception occurred: The field 'node_id' was not recognised"

    PHP:

            $writer 
    XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
            
    $writer->setExistingData$post_id );
            
    $writer->set'message'$body );
            
    $writer->preSave();

            if ( ! 
    $writer->hasErrors() ) {

                
    $writer->save();

                
    $node_id XenWord::getForumIdForPost$post->ID );
                
    $writer XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
                
    $writer->setExistingData$post_id );
                
    $writer->set'node_id'$node_id );
                
    $writer->save();

     
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    by default XenForo did not use node_id for table xf_post. If you want to so must add new column and register field into datawriter.
     
  5. Liam W

    Liam W Well-Known Member

    There is no node id field for posts.

    Liam
     
  6. LPH

    LPH Well-Known Member

    Hmm... I'm using this in another function in the same class and it sets it. Now I'm really lost. LOL. OK. Time to step back and figure out what I'm doing because I'm wanting the xf_thread and not xf_post.

    PHP:
    $forum_idXenWord::getForumIdForPost$post_id );
    $ThreadWriter->set'node_id'$forum_id );
     
  7. Daniel Hood

    Daniel Hood Well-Known Member

    PHP:
    $writer XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
    $writer->setExistingData$post_id );
    $writer->set'message'$body );
    $writer->preSave();

    if ( ! 
    $writer->hasErrors() ) {
    $writer->save();
    $node_id XenWord::getForumIdForPost$post->ID );
    $thread_id $writer->get('thread_id');

    $dw XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($thread_id);
    $dw->set('node_id'$node_id);
    $dw->save();
    }
    ?
     
    Last edited: Apr 21, 2015
    LPH likes this.
  8. LPH

    LPH Well-Known Member

    OK. This works :)

    PHP:
    $writer XenForo_DataWriter::create'XenForo_DataWriter_DiscussionMessage_Post' );
    $writer->setExistingData$post_id );
    $writer->set'message'$body );
    $writer->preSave();

    if ( ! 
    $writer->hasErrors() ) {

        
    $writer->save();

        
    $node_id XenWord::getForumIdForPost$post->ID );
        
    $thread $writer->getMergedData();

        
    $writer XenForo_DataWriter::create'XenForo_DataWriter_Discussion_Thread' );
        
    $writer->setExistingData$thread['thread_id'] );
        
    $writer->set'node_id'$node_id );
        
    $writer->save();
    }
     
  9. LPH

    LPH Well-Known Member

    @Liam W @Nobita.Kun and @Daniel Hood

    Thanks everyone for the help. I'm starting to see that XenForo_DataWriter_DiscussionMessage_Post and XenForo_DataWriter_Discussion_Thread were the issues.
     

Share This Page