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

Delete addon-items when user is deleted

Discussion in 'XenForo Development Discussions' started by Bugfix, Jun 26, 2014.

  1. Bugfix

    Bugfix Member

    Hello!

    I need to delete items of a user (stored in a custome table) when a user is being deleted in the ACP.
    Is there a hook for this or what is the correct way to do this?

    Thank you!
    Harald
     
  2. borbole

    borbole Well-Known Member

    Can you please give us a few more details? What items do you mean?
     
  3. Bugfix

    Bugfix Member

    Thank you for your reply!
    Isn't this irrelevant? It is a custom table with extra data for the user.
    When user 123 is beeing deleted in the ACP, i need to delete those items where user_id = 123 in my custom table too.

    My question is how to do that.
     
  4. borbole

    borbole Well-Known Member

    You will need an add on for that. More or less like the add on that I have coded that removes users posts, threads etc when they are being deleted.

    http://xenforo.com/community/resources/delete-user-s-content.2945/

    Or you can delete them manually by running a query.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    In your add-on, create a Code Event Listener that listens to the load_class_datawriter event.

    Then, extend XenForo_DataWriter_User::_postDelete();

    Add code to that function which deletes the user from your custom table.

    If you have extended Models or Controllers before in XenForo the concepts are pretty much the same.
     
    AndyB, Bugfix and Brogan like this.
  6. Bugfix

    Bugfix Member

    Sure, I do have an addon. The question is - how can I extend the default behaviour of XF in my addon so that my custom data is deleted too?
     
  7. Bugfix

    Bugfix Member

    Hey Chris! load_class_datawriter & _postDelete -> exactly what I was looking for!
    Thank you!
     
    Chris D likes this.
  8. Bugfix

    Bugfix Member

    Hey @Chris D , I have an additional question:
    I have implemented the Like-Model for my new Content-type.
    Adding a like is easy - "incrementLikeCounter" from XenForo_LikeHandler_Abstract.
    But how do I decrement the counter when a user is being deleted?
     
  9. Bugfix

    Bugfix Member

    OK, just found "getLatestContentLikeUsers" in XenForo_Model_Like!
    I will give it a try ;)
     

Share This Page