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

Update resource thread message on resource save event

Hi, i need to update resource thread message on resource save event. When resource desc is saved i want to set discussion thread the same content. So, i just need to update message of discussion thread. I know that resource save function in library\XenResource\DataWriter\Resource.php with name protected function _postSave(). It also has the function protected function _insertDiscussionThread($nodeId, $prefixId = 0), but it's for creating new thread when resource is created. I am stuck, how to set discussion thread the same message as resource have when it's get saved? I don't need full code, may be just tip. Thanks.
I figured it out. If someone are interested in, below code. I just added small block(commented). This is just beginning of protected function _postSave(). You can find this function in library\XenResource\DataWriter\Resource.php:
    protected function _postSave()
        $postSaveChanges = array();

        // BushNik 30.05.2015 Start
        // Automatic thread message update when resource is saved.
    if ($this->isUpdate() && !$this->isChanged('resource_state') && $this->_descriptionDw)
       $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
       if ($threadDw->setExistingData($this->get('discussion_thread_id')) && $threadDw->get('discussion_type') == 'resource')
         $postWriter = $threadDw->getFirstMessageDw();
         $postWriter->set('message', $this->_descriptionDw->get('message'));       
        // BushNik 30.05.2015 End
Last edited: