HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

DB cleanup on comment deletion?

This discussion is related to the Kudos Plugin addon.

Thanks for this add-on. It's very close to my needs, and I've been adapting it for an unlaunched site. In so doing I have noticed that when a kudo'd comment is deleted, the kudos data doesn't get cleaned up. So, caveat emptor. Could become needlessly cluttered on an active database (especially if you are deleting for n # of hates).

I assume this could be handled with an event handler following comment deletion. I will post a fix if I can get one together, but anyone's advice is welcome in the meantime--I'm new to Vanilla. Thanks again!

PS - The Voting plugin looks to behave the same way, or else I didn't see it when I nosed through the code.


  • Welcome to the community!

    You want to hook into the comment and discussion models and delete any attached kudos. Something like below should get you started:

    public function CommentModel_DeleteComment_Handler($Sender) {
      $CommentID = $Sender->EventArguments['CommentID'];
      $Sender->SQL->Delete('Kudos', array('CommentID' => $CommentID));
    public function DiscussionModel_DeleteDiscussion_Handler($Sender) {
      $DiscussionID = $Sender->EventArguments['DiscussionID'];
      $Sender->SQL->Delete('Kudos', array('DiscussionID' => $DiscussionID));

    This is completely untested, but it should work.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Thanks a lot, hgtonight, I'll give that a shot. I had gotten as far as trying DiscussionModel_Delete_Handler but that wasn't working.

    After I made my original post I went to lunch, and there realized my postscript was wrong. The Voting plugin doesn't have this problem, I don't think, because I think it writes to the comments table directly. Kudos has the many-to-many table to deal with.

  • Ok, I've tested @hgtonight's code and it appears to be working great for comment deletion. And the discussion deletion fits in perfectly with my planned implementation, but not right out of the box.

    The Kudos code looks like it's written to be easy to flip between allowing kudos on discussions or on comments (though this isn't an option it gives in the UI, I don't think--the code is more or less in 'comment mode'). The point is, although there is a DiscussionID field in the Kudos table, it's always null, so your DiscussionModel method won't capture any kudos.

    I'm also new to jQuery & JSON so I couldn't offer my own untested solution, but I'll post something once I've stumbled across something that seems to work. In the event that's a long time coming, I'd point other interested parties to where I suspect the action's going to be: default.php DiscussionController_Kudos_Create()

  • As I mentioned, I don't much know my way around jquery yet, so I advise anyone reading this to take it with a grain of salt. If you always set the DiscussionID then @hgtonight's code will work. Otherwise, based on this doc (which bugs out right at the relevant part!) and this helpful list, I think this might do it for people who have this plugin installed without other changes:

    public function DiscussionModel_DeleteDiscussion_Handler($Sender) {
      $DiscussionID = $Sender->EventArguments['DiscussionID'];
      $CommentIDs = $Sender->SQL->GetWhere ('Comments', array('DiscussionID' => $DiscussionID));
      $Sender->SQL->GetDelete('Kudos', array('CommentID' => $CommentIDs));

    Untested and not particularly confident in how to set up the "where in" clause on that last line! Hope it helps the next person, though.

  • A related document can be found on the community wiki here: http://vanillawiki.homebrewforums.net/index.php/Database_&_Query_Building

    I am not sure what you are meaning with your last post. Care to clarify?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • If you are referring to my saying "(which bugs out right at the relevant part!)," I mean that at the bottom of http://vanillaforums.org/docs/database, the text reads "And for one more example on using DataSets, here's how one might decide to traverse a set of data:" followed by what looks like corrupted code.

    I appreciate the link! I will read with interest.

  • Thanks for noticing, I alerted the editors

    There was an error rendering this rich post.

Sign In or Register to comment.