XenForo_DataWriter_DiscussionMessage_Post and draft

When listening to XenForo_DataWriter_DiscussionMessage_Post, what is the right way to tell if it is saving a draft? I am seeing multiple XenForo_DataWriter_DiscussionMessage_Post events for a post, presumably it relates to draft?

The intention is to monitor the save() method and do additional stuff related to the post, but only if it is the final save that commits the post.

Any help and suggestion would be much appreciated. Thanks.

Chris D

XenForo developer
Staff member
For any DataWriter the syntax to use is:

Use that in the _preSave() or _postSave() functions.

It only returns true if a new record is being inserted into the table.


Well-known member
what is the right way to tell if it is saving a draft?
There's AFAIK no way to tell this.

Drafts aren't handled by the datawriters (check XenForo_Model_Draft ;) )

public function saveDraft($key, $message, array $extraData = array(), array $viewingUser = null, $lastUpdate = null)

     $message = trim($message);
     if (!$viewingUser['user_id'] || !strlen($message))
       return false;

     if (!$lastUpdate)
       $lastUpdate = XenForo_Application::$time;

       INSERT INTO xf_draft
         (draft_key, user_id, last_update, message, extra_data)
         (?, ?, ?, ?, ?)
         last_update = VALUES(last_update),
         message = VALUES(message),
         extra_data = VALUES(extra_data)
     ", array($key, $viewingUser['user_id'], $lastUpdate, $message, serialize($extraData)));

     return true;
OK, it appears that the additional XenForo_DataWriter_DiscussionMessage_Post is coming from editing an existing post.....

I am trying to extract data from a post, and store them in a separate table, indexed by the post_id. I guess I will need to delete existing reference in my separate table, or do an update instead of insert (though this may be a bit involved).

A related question is referential integrity, is this currently supported? i.e. deleting a post will delete associated data rows - note that these are in my separate table and not the standard set of tables.