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

postSave Resource discussion thread id is zero

Discussion in 'XenForo Development Discussions' started by CrispinP, Jul 20, 2016.

  1. CrispinP

    CrispinP Well-Known Member

    Hi folks,

    I have an add-on which extends data writer. The hint used is "XenResource_DataWriter_Update"

    In my _postSave function I can see the resource_id when a resource is added but the discussion_thread_id is always zero.

    My code:
        $f = $this->getModelFromCache('XenResource_Model_Resource');
    Here is what I get when I get a resource in the function:
        [resource_id] => 312
        [title] => sdf
        [tag_line] => asdfasf
        [user_id] => 1
        [username] => Crispin
        [resource_state] => visible
        [resource_date] => 1469051740
        [resource_category_id] => 6
        [current_version_id] => 0
        [description_update_id] => 0
        [discussion_thread_id] => 0
        [external_url] => 
        [is_fileless] => 0
        [external_purchase_url] => 
        [price] => 0.00
        [currency] => 
        [download_count] => 0
        [rating_count] => 0
        [rating_sum] => 0
        [rating_avg] => 0
        [rating_weighted] => 3
        [update_count] => 0
        [review_count] => 0
        [last_update] => 1469051740
        [alt_support_url] => 
        [had_first_visible] => 1
        [custom_resource_fields] => a:0:{}
        [prefix_id] => 0
        [icon_date] => 0
        [tags] => a:0:{}
    If I hardcode a previously saved id, 300, I do get the value back.

    Why is it not available the way I am doing it? I'm really confused. :(

  2. Liam W

    Liam W Well-Known Member

    Is the resource category setup to create a thread in a forum when a resource is created?

  3. CrispinP

    CrispinP Well-Known Member

    Doh - should have said - yes, it is. The thread is created, I can see like normal. Just the id is not updated in the array.

    I've done some more digging.

    In XenResource DataWriter there is a function called _insertDiscussionThread. It is this which sets the thread id after creating the thread. This is called by the _postSave function in datawriter.

    If I put a debug print in there and a debug print at the bottom of my _postSave function I can see that my _postSave function is called before the the real one. This is why it's not populated.

    My function looks like this:
    class Crispin_Bla_DataWriter_DataWriter extends XFCP_Crispin_Bla_DataWriter_DataWriter
        public function _postSave()
            // call parent
    Am I simply just calling it wrong?
  4. Liam W

    Liam W Well-Known Member

    I'm assuming you're doing parent::_postSave() before your code?

    If you are, that's a strange one, and I'm not 100% sure what would cause it...

  5. CrispinP

    CrispinP Well-Known Member

    Yup. Parent save is the first line of my function.

    Is my function actually overriding the real postsave? I don't think it is. They appear to be running sequential.

Share This Page