Last post after changing message/discussion_state

Stepel

Member
Hi,

I check few things in DataWriter_DiscussonMessage_Post and I set 'moderated' state if something is wrong. I see that even post/thread is set to 'moderated' by changing state in DataWritter methods (example preSave()) the post/thread is visible as "Latest post" in forum list. Please tell me what decide (which method etc) that this Latest post is properly (post/thread should has visible state).

It is weird for me, because when I change state by "unapprove" functionality in XF then Latest post is properly but when I analyse this functionality I don't see anything more than "change state to moderated"

Even I call method "UpdateLatestPost()" from DataWritter_Forum Class... it doesn't help.
Any advice?
 
Last edited:
This is what you may want to use when you want to update a thread state
PHP:
           /** @var XenForo_DataWriter_Discussion_Thread $dw */
            $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); // create a dw instance
            $dw->setExistingData($thread); // set a thread id to work with
            $dw->set('discussion_state', 'moderated'); // valid options: visible, moderated and deleted
            $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum); // get the $forum using node_id key from $thread key
            $dw->save(); // ktnxbai
 
it doesn't work when i want to do it from _messagePostSave() becaue I check if it is firstPost in Thread and if yes then i do
PHP:
$dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread',XenForo_DataWriter::ERROR_SILENT);
            $dw->setExistingData($thread_id);
            $forum = XenForo_Model::create('XenForo_Model_Forum')->getForumById($dw->get('node_id'));
            $dw->set('discussion_state', 'moderated');   
            $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
            $dw->save();
 
Any idea ? I don't understand why it doesn't work. I tried in _postSaveAfterTransaction too but it doesn;t work. Maybe I shouldn't do in DataWritter_DiscussionMessage_Post ?
 
As I said, I extended XenForo_DataWriter_DiscussionMessage_Post


PHP:
protected function _messagePostSave()
{
  parent::_messagePostSave();
  if ($this->isChanged('message')){
       if (isset($GLOBALS['peb_set_thread_moderated_kk']) && $GLOBALS['peb_set_thread_moderated_kk']) {
       $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread',XenForo_DataWriter::ERROR_SILENT);
       $dw->setExistingData($thread_id);
       $forum = XenForo_Model::create('XenForo_Model_Forum')->getForumById($dw->get('node_id'));
       $dw->set('discussion_state', 'moderated');
       $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
       $dw->save();
  }
     unset($GLOBALS['peb_set_thread_moderated_kk']);
}

It works like that because I check special limits for user when user tries to write post. If it is first post in thread i want to set thread as moderated.
 
Don't do that. Use the code I gave outside datawriter, for example in controller or a model or a helper.
 
Back
Top Bottom