Implemented beforeAttachmentDelete method in \XF\Attachment\AbstractHandler

DragonByte Tech

Well-known member
At the moment, if I want to perform some operations on attachments for a specific content type:
  • validate an attachment before upload
  • apply code after the attachment has been associated
  • apply code after the attachment has been deleted
I can achieve all of this by extending that content type's attachment handler. The item conspicuous by its absence in that list is "validate an attachment before deletion".

Use case: In our Credits mod, the admin can choose to either award for or charge for attaching content to a post, limited by forum. In the event that the admin awards credits for uploads, I need to validate that the user has enough credits to delete the upload (undo the event) before I can allow the deletion to proceed.

Unlike testing that the user has enough credits to upload, and manipulate credits after association with the post, and manipulating credits after deletion, I have to extend the preDelete event on the Attachment entity in order to test the "undo event".

This means I need to add additional code to check the context (content_type = post), plus it means extending a whole different class, making the code less tidy.

Since adding such a method to AbstractHandler wouldn't actually need to do anything by default, it shouldn't cause any regressions or require extensive testing, nor should it cause any BC breaks.


Fillip
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
Top Bottom