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

Thread DataWriter

NixFifty

Well-known member
#1
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.
 

Chris D

XenForo developer
Staff member
#2
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

Well-known member
#3
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();
Ah, that didn't occur to me. Thanks for that Chris, worked like a charm! (y)