Thread DataWriter

Naz

XenForo developer
Staff 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.
 
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();
 
  • Like
Reactions: Naz
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)
 
Top Bottom