XF 1.5 Setting custom post field from getFirstMessageDw ?

cmpe

Active member
Heh, is anyone willing to help out with a 1.5 dev question? :)

I can't seen to override the _getFields() function for XenForo_DataWriter_DiscussionMessage_Post.

I created a new column for the xf_post table:
Code:
ALTER TABLE `xf_post` ADD COLUMN `marker` tinyint(3) unsigned NOT NULL DEFAULT '0'

I basically have a process that automatically posts new threads using code something like this:
PHP:
        $writer = XenForo_DataWriter::create( 'XenForo_DataWriter_Discussion_Thread' );
        $writer->set( XF_ID_KEY, $xf_user_id );
        $writer->set( XF_LOGIN_KEY, $xf_username );
        $writer->set( XF_TITLE_KEY, $post->post_title );
        $writer->set( XF_PREFIX_ID_KEY, $prefixId );

        $postWriter = $writer->getFirstMessageDw();
        $postWriter->set( 'marker',  1 );        // Trying to add; added custom column in xf_post
        $postWriter->set( XF_MESSAGE_KEY, $post->post_content );
Without trying to "set" the marker, the thread gets created. With it, the new thread does not get created and if I dump $postWriter, I see an error like this:
["marker"] => string(43) "The field 'marker' was not recognised."

I've setup a load_class_datawriter event class with an event hit for XenForo_DataWriter_DiscussionMessage_Post which points to the following override class:
PHP:
class My_Addon_DataWriter_Post extends XFCP_My_Addon_DataWriter_Post
{
        protected function _getFields()
        {
            $structure = $this->_messageDefinition->getMessageStructure();

            $fields = parent::_getFields();
            $fields['xf_post']['marker'] = array('type' => self::TYPE_BOOLEAN, 'required' => false, 'default' => 0);

            return $fields;
        }
}

What is confusing me is that if I do a dump of $fields I can see that the marker key is in there so the theory is that this has something to do with using getFirstMessageDw from the XenForo_DataWriter_Discussion_Thread model?

One workaround I could do is to set the marker column on the first post AFTER the thread is successfully created but been banging my head on this for the last 24 hours and wanted to see if anyone knew what I'm getting stuck on.

Thanks for any advice!
 
Nevermind. As it tends to happen... a few minutes after I posted, I stepped away from the screen and realized all the symptoms pointed to the outside process that I use to auto-create threads not changing regardless of the code listener.

Did a quick search and found this post:
https://xenforo.com/community/threa...on-outside-of-xenforo.7585/page-3#post-341943

That was what the problem was. All that time troubleshooting, it came down to my external process not loading the xenforo dependencies. :LOL:
 

Similar threads

Back
Top Bottom