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

Thread DataWriter

Discussion in 'XenForo Development Discussions' started by NixFifty, Mar 19, 2014.

  1. NixFifty

    NixFifty Well-Known Member

    I seem to be having an issue with the Thread DataWriter. When I set the new values (new node_id and discussion_state to deleted) and then save, it seems the counters aren't being updated correctly.

    Code:
    $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($threadId);
    $dw->set('node_id', $targetNode);
    $dw->set('discussion_state', 'deleted');
    $dw->save();
    
    However, if I change my code to this (and not delete the thread after moving it):

    Code:
    $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($threadId);
    $dw->set('node_id', $targetNode);
    $dw->save();
    
    The counters and forum information update fine. Could anyone explain what the problem is and how to go about resolving it?

    My end goal is to have a thread moved from A to B and soft deleted, programmatically.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    I just checked the code.

    The post save code that handles the moving of a forum only does so when the thread is visible. There's nothing in the code to handle the simultaneous deletion and moving of a thread. And, why would there be? It's not actually something you can do in one action normally.

    The easiest thing to do, though probably not the most elegant, is to re-instantiate the DataWriter again after the thread has been moved.

    PHP:
    $dw XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($threadId);
    $dw->set('node_id'$targetNode);
    $dw->save();

    $dw XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $dw->setExistingData($threadId);
    $dw->set('discussion_state''deleted');
    $dw->save();
     
    NixFifty likes this.
  3. NixFifty

    NixFifty Well-Known Member

    Ah, that didn't occur to me. Thanks for that Chris, worked like a charm! (y)
     

Share This Page