• 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

#1
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
 

borbole

Well-known member
#2
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
Can you please give us a few more details? What items do you mean?
 
#3
Thank you for your reply!
What items do you mean?
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.
 

borbole

Well-known member
#4
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.
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.
 

Chris D

XenForo developer
Staff member
#5
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
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.
 
#8
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?