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

XenForo_DataWriter_DiscussionMessage_Post and draft

Discussion in 'XenForo Development Discussions' started by viewfinder, Nov 8, 2013.

  1. viewfinder

    viewfinder Member

    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.
  2. Chris D

    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.
  3. xf_phantom

    xf_phantom Well-Known Member

    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))

         if (!
    $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$messageserialize($extraData)));

  4. viewfinder

    viewfinder Member

    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.
  5. viewfinder

    viewfinder Member

    OK, answered my own question re referential integrity. As long as the foreign key is set, delete will cascade.

Share This Page